mirror of
https://github.com/notherealmarco/WASAPhoto.git
synced 2025-05-05 12:22:35 +02:00
Add GET bans
This commit is contained in:
parent
77e9f405c6
commit
4f391f0b65
7 changed files with 117 additions and 10 deletions
|
@ -56,6 +56,7 @@ type AppDatabase interface {
|
|||
BanUser(uid string, ban string) (QueryResult, error)
|
||||
UnbanUser(uid string, unban string) (QueryResult, error)
|
||||
IsBanned(uid string, banner string) (bool, error)
|
||||
GetUserBans(uid string, start_index int, limit int) (*[]structures.UIDName, error)
|
||||
|
||||
PostPhoto(uid string) (DBTransaction, int64, error)
|
||||
DeletePhoto(uid string, photo int64) (bool, error)
|
||||
|
@ -64,7 +65,8 @@ 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) // should support limits
|
||||
GetUserProfile(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)
|
||||
|
||||
GetComments(uid string, photo_id int64, requesting_uid string, start_index int, offset int) (QueryResult, *[]structures.Comment, error)
|
||||
|
|
|
@ -39,7 +39,8 @@ func (db *appdbimpl) GetUserProfile(uid string) (QueryResult, *structures.UserPr
|
|||
return ERR_INTERNAL, nil, err
|
||||
}
|
||||
|
||||
photos, err := db.getUserPhotos(uid)
|
||||
var photos int64
|
||||
err = db.c.QueryRow(`SELECT COUNT(*) FROM "photos" WHERE "photos"."user" = ?`, uid).Scan(&following)
|
||||
|
||||
if err != nil {
|
||||
return ERR_INTERNAL, nil, err
|
||||
|
@ -54,7 +55,7 @@ func (db *appdbimpl) GetUserProfile(uid string) (QueryResult, *structures.UserPr
|
|||
}, nil
|
||||
}
|
||||
|
||||
func (db *appdbimpl) getUserPhotos(uid string) (*[]structures.UserPhoto, error) {
|
||||
func (db *appdbimpl) GetUserPhotos(uid string, start_index int, limit int) (*[]structures.UserPhoto, error) {
|
||||
|
||||
// Get photos
|
||||
rows, err := db.c.Query(`SELECT "p"."id", "p"."date",
|
||||
|
@ -65,9 +66,16 @@ func (db *appdbimpl) getUserPhotos(uid string) (*[]structures.UserPhoto, error)
|
|||
(
|
||||
SELECT COUNT(*) AS "comments" FROM "comments" AS "c"
|
||||
WHERE "c"."photo" = "p"."id"
|
||||
),
|
||||
EXISTS (
|
||||
SELECT * FROM "likes" AS "l"
|
||||
WHERE "l"."photo_id" = "p"."id"
|
||||
AND "l"."user" = ?
|
||||
)
|
||||
FROM "photos" AS "p"
|
||||
WHERE "p"."user" = ?`, uid)
|
||||
WHERE "p"."user" = ?
|
||||
OFFSET ?
|
||||
LIMIT ?`, uid, uid, start_index, limit)
|
||||
if err != nil {
|
||||
// Return the error
|
||||
return nil, err
|
||||
|
@ -78,7 +86,7 @@ func (db *appdbimpl) getUserPhotos(uid string) (*[]structures.UserPhoto, error)
|
|||
for rows.Next() {
|
||||
// If there is a next row, we create an instance of Photo and add it to the slice
|
||||
var photo structures.UserPhoto
|
||||
err = rows.Scan(&photo.ID, &photo.Date, &photo.Likes, &photo.Comments)
|
||||
err = rows.Scan(&photo.ID, &photo.Date, &photo.Likes, &photo.Comments, &photo.Liked)
|
||||
if err != nil {
|
||||
// Return the error
|
||||
return nil, err
|
||||
|
|
|
@ -235,6 +235,23 @@ func (db *appdbimpl) IsBanned(uid string, banner string) (bool, error) {
|
|||
return cnt > 0, nil
|
||||
}
|
||||
|
||||
func (db *appdbimpl) GetUserBans(uid string, start_index int, limit int) (*[]structures.UIDName, error) {
|
||||
|
||||
rows, err := db.c.Query(`SELECT "ban", "user"."name" FROM "bans", "users"
|
||||
WHERE "bans"."ban" = "users"."uid"
|
||||
AND "bans"."user" = ?
|
||||
OFFSET ?
|
||||
LIMIT ?`, uid, start_index, limit)
|
||||
|
||||
bans, err := db.uidNameQuery(rows, err)
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return bans, nil
|
||||
}
|
||||
|
||||
// Search by name
|
||||
func (db *appdbimpl) SearchByName(name string, requesting_uid string, start_index int, limit int) (*[]structures.UIDName, error) {
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue