Add License
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -17,8 +17,9 @@ type License struct {
|
||||
}
|
||||
|
||||
type LicenseParam struct {
|
||||
Limit int `form:"limit,default=10"`
|
||||
Offset int `form:"offset,default=0"`
|
||||
Limit int `form:"limit,default=10"`
|
||||
Offset int `form:"offset,default=0"`
|
||||
Status string `form:"status,default="`
|
||||
}
|
||||
|
||||
func (r *License) ToEntity() (*entity.License, error) {
|
||||
|
||||
@@ -12,8 +12,10 @@ type License struct {
|
||||
RenewalDate string `json:"renewal_date,omitempty"`
|
||||
SerialNumber string `json:"serial_number"`
|
||||
PartnerID int64 `json:"partner_id"`
|
||||
CreatedBy int64 `json:"created_by"`
|
||||
CreatedBy string `json:"created_by"`
|
||||
UpdatedBy int64 `json:"updated_by"`
|
||||
PartnerName string `json:"partner_name"`
|
||||
Status string `json:"status"`
|
||||
}
|
||||
|
||||
type LicenseList struct {
|
||||
@@ -33,8 +35,10 @@ func (r *License) FromEntity(e *entity.License) {
|
||||
}
|
||||
r.SerialNumber = e.SerialNumber
|
||||
r.PartnerID = e.PartnerID
|
||||
r.CreatedBy = e.CreatedBy
|
||||
r.CreatedBy = e.CreatedByName
|
||||
r.UpdatedBy = e.UpdatedBy
|
||||
r.PartnerName = e.PartnerName
|
||||
r.Status = e.LicenseStatus
|
||||
}
|
||||
|
||||
func FromEntityList(entities []*entity.License) []License {
|
||||
|
||||
Reference in New Issue
Block a user