forked from ebhomengo/niki
67 lines
2.7 KiB
Go
67 lines
2.7 KiB
Go
|
package agentkindboxhandler
|
||
|
|
||
|
import (
|
||
|
"git.gocasts.ir/ebhomengo/niki/entity"
|
||
|
"git.gocasts.ir/ebhomengo/niki/pkg/claim"
|
||
|
"net/http"
|
||
|
|
||
|
param "git.gocasts.ir/ebhomengo/niki/param/agent/kind_box"
|
||
|
httpmsg "git.gocasts.ir/ebhomengo/niki/pkg/http_msg"
|
||
|
queryparam "git.gocasts.ir/ebhomengo/niki/pkg/query_param"
|
||
|
"github.com/labstack/echo/v4"
|
||
|
)
|
||
|
|
||
|
// GetAll godoc
|
||
|
// @Summary Get all awaiting return KindBoxes by agent
|
||
|
// @Description Retrieves a list of all awaiting return KindBoxes for agent with filtering, sorting, and pagination options
|
||
|
// @Tags KindBox
|
||
|
// @Accept json
|
||
|
// @Produce json
|
||
|
// @Param filter_id query int false "Filter by ID"
|
||
|
// @Param filter_benefactor_id query int false "Filter by benefactor ID"
|
||
|
// @Param filter_type query entity.KindBoxType false "Filter by KindBox type" Format(enum)
|
||
|
// @Param filter_serial_number query string false "Filter by serial number"
|
||
|
// @Param filter_return_refer_time_id query int false "Filter by return refer time ID"
|
||
|
// @Param filter_return_refer_date query string false "Filter by return refer date" Format(date)
|
||
|
// @Param filter_return_address_id query int false "Filter by return address ID"
|
||
|
// @Param page_number query int false "Page number"
|
||
|
// @Param page_size query int false "Page size"
|
||
|
// @Param sort_field query string false "Sort by field" Enums(id,benefactor_id,type,serial_number,return_refer_time_id,return_refer_date,return_address_id)
|
||
|
// @Param sort_direction query string false "Sort order" Enums(asc,desc)
|
||
|
// @Success 200 {object} param.GetAllResponse
|
||
|
// @Failure 400 {string} "Bad Request"
|
||
|
// @Failure 401 {string} "invalid or expired jwt"
|
||
|
// @Failure 403 {string} "user not allowed"
|
||
|
// @Failure 422 {object} httpmsg.ErrorResponse
|
||
|
// @Failure 500 {string} "something went wrong"
|
||
|
// @Security AuthBearerAdmin
|
||
|
// @Router /agents/kindboxes [get]
|
||
|
func (h Handler) GetAll(c echo.Context) error {
|
||
|
var req param.GetAllRequest
|
||
|
|
||
|
if err := c.Bind(&req); err != nil {
|
||
|
return echo.NewHTTPError(http.StatusBadRequest)
|
||
|
}
|
||
|
|
||
|
req.Filter = queryparam.GetFilterParams(c)
|
||
|
if fieldErrors, err := h.agentKindBoxVld.ValidateGetAll(req); err != nil {
|
||
|
msg, code := httpmsg.Error(err)
|
||
|
|
||
|
return c.JSON(code, httpmsg.ErrorResponse{
|
||
|
Message: msg,
|
||
|
Errors: fieldErrors,
|
||
|
})
|
||
|
}
|
||
|
req.Filter["receiver_agent_id"] = claim.GetClaimsFromEchoContext(c).UserID
|
||
|
req.Filter["status"] = entity.KindBoxAssignedReceiverAgentStatus.String()
|
||
|
|
||
|
resp, err := h.agentKindBoxSvc.GetAll(c.Request().Context(), req)
|
||
|
if err != nil {
|
||
|
msg, code := httpmsg.Error(err)
|
||
|
|
||
|
return echo.NewHTTPError(code, msg)
|
||
|
}
|
||
|
|
||
|
return c.JSON(http.StatusOK, resp)
|
||
|
}
|