-
Notifications
You must be signed in to change notification settings - Fork 0
/
board_endpoints.go
42 lines (37 loc) · 1.24 KB
/
board_endpoints.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
package endpoints
import (
"context"
"github.com/datatug/datatug/packages/api"
"github.com/datatug/datatug/packages/dto"
"github.com/datatug/datatug/packages/models"
"github.com/sneat-co/sneat-go-core/apicore"
"github.com/strongo/random"
"net/http"
)
// getBoard handles get board endpoint
func getBoard(w http.ResponseWriter, r *http.Request) {
var ref dto.ProjectItemRef
getProjectItem(w, r, &ref, func(ctx context.Context) (responseDTO apicore.ResponseDTO, err error) {
return api.GetBoard(ctx, ref)
})
}
// createBoard handles board creation endpoint
func createBoard(w http.ResponseWriter, r *http.Request) {
var ref dto.ProjectRef
var board models.Board
board.ID = models.AutoID
createProjectItem(w, r, &ref, &board, func(ctx context.Context) (apicore.ResponseDTO, error) {
board.ID = random.ID(9)
return api.CreateBoard(ctx, ref, board)
})
}
// saveBoard handles save board endpoint
func saveBoard(w http.ResponseWriter, r *http.Request) {
var ref dto.ProjectItemRef
var board models.Board
saveProjectItem(w, r, &ref, &board, func(ctx context.Context) (apicore.ResponseDTO, error) {
return api.SaveBoard(ctx, ref.ProjectRef, board)
})
}
// deleteBoard handles delete board endpoint
var deleteBoard = deleteProjItem(api.DeleteBoard)