feat: add dashboard summary endpoint and related models, queries, and services
This commit is contained in:
43
internal/services/dashboard_service.go
Normal file
43
internal/services/dashboard_service.go
Normal file
@@ -0,0 +1,43 @@
|
||||
package services
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"strconv"
|
||||
"wm-backend/global"
|
||||
"wm-backend/internal/repositories"
|
||||
"wm-backend/response"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/jackc/pgx/v5/pgtype"
|
||||
"github.com/rs/zerolog/log"
|
||||
)
|
||||
|
||||
// @Summary Get dashboard summary
|
||||
// @Description Retrieve dashboard summary with key statistics
|
||||
// @Tags dashboard
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Param warehouse_id query int false "Filter by warehouse ID"
|
||||
// @Success 200 {object} response.SuccessResponse{data=models.DashboardSummary}
|
||||
// @Failure 500 {object} response.ErrorResponse
|
||||
// @Router /v1/dashboard/summary [get]
|
||||
func DashboardSummary(c *gin.Context) error {
|
||||
var warehouseID pgtype.Int8
|
||||
if raw := c.Query("warehouse_id"); raw != "" {
|
||||
id, err := strconv.ParseInt(raw, 10, 64)
|
||||
if err != nil {
|
||||
response.BadRequestError(c, http.StatusBadRequest, "Invalid warehouse_id")
|
||||
return nil
|
||||
}
|
||||
warehouseID = pgtype.Int8{Int64: id, Valid: true}
|
||||
}
|
||||
|
||||
summary, err := repositories.GetDashboardSummary(c.Request.Context(), global.Queries, warehouseID)
|
||||
if err != nil {
|
||||
log.Err(err).Msg("Error when Get Dashboard Summary")
|
||||
response.InternalServerError(c, http.StatusInternalServerError, "Failed to get dashboard summary")
|
||||
return nil
|
||||
}
|
||||
response.Ok(c, "Success", summary)
|
||||
return nil
|
||||
}
|
||||
Reference in New Issue
Block a user