-
Notifications
You must be signed in to change notification settings - Fork 1
/
notes.go
46 lines (39 loc) · 972 Bytes
/
notes.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 handler
import (
"net/http"
"github.com/labstack/echo/v4"
"github.com/shoriwe/tulip/store"
)
func (h *Handler) CreateNote(ctx echo.Context) error {
var note store.Note
bindErr := ctx.Bind(¬e)
if bindErr != nil {
return bindErr
}
return h.store.CreateNote(note.Name, note.Content)
}
func (h *Handler) ListNotes(ctx echo.Context) error {
notes, lErr := h.store.ListNotes()
if lErr != nil {
return lErr
}
return ctx.JSON(http.StatusOK, notes)
}
func (h *Handler) GetNote(ctx echo.Context) error {
note, gErr := h.store.GetNote(ctx.Param(NameParam))
if gErr != nil {
return gErr
}
return ctx.JSON(http.StatusOK, note)
}
func (h *Handler) UpdateNote(ctx echo.Context) error {
var note store.Note
bindErr := ctx.Bind(¬e)
if bindErr != nil {
return bindErr
}
return h.store.UpdateNote(ctx.Param(NameParam), note.Content)
}
func (h *Handler) DeleteNote(ctx echo.Context) error {
return h.store.DeleteNote(ctx.Param(NameParam))
}