mirror of
https://github.com/notherealmarco/WASAPhoto.git
synced 2025-03-14 14:16:15 +01:00
Add followed & banned status to search result in backend
This commit is contained in:
parent
25be953a11
commit
acfa1374ff
3 changed files with 45 additions and 7 deletions
|
@ -45,7 +45,7 @@ type AppDatabase interface {
|
||||||
UserExistsNotBanned(uid string, requesting_uid string) (bool, error)
|
UserExistsNotBanned(uid string, requesting_uid string) (bool, error)
|
||||||
GetUserID(name string) (string, error)
|
GetUserID(name string) (string, error)
|
||||||
|
|
||||||
SearchByName(name string, requesting_uid string, start_index int, limit int) (*[]structures.UIDName, error)
|
SearchByName(name string, requesting_uid string, start_index int, limit int) (*[]structures.SearchResult, error)
|
||||||
|
|
||||||
UpdateUsername(uid string, name string) (QueryResult, error)
|
UpdateUsername(uid string, name string) (QueryResult, error)
|
||||||
|
|
||||||
|
|
|
@ -284,9 +284,25 @@ func (db *appdbimpl) GetUserBans(uid string, start_index int, limit int) (*[]str
|
||||||
}
|
}
|
||||||
|
|
||||||
// Search by name
|
// Search by name
|
||||||
func (db *appdbimpl) SearchByName(name string, requesting_uid string, start_index int, limit int) (*[]structures.UIDName, error) {
|
func (db *appdbimpl) SearchByName(name string, requesting_uid string, start_index int, limit int) (*[]structures.SearchResult, error) {
|
||||||
|
|
||||||
rows, err := db.c.Query(`SELECT "uid", "name" FROM "users"
|
rows, err := db.c.Query(`SELECT "uid", "name",
|
||||||
|
(
|
||||||
|
SELECT EXISTS(
|
||||||
|
SELECT * FROM "follows" AS "f"
|
||||||
|
WHERE "f"."follower" = "users"."uid"
|
||||||
|
AND "f"."followed" = ?
|
||||||
|
)
|
||||||
|
),
|
||||||
|
(
|
||||||
|
SELECT EXISTS(
|
||||||
|
SELECT * FROM "bans" AS "b"
|
||||||
|
WHERE "b"."user" = "users"."uid"
|
||||||
|
AND "b"."ban" = ?
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
FROM "users"
|
||||||
WHERE "name" LIKE '%' || ? || '%'
|
WHERE "name" LIKE '%' || ? || '%'
|
||||||
|
|
||||||
AND "uid" NOT IN (
|
AND "uid" NOT IN (
|
||||||
|
@ -295,13 +311,28 @@ func (db *appdbimpl) SearchByName(name string, requesting_uid string, start_inde
|
||||||
AND "bans"."ban" = ?
|
AND "bans"."ban" = ?
|
||||||
)
|
)
|
||||||
LIMIT ?
|
LIMIT ?
|
||||||
OFFSET ?`, name, requesting_uid, limit, start_index)
|
OFFSET ?`, requesting_uid, requesting_uid, name, requesting_uid, limit, start_index)
|
||||||
|
|
||||||
users, err := db.uidNameQuery(rows, err)
|
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
return users, nil
|
var search_data []structures.SearchResult = make([]structures.SearchResult, 0)
|
||||||
|
|
||||||
|
defer rows.Close()
|
||||||
|
|
||||||
|
for rows.Next() {
|
||||||
|
var search_entry structures.SearchResult
|
||||||
|
err = rows.Scan(&search_entry.UID, &search_entry.Name, &search_entry.Followed, &search_entry.Banned)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
search_data = append(search_data, search_entry)
|
||||||
|
}
|
||||||
|
// We check if the iteration ended prematurely
|
||||||
|
if err = rows.Err(); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return &search_data, nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,6 +9,13 @@ type UIDName struct {
|
||||||
Name string `json:"name"`
|
Name string `json:"name"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type SearchResult struct {
|
||||||
|
UID string `json:"user_id"`
|
||||||
|
Name string `json:"name"`
|
||||||
|
Followed bool `json:"followed"`
|
||||||
|
Banned bool `json:"banned"`
|
||||||
|
}
|
||||||
|
|
||||||
type GenericResponse struct {
|
type GenericResponse struct {
|
||||||
Status string `json:"status"`
|
Status string `json:"status"`
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue