feat: site count

This commit is contained in:
ferdiansyah783
2024-07-27 15:26:00 +07:00
parent dfed117d90
commit 4013b12ac9
8 changed files with 94 additions and 6 deletions
+27 -1
View File
@@ -26,6 +26,7 @@ func (h *Handler) Route(group *gin.RouterGroup, jwt gin.HandlerFunc) {
route.PUT("/:id", jwt, h.Update)
route.GET("/:id", jwt, h.GetByID)
route.DELETE("/:id", jwt, h.Delete)
route.GET("/count", jwt, h.Count)
}
func NewHandler(service services.Site) *Handler {
@@ -148,7 +149,8 @@ func (h *Handler) GetAll(c *gin.Context) {
return
}
Sites, total, err := h.service.GetAll(c.Request.Context(), req.ToEntity())
ctx := request.GetMyContext(c)
Sites, total, err := h.service.GetAll(c.Request.Context(), req.ToEntity(ctx))
if err != nil {
response.ErrorWrapper(c, err)
return
@@ -242,6 +244,30 @@ func (h *Handler) GetByID(c *gin.Context) {
})
}
func (h *Handler) Count(c *gin.Context) {
var req request.SiteParam
if err := c.ShouldBindQuery(&req); err != nil {
response.ErrorWrapper(c, errors.ErrorBadRequest)
return
}
ctx := request.GetMyContext(c)
res, err := h.service.Count(ctx, req.ToEntity(ctx))
if err != nil {
response.ErrorWrapper(c, err)
return
}
c.JSON(http.StatusOK, response.BaseResponse{
Success: true,
Status: http.StatusOK,
Data: response.SiteCount{
Count: res.Count,
},
})
}
func (h *Handler) toSiteResponse(resp *entity.Site) response.Site {
return response.Site{
ID: &resp.ID,