-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrest_get_archives.go
More file actions
48 lines (40 loc) · 938 Bytes
/
rest_get_archives.go
File metadata and controls
48 lines (40 loc) · 938 Bytes
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
package main
import (
"knowlgraph.com/ent"
"knowlgraph.com/ent/archive"
"knowlgraph.com/ent/predicate"
"knowlgraph.com/ent/user"
)
func getArchives(c *Context) error {
var _query struct {
Status archive.Status `form:"status"`
}
err := c.ShouldBindQuery(&_query)
if err != nil {
return c.BadRequest(err.Error())
}
_userID := c.GetInt(GinKeyUserID)
var _archiveWhere []predicate.Archive
_archiveWhere = append(
_archiveWhere,
archive.HasUserWith(
user.ID(_userID)))
if _query.Status.String() != "" {
_archiveWhere = append(_archiveWhere, archive.StatusEQ(_query.Status))
}
_archives, err := client.Archive.
Query().
Where(_archiveWhere...).
WithNode(func(nq *ent.NodeQuery) {
nq.WithWord().
WithPath(func(nq *ent.NodeQuery) {
nq.WithWord()
})
}).
Order(ent.Desc(archive.FieldCreatedAt)).
All(ctx)
if err != nil {
return c.NotFound(err.Error())
}
return c.Ok(_archives)
}