forked from mdouchement/standardfile
-
Notifications
You must be signed in to change notification settings - Fork 0
/
item_handlers.go
64 lines (51 loc) · 1.55 KB
/
item_handlers.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
package server
import (
"net/http"
"github.com/labstack/echo/v4"
"github.com/cherya/standardfile/internal/database"
"github.com/cherya/standardfile/internal/server/service"
"github.com/cherya/standardfile/internal/sferror"
)
// item contains all item handlers.
type item struct {
db database.Client
}
///// Sync
////
//
// Sync used for saves local changes as well as retrieves remote changes.
// https://standardfile.org/#post-items-sync
func (h *item) Sync(c echo.Context) error {
// Filter params
var params service.SyncParams
if err := c.Bind(¶ms); err != nil {
return c.JSON(http.StatusBadRequest, sferror.New("Could not get syncing params."))
}
params.UserAgent = c.Request().UserAgent()
params.Session = currentSession(c)
sync := service.NewSync(h.db, currentUser(c), params)
if err := sync.Execute(); err != nil {
return err
}
return c.JSON(http.StatusOK, sync)
}
///// Backup
////
//
// Backup used for writes all user data to backup extension.
// This is called when a new extension is registered.
func (h *item) Backup(c echo.Context) error {
// In reference implementation, there is post_to_extension but not implemented here.
// See README.md
return c.NoContent(http.StatusOK)
}
///// Delete
////
//
// Delete used for remove all defined items.
func (h *item) Delete(c echo.Context) error {
// user := currentUser(c)
// https://github.com/standardfile/ruby-server/blob/master/app/controllers/api/items_controller.rb#L72-L76
// TODO undocumented feature and seems not used by official client.
return c.NoContent(http.StatusNoContent)
}