-
Notifications
You must be signed in to change notification settings - Fork 0
/
routes_indexers.go
97 lines (77 loc) · 2.64 KB
/
routes_indexers.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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
package app
import (
"net/http"
"github.com/labstack/echo/v4"
)
func (a *Application) IndexersIndex(c echo.Context, page int, limit int) error {
list, count, err := a.DB.IndexerList(page, limit)
if err != nil {
return err
}
return c.JSON(http.StatusOK, &Response{Total: count, Result: list})
}
func (a *Application) IndexersCreate(c echo.Context, subject *Indexer) error {
if err := a.DB.Indexer.Save(subject); err != nil {
return err
}
return c.JSON(http.StatusOK, &Response{Error: false, Result: subject})
}
func (a *Application) IndexersShow(c echo.Context, id string) error {
subject, err := a.DB.Indexer.Get(id, &Indexer{})
if err != nil {
return err
}
return c.JSON(http.StatusOK, &Response{Error: false, Result: subject})
}
func (a *Application) IndexersUpdate(c echo.Context, id string, subject *Indexer) error {
if err := a.DB.Indexer.Save(subject); err != nil {
return err
}
return c.JSON(http.StatusOK, &Response{Error: false, Result: subject})
}
func (a *Application) IndexersSettings(c echo.Context, id string, setting *Setting) error {
subject, err := a.DB.IndexerGet(id)
if err != nil {
return err
}
switch setting.Name {
case "active":
subject.Active = setting.Value
}
if err := a.DB.Indexer.Save(subject); err != nil {
return err
}
return c.JSON(http.StatusOK, &Response{Error: false, Result: setting})
}
func (a *Application) IndexersDelete(c echo.Context, id string) error {
// asssuming this is a CRUD route, get the subject from the database
subject, err := a.DB.Indexer.Get(id, &Indexer{})
if err != nil {
return err
}
if err := a.DB.Indexer.Delete(subject); err != nil {
return err
}
return c.JSON(http.StatusOK, &Response{Error: false, Result: subject})
}
func (a *Application) IndexersRefresh(c echo.Context, id string) error {
if id == "all" {
if err := a.Workers.Enqueue(&ParseActive{}); err != nil {
return c.JSON(http.StatusInternalServerError, &Response{Error: true, Message: err.Error()})
}
return c.JSON(http.StatusOK, &Response{Error: false})
} else if id == "rift" {
if err := a.Workers.Enqueue(&ParseRift{}); err != nil {
return c.JSON(http.StatusInternalServerError, &Response{Error: true, Message: err.Error()})
}
return c.JSON(http.StatusOK, &Response{Error: false})
}
indexer, err := a.DB.IndexerByName(id)
if err != nil {
return c.JSON(http.StatusInternalServerError, &Response{Error: true, Message: err.Error()})
}
if err := a.Workers.Enqueue(&ParseIndexer{ID: indexer.ID.Hex(), Title: indexer.Name}); err != nil {
return c.JSON(http.StatusInternalServerError, &Response{Error: true, Message: err.Error()})
}
return c.JSON(http.StatusOK, &Response{Error: false})
}