Fix profile view follow & ban status, Add ban status in GET profile API call

This commit is contained in:
Marco Realacci 2022-12-12 12:37:30 +01:00
parent 00e6b3de7b
commit 4c4481393d
8 changed files with 39 additions and 16 deletions

8
.vscode/launch.json vendored
View file

@ -4,13 +4,17 @@
// Per altre informazioni, visitare: https://go.microsoft.com/fwlink/?linkid=830387 // Per altre informazioni, visitare: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0", "version": "0.2.0",
"configurations": [ "configurations": [
{ {
"name": "Launch Package", "name": "Launch Package",
"type": "go", "type": "go",
"request": "launch", "request": "launch",
"mode": "auto", "mode": "auto",
"buildFlags": "-tags webui", "buildFlags": "",
"program": "./cmd/webapi" "program": "./cmd/webapi",
"args": [
"--db-filename", "/home/marco/wasa/wasadata/wasaphoto.db", "--data-path", "/home/marco/wasa/wasadata/data"
]
} }
] ]
} }

View file

@ -1005,6 +1005,8 @@ components:
$ref: "#/components/schemas/photos_n" $ref: "#/components/schemas/photos_n"
followed: followed:
$ref: "#/components/schemas/follow_status" $ref: "#/components/schemas/follow_status"
banned:
$ref: "#/components/schemas/ban_status"
user_photo_stream: user_photo_stream:
type: array type: array
minItems: 0 minItems: 0

View file

@ -54,12 +54,21 @@ func (db *appdbimpl) GetUserProfile(uid string, requesting_uid string) (QueryRes
return ERR_INTERNAL, nil, err return ERR_INTERNAL, nil, err
} }
// Get ban status
var ban_status bool
err = db.c.QueryRow(`SELECT EXISTS (SELECT * FROM "bans" WHERE "user" = ? AND "ban" = ?)`, requesting_uid, uid).Scan(&ban_status)
if err != nil {
return ERR_INTERNAL, nil, err
}
return SUCCESS, &structures.UserProfile{ return SUCCESS, &structures.UserProfile{
UID: uid, UID: uid,
Name: name, Name: name,
Following: following, Following: following,
Followers: followers, Followers: followers,
Followed: follow_status, Followed: follow_status,
Banned: ban_status,
Photos: photos, Photos: photos,
}, nil }, nil
} }

View file

@ -290,15 +290,15 @@ func (db *appdbimpl) SearchByName(name string, requesting_uid string, start_inde
( (
SELECT EXISTS( SELECT EXISTS(
SELECT * FROM "follows" AS "f" SELECT * FROM "follows" AS "f"
WHERE "f"."follower" = "users"."uid" WHERE "f"."follower" = ?
AND "f"."followed" = ? AND "f"."followed" = "users"."uid"
) )
), ),
( (
SELECT EXISTS( SELECT EXISTS(
SELECT * FROM "bans" AS "b" SELECT * FROM "bans" AS "b"
WHERE "b"."user" = "users"."uid" WHERE "b"."user" = ?
AND "b"."ban" = ? AND "b"."ban" = "users"."uid"
) )
) )

View file

@ -52,5 +52,6 @@ type UserProfile struct {
Following int64 `json:"following"` Following int64 `json:"following"`
Followers int64 `json:"followers"` Followers int64 `json:"followers"`
Followed bool `json:"followed"` Followed bool `json:"followed"`
Banned bool `json:"banned"`
Photos int64 `json:"photos"` Photos int64 `json:"photos"`
} }

Binary file not shown.

View file

@ -1,23 +1,23 @@
{ {
"hash": "0c3e4771", "hash": "80447977",
"browserHash": "01248067", "browserHash": "b98131b5",
"optimized": { "optimized": {
"axios": { "axios": {
"src": "../../axios/index.js", "src": "../../axios/index.js",
"file": "axios.js", "file": "axios.js",
"fileHash": "d8d02cf0", "fileHash": "6b5eae63",
"needsInterop": true "needsInterop": true
}, },
"vue": { "vue": {
"src": "../../vue/dist/vue.runtime.esm-bundler.js", "src": "../../vue/dist/vue.runtime.esm-bundler.js",
"file": "vue.js", "file": "vue.js",
"fileHash": "f8034b26", "fileHash": "de50261f",
"needsInterop": false "needsInterop": false
}, },
"vue-router": { "vue-router": {
"src": "../../vue-router/dist/vue-router.mjs", "src": "../../vue-router/dist/vue-router.mjs",
"file": "vue-router.js", "file": "vue-router.js",
"fileHash": "b4ca170f", "fileHash": "4cad12d6",
"needsInterop": false "needsInterop": false
} }
}, },

View file

@ -2,6 +2,14 @@
export default { export default {
props: ["user_id", "name", "followed", "banned", "my_id", "show_new_post"], props: ["user_id", "name", "followed", "banned", "my_id", "show_new_post"],
watch: {
banned: function(new_val, old_val) {
this.user_banned = new_val;
},
followed: function(new_val, old_val) {
this.user_followed = new_val;
},
},
data: function() { data: function() {
return { return {
errorMsg: "aaa", errorMsg: "aaa",
@ -63,7 +71,6 @@ export default {
}, },
}, },
created() { created() {
}, },
} }
</script> </script>