fix connection handlers, group ops, and various HTTP handler bugs
This commit is contained in:
+26
-1
@@ -38,9 +38,13 @@ func DbInit(ctx context.Context) {
|
||||
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,
|
||||
created_at TIMESTAMP NOT NULL DEFAULT NOW()
|
||||
created_at TIMESTAMP NOT NULL DEFAULT NOW(),
|
||||
PRIMARY KEY (requestor_id, recipient_id)
|
||||
)
|
||||
`)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
_, err = dbConn.Exec(ctx, `
|
||||
CREATE TABLE IF NOT EXISTS chat_groups (
|
||||
@@ -184,6 +188,27 @@ func DbGroupSetColor(ctx context.Context, group *Group) error {
|
||||
return err
|
||||
}
|
||||
|
||||
func DbConnectionSave(ctx context.Context, creationDate time.Time, requestorId uint32, recipientId uint32, isAccepted bool) error {
|
||||
_, err := dbConn.Exec(ctx, `
|
||||
INSERT INTO user_connections (created_at, requestor_id, recipient_id, is_accepted) VALUES ($1, $2, $3, $4)
|
||||
`, creationDate, requestorId, recipientId, isAccepted)
|
||||
return err
|
||||
}
|
||||
|
||||
func DbConnectionAccept(ctx context.Context, requestorId uint32, recipientId uint32) error {
|
||||
_, err := dbConn.Exec(ctx, `
|
||||
UPDATE user_connections SET is_accepted = true WHERE requestor_id = $1 AND recipient_id = $2
|
||||
`, requestorId, recipientId)
|
||||
return err
|
||||
}
|
||||
|
||||
func DbConnectionDelete(ctx context.Context, requestorId uint32, recipientId uint32) error {
|
||||
_, err := dbConn.Exec(ctx, `
|
||||
DELETE FROM user_connections WHERE requestor_id = $1 AND recipient_id = $2
|
||||
`, requestorId, recipientId)
|
||||
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)
|
||||
|
||||
Reference in New Issue
Block a user