Add follow status to GetUserProfile

This commit is contained in:
Marco Realacci 2022-11-22 17:48:15 +01:00
parent 9968f9e66f
commit 09adc06e18
4 changed files with 9 additions and 3 deletions

View file

@ -65,7 +65,7 @@ type AppDatabase interface {
LikePhoto(uid string, photo int64, liker_uid string) (QueryResult, error)
UnlikePhoto(uid string, photo int64, liker_uid string) (QueryResult, error)
GetUserProfile(uid string) (QueryResult, *structures.UserProfile, error)
GetUserProfile(uid string, requesting_uid string) (QueryResult, *structures.UserProfile, error)
GetUserPhotos(uid string, start_index int, limit int) (*[]structures.UserPhoto, error)
GetUserStream(uid string, start_index int, limit int) (*[]structures.Photo, error)

View file

@ -8,7 +8,7 @@ import (
//this should be changed, but we need to change OpenAPI first
// Get user profile, including username, followers, following, and photos
func (db *appdbimpl) GetUserProfile(uid string) (QueryResult, *structures.UserProfile, error) {
func (db *appdbimpl) GetUserProfile(uid string, requesting_uid string) (QueryResult, *structures.UserProfile, error) {
// Get user info
var name string
err := db.c.QueryRow(`SELECT "name" FROM "users" WHERE "uid" = ?`, uid).Scan(&name)
@ -46,11 +46,16 @@ func (db *appdbimpl) GetUserProfile(uid string) (QueryResult, *structures.UserPr
return ERR_INTERNAL, nil, err
}
// Get follow status
var follow_status bool
err = db.c.QueryRow(`SELECT EXISTS (SELECT * FROM "follows" WHERE "follower" = ? AND "followed" = ?)`, requesting_uid, uid).Scan(&follow_status)
return SUCCESS, &structures.UserProfile{
UID: uid,
Name: name,
Following: following,
Followers: followers,
Followed: follow_status,
Photos: photos,
}, nil
}