-
Notifications
You must be signed in to change notification settings - Fork 0
/
project_endpoints.go
46 lines (40 loc) · 1.49 KB
/
project_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
43
44
45
46
package endpoints
import (
"context"
"github.com/datatug/datatug/packages/api"
"github.com/datatug/datatug/packages/dto"
"github.com/sneat-co/sneat-go-core/apicore"
"net/http"
)
//var _ ProjectEndpoints = (*ProjectAgentEndpoints)(nil)
// ProjectAgentEndpoints defines project endpoints
type ProjectAgentEndpoints struct {
}
// createProject creates project
func (ProjectAgentEndpoints) createProject(w http.ResponseWriter, r *http.Request) {
request := dto.CreateProjectRequest{
StoreID: r.URL.Query().Get("store"),
}
var worker = func(ctx context.Context) (responseDTO apicore.ResponseDTO, err error) {
return api.CreateProject(ctx, request)
}
verifyOptions := VerifyRequest{
MinContentLength: int64(len(`{"title":""}`)),
MaxContentLength: 1024,
AuthRequired: true,
}
handle(w, r, &request, verifyOptions, http.StatusOK, getContextFromRequest, worker)
}
// deleteProject deletes project
func (ProjectAgentEndpoints) deleteProject(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(http.StatusNotImplemented)
_, _ = w.Write([]byte("Deletion of a DataTug project is not implemented at agent yet."))
}
// getProjectSummary a handler to return project summary
func getProjectSummary(w http.ResponseWriter, r *http.Request) {
ref := newProjectRef(r.URL.Query())
worker := func(ctx context.Context) (response apicore.ResponseDTO, err error) {
return api.GetProjectSummary(ctx, ref)
}
handle(w, r, &ref, VerifyRequest{AuthRequired: true}, http.StatusOK, getContextFromRequest, worker)
}