Add stream search, offset & limit, improved bans

This commit is contained in:
Marco Realacci 2022-11-22 15:17:08 +01:00
parent 72f11a2b15
commit 963e392cea
14 changed files with 298 additions and 65 deletions

View file

@ -2,8 +2,6 @@ package database
import (
"time"
"github.com/notherealmarco/WASAPhoto/service/structures"
)
// Post a new photo
@ -44,41 +42,6 @@ func (db *appdbimpl) DeletePhoto(uid string, photo int64) (bool, error) {
return rows > 0, nil
}
func (db *appdbimpl) getUserPhotos(uid string) (*[]structures.Photo, error) {
// Get photos
rows, err := db.c.Query(`SELECT "p"."user", "p"."id", "p"."date",
(
SELECT COUNT(*) AS "likes" FROM "likes" AS "l"
WHERE "l"."photo_id" = "p"."id"
),
(
SELECT COUNT(*) AS "comments" FROM "comments" AS "c"
WHERE "c"."photo" = "p"."id"
)
FROM "photos" AS "p"
WHERE "p"."user" = ?`, uid)
if err != nil {
// Return the error
return nil, err
}
photos := make([]structures.Photo, 0)
for rows.Next() {
// If there is a next row, we create an instance of Photo and add it to the slice
var photo structures.Photo
err = rows.Scan(&photo.UID, &photo.ID, &photo.Date, &photo.Likes, &photo.Comments)
if err != nil {
// Return the error
return nil, err
}
photos = append(photos, photo)
}
return &photos, nil
}
// Check if a given photo owned by a given user exists
func (db *appdbimpl) photoExists(uid string, photo int64) (bool, error) {