package adminbenefactorhandler import ( params "git.gocasts.ir/ebhomengo/niki/param" adminaddressparam "git.gocasts.ir/ebhomengo/niki/param/admin/address" adminkindboxparam "git.gocasts.ir/ebhomengo/niki/param/admin/kind_box" adminkindboxreqparam "git.gocasts.ir/ebhomengo/niki/param/admin/kind_box_req" "net/http" param "git.gocasts.ir/ebhomengo/niki/param/admin/benefactor" httpmsg "git.gocasts.ir/ebhomengo/niki/pkg/http_msg" "github.com/labstack/echo/v4" ) // GetBenefactor godoc // @Summary Get benefactor details by id // @Description This endpoint retrieves details for a specific benefactor. // @Tags Admins Benefactors // @Accept json // @Produce json // @Param id path int true "Benefactor ID" // @Success 200 {object} BenefactorAggregatedResponse // @Failure 400 {string} "Bad request" // @Failure 401 {string} "invalid or expired jwt" // @Failure 403 {string} "user not allowed" // @Failure 404 {string} "record not found" // @Failure 500 {string} "something went wrong" // @Security AuthBearerAdmin // @Router /admins/benefactors/{id} [get]. func (h Handler) GetBenefactor(c echo.Context) error { var req param.GetBenefactorByIDRequest if err := c.Bind(&req); err != nil { return echo.NewHTTPError(http.StatusBadRequest) } bnf, err := h.benefactorSvc.GetByID(c.Request().Context(), req) if err != nil { msg, code := httpmsg.Error(err) return echo.NewHTTPError(code, msg) } addresses, err := h.addressSvc.GetAll(c.Request().Context(), adminaddressparam.GetAllAddressesRequest{ BenefactorID: bnf.Data.ID, }) if err != nil { msg, code := httpmsg.Error(err) return echo.NewHTTPError(code, msg) } kindBoxes, err := h.kindBoxSvc.GetAll(c.Request().Context(), adminkindboxparam.KindBoxGetAllRequest{ Pagination: params.PaginationRequest{ PageSize: 50, PageNumber: 1, }, Sort: params.SortRequest{ Field: "created_at", Direction: params.DescSortDirection, }, Filter: map[string]any{ "benefactor_id": bnf.Data.ID, }, }) if err != nil { msg, code := httpmsg.Error(err) return echo.NewHTTPError(code, msg) } kindBoxReqs, err := h.kindBoxReqSvc.GetAll(c.Request().Context(), adminkindboxreqparam.KindBoxReqGetAllRequest{ Pagination: params.PaginationRequest{ PageSize: 50, PageNumber: 1, }, Sort: params.SortRequest{ Field: "created_at", Direction: params.DescSortDirection, }, Filter: map[string]any{ "benefactor_id": bnf.Data.ID, }, }) if err != nil { msg, code := httpmsg.Error(err) return echo.NewHTTPError(code, msg) } resp := BenefactorAggregatedResponse{ Data: Data{ Benefactor: bnf.Data, Addresses: addresses.Data, KindBoxes: kindBoxes.Data, KindBoxReqs: kindBoxReqs.Data, }, } return c.JSON(http.StatusOK, resp) }