This repository has been archived by the owner on Jan 22, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
post.go
64 lines (53 loc) · 1.45 KB
/
post.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
package userDB
import (
"database/sql"
"fmt"
)
// Create a new user that is part of a `ban` and has the specified `emails`
func NewUser(db *sql.DB, name string, emails []string, ban int) error {
// Gebruiker toevoegen
insertQuery := fmt.Sprintf("insert into Users (Name) values (%s)", name)
result, err := db.Exec(insertQuery)
if err != nil {
return err
}
// Get user id
id, err := result.LastInsertId()
if err != nil {
return err
}
// Email(s) toevoegen
for _, email := range emails {
err := AddUserEmail(db, id, email)
if err != nil {
return err
}
}
// Ban toevoegen
err = AddUserBan(db, id, ban)
return err
}
// Remove a user from the database, including all its emails and ban entries
func RemoveUser(dq *sql.DB, userId int64) error {
panic("unimplemented")
}
// Add an email to a user
func AddUserEmail(db *sql.DB, userId int64, email string) error {
query := fmt.Sprintf("insert into Emails (Email_Id, Email) (values %d, %s)", userId, email)
_, err := db.Exec(query)
return err
}
// Remove an email from a user
func RemoveUserEmail(db *sql.DB, userId int64, email string) error {
panic("unimplemented")
}
// Add a ban to a user
func AddUserBan(db *sql.DB, userId int64, ban int) error {
query := fmt.Sprintf("insert into User_Ban (User_Id, Ban_Id) values (%d, %d)", userId, ban)
_, err := db.Exec(query)
return err
}
// Remove a ba from a user
func RemoveUserBan(db *sql.DB, userId, int64, ban int) error {
panic("unimplementted")
}