-
Notifications
You must be signed in to change notification settings - Fork 4
/
resource.go
65 lines (53 loc) · 1.37 KB
/
resource.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
65
package handler
import (
"net/http"
"github.com/labstack/echo"
"github.com/x-color/vue-trello/model"
"github.com/x-color/vue-trello/usecase"
)
// Tag includes response data for Tag.
type Tag struct {
ID string `json:"id"`
Name string `json:"title"`
Color string `json:"color"`
}
// Resources includes response data for Resources.
type Resources struct {
Colors []string `json:"colors"`
Tags []Tag `json:"tags"`
}
func (r *Resources) convertFrom(tags model.Tags, colors model.Colors) {
r.Tags = []Tag{}
for _, tag := range tags {
r.Tags = append(r.Tags, Tag{
ID: tag.ID,
Name: tag.Name,
Color: string(tag.Color),
})
}
cs := []string{}
for _, color := range colors {
cs = append(cs, string(color))
}
r.Colors = cs
}
// ResourceHandler includes a interactor for Resources usecase.
type ResourceHandler struct {
intractor usecase.ResourceUsecase
}
// NewResourceHandler returns a new ResourceHandler.
func NewResourceHandler(r usecase.ResourceUsecase) ResourceHandler {
return ResourceHandler{
intractor: r,
}
}
// Get is http handler to get resources process.
func (h *ResourceHandler) Get(c echo.Context) error {
tags, colors, err := h.intractor.GetAllTagsandColors()
if err != nil {
return convertToHTTPError(c, err)
}
resResources := Resources{}
resResources.convertFrom(tags, colors)
return c.JSON(http.StatusOK, resResources)
}