forked from kodekloudhub/go-webapp-sample
-
Notifications
You must be signed in to change notification settings - Fork 0
/
category.go
33 lines (28 loc) · 1.04 KB
/
category.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
package controller
import (
"net/http"
"github.com/labstack/echo/v4"
"github.com/ybkuroki/go-webapp-sample/container"
"github.com/ybkuroki/go-webapp-sample/service"
)
// CategoryController is a controller for managing category data.
type CategoryController struct {
container container.Container
service *service.CategoryService
}
// NewCategoryController is constructor.
func NewCategoryController(container container.Container) *CategoryController {
return &CategoryController{container: container, service: service.NewCategoryService(container)}
}
// GetCategoryList returns the list of all categories.
// @Summary Get a category list
// @Description Get a category list
// @Tags Categories
// @Accept json
// @Produce json
// @Success 200 {array} model.Category "Success to fetch a category list."
// @Failure 401 {string} false "Failed to the authentication."
// @Router /categories [get]
func (controller *CategoryController) GetCategoryList(c echo.Context) error {
return c.JSON(http.StatusOK, controller.service.FindAllCategories())
}