-
Notifications
You must be signed in to change notification settings - Fork 4
/
route.go
60 lines (49 loc) · 1.54 KB
/
route.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
package get_apps_list
import (
"net/http"
"strings"
"github.com/anti-raid/splashtail/splashcore/structparser/db"
"github.com/anti-raid/splashtail/splashcore/types"
"github.com/anti-raid/splashtail/webserver/state"
docs "github.com/infinitybotlist/eureka/doclib"
"github.com/infinitybotlist/eureka/uapi"
"go.uber.org/zap"
"github.com/jackc/pgx/v5"
)
var (
appColsArr = db.GetCols(types.AppResponse{})
appCols = strings.Join(appColsArr, ",")
)
func Docs() *docs.Doc {
return &docs.Doc{
Summary: "Get Application List",
Description: "Gets all applications of the user returning a list of apps.",
Params: []docs.Parameter{
{
Name: "user_id",
Description: "The ID of the user to use.",
Required: true,
In: "path",
Schema: docs.IdSchema,
},
},
Resp: types.AppListResponse{},
}
}
func Route(d uapi.RouteData, r *http.Request) uapi.HttpResponse {
row, err := state.Pool.Query(d.Context, "SELECT "+appCols+" FROM apps WHERE user_id = $1", d.Auth.ID)
if err != nil {
state.Logger.Error("Failed to fetch application list [db fetch]", zap.String("userId", d.Auth.ID), zap.Error(err))
return uapi.DefaultResponse(http.StatusInternalServerError)
}
app, err := pgx.CollectRows(row, pgx.RowToStructByName[types.AppResponse])
if err != nil {
state.Logger.Error("Failed to fetch application list [collection]", zap.String("userId", d.Auth.ID), zap.Error(err))
return uapi.DefaultResponse(http.StatusNotFound)
}
return uapi.HttpResponse{
Json: types.AppListResponse{
Apps: app,
},
}
}