-
Notifications
You must be signed in to change notification settings - Fork 0
/
remove.go
47 lines (39 loc) · 956 Bytes
/
remove.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
package handlers
import (
"context"
"net/http"
"github.com/dmibod/kanban/shared/kernel"
"github.com/dmibod/kanban/shared/tools/logger"
"github.com/dmibod/kanban/shared/tools/mux"
"github.com/go-chi/render"
)
// Remove operation
func Remove(id string, service RemoveService, l logger.Logger) Operation {
return &removeOperation{
id: id,
service: service,
Logger: l,
}
}
// RemoveService interface
type RemoveService interface {
Remove(context.Context, kernel.ID) error
}
type removeOperation struct {
logger.Logger
id string
service RemoveService
}
// Execute remove
func (o *removeOperation) Execute(w http.ResponseWriter, r *http.Request) {
if err := o.service.Remove(r.Context(), kernel.ID(o.id)); err != nil {
o.Errorln(err)
mux.RenderError(w, http.StatusInternalServerError)
return
}
resp := struct {
ID string `json:"id"`
Success bool `json:"success"`
}{o.id, true}
render.JSON(w, r, resp)
}