mirror of
https://github.com/notherealmarco/WASAPhoto.git
synced 2025-05-05 12:22:35 +02:00
Add get followers
This commit is contained in:
parent
b89296c249
commit
e8047c77a0
10 changed files with 162 additions and 17 deletions
|
@ -34,6 +34,8 @@ import (
|
|||
"database/sql"
|
||||
"errors"
|
||||
"fmt"
|
||||
|
||||
"github.com/notherealmarco/WASAPhoto/service/structures"
|
||||
)
|
||||
|
||||
// AppDatabase is the high level interface for the DB
|
||||
|
@ -42,6 +44,7 @@ type AppDatabase interface {
|
|||
GetUserID(name string) (string, error)
|
||||
UpdateUsername(uid, name string) error
|
||||
CreateUser(name string) (string, error)
|
||||
GetUserFollowers(uid string) ([]structures.UIDName, error)
|
||||
FollowUser(uid string, follow string) error
|
||||
UnfollowUser(uid string, unfollow string) error
|
||||
BanUser(uid string, ban string) error
|
||||
|
|
|
@ -3,6 +3,7 @@ package database
|
|||
import (
|
||||
"github.com/gofrs/uuid"
|
||||
"github.com/notherealmarco/WASAPhoto/service/database/db_errors"
|
||||
"github.com/notherealmarco/WASAPhoto/service/structures"
|
||||
)
|
||||
|
||||
//Check if user exists and if exists return the user id by username
|
||||
|
@ -44,6 +45,28 @@ func (db *appdbimpl) UpdateUsername(uid string, name string) error {
|
|||
return err
|
||||
}
|
||||
|
||||
// Get user followers
|
||||
func (db *appdbimpl) GetUserFollowers(uid string) ([]structures.UIDName, error) {
|
||||
rows, err := db.c.Query(`SELECT "follower", "user.name" FROM "follows", "users"
|
||||
WHERE "follows.follower" = "users.uid"
|
||||
AND "followed" = ?`, uid)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var followers []structures.UIDName = make([]structures.UIDName, 0)
|
||||
for rows.Next() {
|
||||
var uid string
|
||||
var name string
|
||||
err = rows.Scan(&uid, &name)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
followers = append(followers, structures.UIDName{UID: uid, Name: name})
|
||||
}
|
||||
return followers, nil
|
||||
}
|
||||
|
||||
// Follow a user
|
||||
func (db *appdbimpl) FollowUser(uid string, follow string) error {
|
||||
_, err := db.c.Exec(`INSERT INTO "follows" ("follower", "followed") VALUES (?, ?)`, uid, follow)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue