Add License

This commit is contained in:
aditya.siregar
2024-07-29 22:30:29 +07:00
parent 6a987f78b9
commit f645f23fd4
9 changed files with 82 additions and 30 deletions
+9 -5
View File
@@ -4,6 +4,7 @@ import (
"furtuna-be/internal/common/errors"
"furtuna-be/internal/handlers/request"
"furtuna-be/internal/handlers/response"
"furtuna-be/internal/middlewares"
"furtuna-be/internal/services"
"github.com/gin-gonic/gin"
"github.com/go-playground/validator/v10"
@@ -16,11 +17,12 @@ type Handler struct {
func (h *Handler) Route(group *gin.RouterGroup, jwt gin.HandlerFunc) {
route := group.Group("/license")
isAdmin := middlewares.IsAdminMiddleware()
route.POST("/", jwt, h.Create)
route.GET("/", jwt, h.GetAll)
route.PUT("/:id", jwt, h.Update)
route.GET("/:id", jwt, h.GetByID)
route.POST("/", jwt, isAdmin, h.Create)
route.GET("/", jwt, isAdmin, h.GetAll)
route.PUT("/:id", jwt, isAdmin, h.Update)
route.GET("/:id", jwt, isAdmin, h.GetByID)
}
func NewHandler(service services.License) *Handler {
@@ -115,7 +117,9 @@ func (h *Handler) GetAll(c *gin.Context) {
return
}
licenses, total, err := h.service.GetAll(c.Request.Context(), req.Limit, req.Offset)
ctx := request.GetMyContext(c)
licenses, total, err := h.service.GetAll(ctx, req.Limit, req.Offset, req.Status)
if err != nil {
response.ErrorWrapper(c, err)
return