This repository has been archived by the owner on Feb 4, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Clients.go
47 lines (42 loc) · 1.51 KB
/
Clients.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
package main
func GetAllClients(request *APIRequest) *APIResponse {
return ValidateAndSelectAll(
request,
&[]Client{},
"SELECT Clients.* FROM Clients JOIN Users ON Users.ID = Clients.UserID WHERE Users.ApiKey = :ApiKey",
[]string { "ApiKey" },
)
}
func GetClient(request *APIRequest) *APIResponse {
return ValidateAndSelectOne(
request,
&Client{},
"SELECT Clients.* FROM Clients JOIN Users ON Users.ID = Clients.UserID WHERE Users.ApiKey = :ApiKey AND Clients.ID = :ID",
[]string { "ApiKey", "ID" },
)
}
func AddClient(request *APIRequest) *APIResponse {
return ValidateAndInsert(
request,
"INSERT INTO Clients(UserID, ServerID, AccountID, ScriptName, ScriptArguments, World) VALUES(:UserID, (SELECT Accounts.ID FROM Accounts WHERE Accounts.UserID = :UserID AND Accounts.ID = :AccountID), (SELECT Servers.ID FROM Servers WHERE Servers.UserID = :UserID AND Servers.ID = :ID), :ScriptName, :ScriptArguments, :World)",
[]string { "ApiKey", "IPAddress", "Name" },
)
}
func UpdateClient(request *APIRequest) *APIResponse {
return ValidateAndUpdateFromStruct(
request,
&Server{},
"Servers",
"UPDATE Clients JOIN Users ON Users.ID = Clients.UserID SET",
" WHERE Users.ApiKey = :ApiKey AND Clients.ID = :ID",
[]string { "ApiKey", "ID" },
"UserID",
)
}
func DeleteClient(request *APIRequest) *APIResponse {
return ValidateAndDelete(
request,
`DELETE Clients FROM Clients JOIN Users ON Users.ID = Clients.UserID WHERE Users.ApiKey = :ApiKey AND Clients.ID = :ID`,
[]string { "ApiKey", "ID" },
)
}