-
Notifications
You must be signed in to change notification settings - Fork 1
/
list.go
46 lines (39 loc) · 1.08 KB
/
list.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
package loginLogs
import (
"github.com/valyala/fasthttp"
"src.goblgobl.com/authen"
"src.goblgobl.com/utils"
"src.goblgobl.com/utils/http"
"src.goblgobl.com/utils/validation"
"src.goblgobl.com/authen/storage"
"src.goblgobl.com/authen/storage/data"
_ "src.goblgobl.com/authen/tests"
)
var (
listValidation = validation.Input().
Field(userIdValidation).
Field(validation.Int("page").Min(1).Default(1)).
Field(validation.Int("perpage").Min(1).Max(100).Default(10))
)
func List(conn *fasthttp.RequestCtx, env *authen.Env) (http.Response, error) {
validator := env.Validator
input, ok := listValidation.ValidateArgs(conn.QueryArgs(), validator)
if !ok {
return http.Validation(validator), nil
}
limit, offset := utils.Paging(input.Int("perpage"), input.Int("page"), 10)
res, err := storage.DB.LoginLogGet(data.LoginLogGet{
Limit: limit,
Offset: offset,
ProjectId: env.Project.Id,
UserId: input.String("user_id"),
})
if err != nil {
return nil, err
}
return http.Ok(struct {
Results []data.LoginLogRecord `json:"results"`
}{
Results: res.Records,
}), nil
}