From 4c4481393d668c631e111792e658c4118e32b5dc Mon Sep 17 00:00:00 2001 From: Marco Realacci Date: Mon, 12 Dec 2022 12:37:30 +0100 Subject: [PATCH] Fix profile view follow & ban status, Add ban status in GET profile API call --- .vscode/launch.json | 8 ++++++-- doc/api.yaml | 2 ++ service/database/db-profile.go | 9 +++++++++ service/database/db-users.go | 8 ++++---- service/structures/api-structures.go | 9 +++++---- wasaphoto.db | Bin 53248 -> 53248 bytes webui/node_modules/.vite/deps/_metadata.json | 10 +++++----- webui/src/components/UserCard.vue | 9 ++++++++- 8 files changed, 39 insertions(+), 16 deletions(-) diff --git a/.vscode/launch.json b/.vscode/launch.json index 4bf30f4..23d82f5 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -4,13 +4,17 @@ // Per altre informazioni, visitare: https://go.microsoft.com/fwlink/?linkid=830387 "version": "0.2.0", "configurations": [ + { "name": "Launch Package", "type": "go", "request": "launch", "mode": "auto", - "buildFlags": "-tags webui", - "program": "./cmd/webapi" + "buildFlags": "", + "program": "./cmd/webapi", + "args": [ + "--db-filename", "/home/marco/wasa/wasadata/wasaphoto.db", "--data-path", "/home/marco/wasa/wasadata/data" + ] } ] } \ No newline at end of file diff --git a/doc/api.yaml b/doc/api.yaml index 4de2fcb..337065a 100644 --- a/doc/api.yaml +++ b/doc/api.yaml @@ -1005,6 +1005,8 @@ components: $ref: "#/components/schemas/photos_n" followed: $ref: "#/components/schemas/follow_status" + banned: + $ref: "#/components/schemas/ban_status" user_photo_stream: type: array minItems: 0 diff --git a/service/database/db-profile.go b/service/database/db-profile.go index 5f8bb80..bf63fe6 100644 --- a/service/database/db-profile.go +++ b/service/database/db-profile.go @@ -54,12 +54,21 @@ func (db *appdbimpl) GetUserProfile(uid string, requesting_uid string) (QueryRes 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{ UID: uid, Name: name, Following: following, Followers: followers, Followed: follow_status, + Banned: ban_status, Photos: photos, }, nil } diff --git a/service/database/db-users.go b/service/database/db-users.go index ab518ac..3d0bd80 100644 --- a/service/database/db-users.go +++ b/service/database/db-users.go @@ -290,15 +290,15 @@ func (db *appdbimpl) SearchByName(name string, requesting_uid string, start_inde ( SELECT EXISTS( SELECT * FROM "follows" AS "f" - WHERE "f"."follower" = "users"."uid" - AND "f"."followed" = ? + WHERE "f"."follower" = ? + AND "f"."followed" = "users"."uid" ) ), ( SELECT EXISTS( SELECT * FROM "bans" AS "b" - WHERE "b"."user" = "users"."uid" - AND "b"."ban" = ? + WHERE "b"."user" = ? + AND "b"."ban" = "users"."uid" ) ) diff --git a/service/structures/api-structures.go b/service/structures/api-structures.go index fca721f..ed6a4df 100644 --- a/service/structures/api-structures.go +++ b/service/structures/api-structures.go @@ -10,10 +10,10 @@ type UIDName struct { } type SearchResult struct { - UID string `json:"user_id"` - Name string `json:"name"` - Followed bool `json:"followed"` - Banned bool `json:"banned"` + UID string `json:"user_id"` + Name string `json:"name"` + Followed bool `json:"followed"` + Banned bool `json:"banned"` } type GenericResponse struct { @@ -52,5 +52,6 @@ type UserProfile struct { Following int64 `json:"following"` Followers int64 `json:"followers"` Followed bool `json:"followed"` + Banned bool `json:"banned"` Photos int64 `json:"photos"` } diff --git a/wasaphoto.db b/wasaphoto.db index 2e9bf16a609a5c34a147ea81a4ee664694d1b6fe..1ae71fea799109d4d3c6e0d0b9db38d085861d38 100644 GIT binary patch delta 279 zcmZozz}&Ead4e<}$3z)tMvjdMOZeFs`7bf>U)n4vaDv}Lhmko{JS92R(Ad(_K-bbD z)m+ykCD}kXDJ9uL*Vr^Q+05L;(#Xuf$TzVlGm(pdfq{|#I|KiBpzgQ)!W_)voJbNk z82E1hCC>3{s56Ih5@YHj0fkKtEDAs;?PcKK3)H)r-`A0mC6vLQ7~Mt&Mn<}ZM!E)O xAx1`4CKgsE=Gq2^Rt5&VV0V6H;QtCV@-;sXCnK{YXF*1ONq#Z!W=4bm`T!Z-MqK~^ delta 42 scmZozz}&Ead4e<}+e8^>Mz)O!OZYdlIQ)^{6u@EtV(2eQ5C9_u04v=NWB>pF diff --git a/webui/node_modules/.vite/deps/_metadata.json b/webui/node_modules/.vite/deps/_metadata.json index 6f206d3..1aabce9 100644 --- a/webui/node_modules/.vite/deps/_metadata.json +++ b/webui/node_modules/.vite/deps/_metadata.json @@ -1,23 +1,23 @@ { - "hash": "0c3e4771", - "browserHash": "01248067", + "hash": "80447977", + "browserHash": "b98131b5", "optimized": { "axios": { "src": "../../axios/index.js", "file": "axios.js", - "fileHash": "d8d02cf0", + "fileHash": "6b5eae63", "needsInterop": true }, "vue": { "src": "../../vue/dist/vue.runtime.esm-bundler.js", "file": "vue.js", - "fileHash": "f8034b26", + "fileHash": "de50261f", "needsInterop": false }, "vue-router": { "src": "../../vue-router/dist/vue-router.mjs", "file": "vue-router.js", - "fileHash": "b4ca170f", + "fileHash": "4cad12d6", "needsInterop": false } }, diff --git a/webui/src/components/UserCard.vue b/webui/src/components/UserCard.vue index fa2f02a..f62ecda 100644 --- a/webui/src/components/UserCard.vue +++ b/webui/src/components/UserCard.vue @@ -2,6 +2,14 @@ export default { 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() { return { errorMsg: "aaa", @@ -63,7 +71,6 @@ export default { }, }, created() { - }, }