-
Notifications
You must be signed in to change notification settings - Fork 0
/
handler_subfeature.go
57 lines (50 loc) · 2.39 KB
/
handler_subfeature.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
package goacl
import (
"fmt"
"net/http"
"github.com/labstack/echo/v4"
"github.com/tlabdotcom/gohelper"
"github.com/tlabdotcom/goresponse"
)
// SubFeature handlers
// func (a *ACL) listSubFeatureHandler(c echo.Context) error {
// datas, err := a.ListSubFeatures(c.Request().Context())
// if err != nil {
// return goresponse.NewStandardErrorResponse(http.StatusInternalServerError).AddError(err).JSON(c)
// }
// return c.JSON(http.StatusOK, goresponse.GenerateSingleDataResponse(datas, "success", http.StatusOK))
// }
// func (a *ACL) createSubFeatureHandler(c echo.Context) error {
// subFeature := new(SubFeature)
// if err := c.Bind(subFeature); err != nil {
// return goresponse.NewStandardErrorResponse(http.StatusUnprocessableEntity).AddError(err).JSON(c)
// }
// if err := a.CreateSubFeature(c.Request().Context(), subFeature); err != nil {
// return goresponse.NewStandardErrorResponse(http.StatusInternalServerError).AddError(err).JSON(c)
// }
// return c.JSON(http.StatusCreated, goresponse.GenerateSingleDataResponse(subFeature, "SubFeature created successfully", http.StatusCreated))
// }
func (a *ACL) updateSubFeatureHandler(c echo.Context) error {
params := new(SubFeatureParam)
if err := c.Bind(params); err != nil {
return goresponse.NewStandardErrorResponse(http.StatusUnprocessableEntity).AddError(err).JSON(c)
}
if err := a.UpdateSubFeature(c.Request().Context(), params); err != nil {
return goresponse.NewStandardErrorResponse(http.StatusInternalServerError).AddError(err).JSON(c)
}
data, err := a.GetSubFeatureByID(c.Request().Context(), params.ID)
if err != nil {
return goresponse.NewStandardErrorResponse(http.StatusInternalServerError).AddError(err).JSON(c)
}
return c.JSON(http.StatusOK, goresponse.GenerateSingleDataResponse(data, "SubFeature updated successfully", http.StatusOK))
}
func (a *ACL) deleteSubFeatureHandler(c echo.Context) error {
subFeatureID, err := gohelper.StringToInt64(c.Param("id"))
if err != nil {
return goresponse.NewStandardErrorResponse(http.StatusUnprocessableEntity).AddError(err).JSON(c)
}
if err := a.DeleteSubFeature(c.Request().Context(), subFeatureID); err != nil {
return goresponse.NewStandardErrorResponse(http.StatusInternalServerError).AddError(err).JSON(c)
}
return c.JSON(http.StatusOK, goresponse.GenerateSingleDataResponse(fmt.Sprintf("SubFeature %d deleted", subFeatureID), "SubFeature deleted successfully", http.StatusOK))
}