mirror of
https://github.com/notherealmarco/WASAPhoto.git
synced 2025-03-14 14:16:15 +01:00
Add follow status to GetUserProfile
This commit is contained in:
parent
9968f9e66f
commit
09adc06e18
4 changed files with 9 additions and 3 deletions
|
@ -22,7 +22,7 @@ func (rt *_router) GetUserProfile(w http.ResponseWriter, r *http.Request, ps htt
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get user profile
|
// Get user profile
|
||||||
status, profile, err := rt.db.GetUserProfile(uid)
|
status, profile, err := rt.db.GetUserProfile(uid, ctx.Auth.GetUserID())
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
helpers.SendInternalError(err, "Database error: GetUserProfile", w, rt.baseLogger)
|
helpers.SendInternalError(err, "Database error: GetUserProfile", w, rt.baseLogger)
|
||||||
|
|
|
@ -65,7 +65,7 @@ type AppDatabase interface {
|
||||||
LikePhoto(uid string, photo int64, liker_uid string) (QueryResult, error)
|
LikePhoto(uid string, photo int64, liker_uid string) (QueryResult, error)
|
||||||
UnlikePhoto(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)
|
GetUserPhotos(uid string, start_index int, limit int) (*[]structures.UserPhoto, error)
|
||||||
GetUserStream(uid string, start_index int, limit int) (*[]structures.Photo, error)
|
GetUserStream(uid string, start_index int, limit int) (*[]structures.Photo, error)
|
||||||
|
|
||||||
|
|
|
@ -8,7 +8,7 @@ import (
|
||||||
//this should be changed, but we need to change OpenAPI first
|
//this should be changed, but we need to change OpenAPI first
|
||||||
|
|
||||||
// Get user profile, including username, followers, following, and photos
|
// 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
|
// Get user info
|
||||||
var name string
|
var name string
|
||||||
err := db.c.QueryRow(`SELECT "name" FROM "users" WHERE "uid" = ?`, uid).Scan(&name)
|
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
|
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{
|
return SUCCESS, &structures.UserProfile{
|
||||||
UID: uid,
|
UID: uid,
|
||||||
Name: name,
|
Name: name,
|
||||||
Following: following,
|
Following: following,
|
||||||
Followers: followers,
|
Followers: followers,
|
||||||
|
Followed: follow_status,
|
||||||
Photos: photos,
|
Photos: photos,
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -43,5 +43,6 @@ type UserProfile struct {
|
||||||
Name string `json:"name"`
|
Name string `json:"name"`
|
||||||
Following int64 `json:"following"`
|
Following int64 `json:"following"`
|
||||||
Followers int64 `json:"followers"`
|
Followers int64 `json:"followers"`
|
||||||
|
Followed bool `json:"followed"`
|
||||||
Photos int64 `json:"photos"` //todo: check json names
|
Photos int64 `json:"photos"` //todo: check json names
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue