so much work to do :c

This commit is contained in:
gitGnome
2026-04-05 22:38:02 +02:00
parent 7f54cc7a40
commit 9b57157769
6 changed files with 41 additions and 58 deletions
+10 -40
View File
@@ -37,7 +37,7 @@ func DbInit(ctx context.Context) {
CREATE TABLE IF NOT EXISTS user_connections (
requestor_id INTEGER NOT NULL REFERENCES users(id) ON DELETE CASCADE,
recipient_id INTEGER NOT NULL REFERENCES users(id) ON DELETE CASCADE,
is_accepted BOOLEAN NOT NULL DEFAULT FALSE,
state TINYINT NOT NULL DEFAULT 0
created_at TIMESTAMP NOT NULL DEFAULT NOW(),
PRIMARY KEY (requestor_id, recipient_id)
)
@@ -46,6 +46,15 @@ func DbInit(ctx context.Context) {
panic(err)
}
_, err = dbConn.Exec(ctx, `
CREATE TABLE IF NOT EXISTS messages (
sender_id INTEGER NOT NULL REFERENCES users(id) ON DELETE CASCADE,
receiver_id INTEGER NOT NULL REFERENCES users(id) ON DELETE CASCADE,
content TEXT NOT NULL,
is_group_message BOOLEAN DEFAULT FALSE
)
`)
_, err = dbConn.Exec(ctx, `
CREATE TABLE IF NOT EXISTS chat_groups (
id SERIAL PRIMARY KEY,
@@ -127,45 +136,6 @@ func DbUserGetGroups(ctx context.Context, user *User) error {
return rows.Err()
}
func DbUserGetConnections(ctx context.Context, user *User) error {
rows, err := dbConn.Query(ctx, `
SELECT
CASE WHEN requestor_id = $1 THEN recipient_id ELSE requestor_id END AS other_id,
requestor_id = $1 AS is_from_user,
is_accepted,
created_at
FROM user_connections
WHERE requestor_id = $1 OR recipient_id = $1
`, user.Id)
if err != nil {
return err
}
user.Connections = make(map[uint32]*Connection)
defer rows.Close()
for rows.Next() {
var (
otherId uint32
isFromUser bool
isAccepted bool
createdAt time.Time
)
err = rows.Scan(&otherId, &isFromUser, &isAccepted, &createdAt)
if err != nil {
return err
}
user.Connections[otherId] = &Connection{
CreatedAt: createdAt,
With: otherId,
IsFromUser: isFromUser,
IsAccepted: isAccepted,
}
}
return rows.Err()
}
func DbUserSetColor(ctx context.Context, user *User) error {
_, err := dbConn.Exec(ctx, `
UPDATE users SET color_red = $1, color_green = $2, color_blue = $3 WHERE id = $4