First webui commit

This commit is contained in:
Marco Realacci 2022-12-09 03:53:16 +01:00
parent e38f5d08ab
commit c4611b92f8
2011 changed files with 30382 additions and 1874 deletions

View file

@ -8,7 +8,7 @@ import (
func (db *appdbimpl) GetUserStream(uid string, start_index int, limit int) (*[]structures.Photo, error) {
// Get photos from the database
rows, err := db.c.Query(`SELECT "p"."user", "p"."id", "p"."date",
rows, err := db.c.Query(`SELECT "p"."user", "u"."name", "p"."id", "p"."date",
(
SELECT COUNT(*) AS "likes" FROM "likes" AS "l"
WHERE "l"."photo_id" = "p"."id"
@ -16,9 +16,17 @@ func (db *appdbimpl) GetUserStream(uid string, start_index int, limit int) (*[]s
(
SELECT COUNT(*) AS "comments" FROM "comments" AS "c"
WHERE "c"."photo" = "p"."id"
),
(
SELECT EXISTS (
SELECT * FROM "likes" AS "l"
WHERE "l"."photo_id" = "p"."id"
AND "l"."user" = ?
)
)
FROM "photos" AS "p"
WHERE "p"."user" IN (
FROM "photos" AS "p", "users" AS "u"
WHERE "p"."user" = "u"."uid"
AND "p"."user" IN (
SELECT "followed" FROM "follows" WHERE "follower" = ?
)
AND "p"."user" NOT IN (
@ -26,7 +34,7 @@ func (db *appdbimpl) GetUserStream(uid string, start_index int, limit int) (*[]s
)
ORDER BY "p"."date" DESC
LIMIT ?
OFFSET ?`, uid, uid, limit, start_index)
OFFSET ?`, uid, uid, uid, limit, start_index)
if err != nil {
// Return the error
return nil, err
@ -39,7 +47,7 @@ func (db *appdbimpl) GetUserStream(uid string, start_index int, limit int) (*[]s
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)
err = rows.Scan(&photo.UID, &photo.Username, &photo.ID, &photo.Date, &photo.Likes, &photo.Comments, &photo.Liked)
if err != nil {
// Return the error
return nil, err