add getUserById helper in http delete old connections code from http

This commit is contained in:
gitGnome
2026-04-08 14:10:43 +02:00
parent 26fef0a777
commit 9804a700ce
5 changed files with 69 additions and 213 deletions
+11 -5
View File
@@ -42,8 +42,8 @@ func DbInit(ctx context.Context) {
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
requestor_id INTEGER NOT NULL REFERENCES users(id) ON DELETE CASCADE,
recipient_id INTEGER NOT NULL REFERENCES users(id) ON DELETE CASCADE,
state TINYINT NOT NULL DEFAULT 0
created_at TIMESTAMP NOT NULL DEFAULT NOW(),
state SMALLINT NOT NULL DEFAULT 0,
created_at TIMESTAMP NOT NULL DEFAULT NOW()
)
`)
if err != nil {
@@ -173,10 +173,10 @@ func DbConnectionSave(ctx context.Context, conn *Connection) error {
`, conn.RequestorId, conn.RecipientId, conn.State, conn.CreatedAt).Scan(&conn.Id)
}
func DbConnectionGetBelongingToUser(ctx context.Context, user *User) error {
func DbConnectionsGetBelongingToUser(ctx context.Context, user *User) error {
rows, err := dbConn.Query(ctx, `
SELECT id, requestor_id, recipient_id, state, created_at
FROM connections
FROM user_connections
WHERE requestor_id = $1 OR recipient_id = $1
`, user.Id)
if err != nil {
@@ -195,10 +195,16 @@ func DbConnectionGetBelongingToUser(ctx context.Context, user *User) error {
}
user.Connections[conn.Id] = conn
}
return rows.Err()
}
func DbConnectionSet(ctx context.Context, conn *Connection) error {
_, err := dbConn.Exec(ctx, `
UPDATE user_connections SET state = $1 WHERE id = $2
`, conn.State, conn.Id)
return err
}
func DbGroupSave(ctx context.Context, group *Group) error {
err := dbConn.QueryRow(ctx, `
INSERT INTO chat_groups (name, creator_id, owner_id, enable_client_colors, color_red, color_green, color_blue, created_at)