feat(admin): append nested data in kindbox and kindboxreq(#208)

This commit is contained in:
Hamed Xamani 2024-11-19 10:13:56 +03:30
parent 1d14e86602
commit 4e97455049
36 changed files with 944 additions and 158 deletions

View File

@ -0,0 +1,17 @@
package adminaddresshandler
import (
param "git.gocasts.ir/ebhomengo/niki/param/admin/address"
admincityparam "git.gocasts.ir/ebhomengo/niki/param/admin/city"
adminprovinceparam "git.gocasts.ir/ebhomengo/niki/param/admin/province"
)
type Info struct {
Province adminprovinceparam.Data `json:"province"`
City admincityparam.Data `json:"city"`
}
type Address struct {
Address param.Data `json:"address"`
Info Info `json:"info"`
}

View File

@ -7,13 +7,13 @@ import (
adminkindboxreqparam "git.gocasts.ir/ebhomengo/niki/param/admin/kind_box_req"
)
type Data struct {
Benefactor param.Data `json:"benefactor"`
type Info struct {
Addresses []adminaddressparam.Data `json:"addresses"`
KindBoxes []adminkindboxparam.Data `json:"kind_boxes"`
KindBoxReqs []adminkindboxreqparam.Data `json:"kind_box_reqs"`
}
type BenefactorAggregatedResponse struct {
Data Data `json:"data"`
Benefactor param.Data `json:"benefactor"`
Info Info `json:"info"`
}

View File

@ -88,8 +88,8 @@ func (h Handler) GetBenefactor(c echo.Context) error {
}
resp := BenefactorAggregatedResponse{
Data: Data{
Benefactor: bnf.Data,
Info: Info{
Addresses: addresses.Data,
KindBoxes: kindBoxes.Data,
KindBoxReqs: kindBoxReqs.Data,

View File

@ -0,0 +1,21 @@
package adminkindboxhandler
import (
adminaddresshandler "git.gocasts.ir/ebhomengo/niki/delivery/http_server/admin/address"
adminbenefactorparam "git.gocasts.ir/ebhomengo/niki/param/admin/benefactor"
param "git.gocasts.ir/ebhomengo/niki/param/admin/kind_box"
adminrefertimeparam "git.gocasts.ir/ebhomengo/niki/param/admin/refer_time"
)
type Info struct {
Benefactor adminbenefactorparam.Data `json:"benefactor"`
DeliverAddress adminaddresshandler.Address `json:"deliver_address"`
DeliverReferTime adminrefertimeparam.Data `json:"deliver_refer_time"`
ReturnAddress adminaddresshandler.Address `json:"return_address"`
ReturnReferTime adminrefertimeparam.Data `json:"return_refer_time"`
}
type KindBoxAggregatedResponse struct {
KindBox param.Data `json:"kind_box"`
Info Info `json:"info"`
}

View File

@ -15,8 +15,12 @@ import (
// @Accept json
// @Produce json
// @Param id path int true "Kind box ID"
// @Success 200 {object} param.KindBoxGetResponse
// @Success 200 {object} KindBoxAggregatedResponse
// @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/kindboxes/{id} [get].
func (h Handler) Get(c echo.Context) error {
@ -25,18 +29,88 @@ func (h Handler) Get(c echo.Context) error {
return echo.NewHTTPError(http.StatusBadRequest)
}
resp, sErr := h.adminKindBoxSvc.Get(c.Request().Context(), req)
kindBox, sErr := h.adminKindBoxSvc.Get(c.Request().Context(), req)
if sErr != nil {
msg, code := httpmsg.Error(sErr)
if resp.FieldErrors != nil {
if kindBox.FieldErrors != nil {
return c.JSON(code, echo.Map{
"message": msg,
"errors": resp.FieldErrors,
"errors": kindBox.FieldErrors,
})
}
return echo.NewHTTPError(code, msg)
}
benefactor, bErr := h.adminBenefactorAggSvc.GetByID(c.Request().Context(), kindBox.Data.BenefactorID)
if bErr != nil {
msg, code := httpmsg.Error(bErr)
if kindBox.FieldErrors != nil {
return c.JSON(code, echo.Map{
"message": msg,
})
}
return echo.NewHTTPError(code, msg)
}
deliverAddress, dAErr := h.addressAggSvc.GetAggregatedByID(c.Request().Context(), kindBox.Data.DeliverAddressID)
if dAErr != nil {
msg, code := httpmsg.Error(dAErr)
if kindBox.FieldErrors != nil {
return c.JSON(code, echo.Map{
"message": msg,
})
}
return echo.NewHTTPError(code, msg)
}
returnAddress, rAErr := h.addressAggSvc.GetAggregatedByID(c.Request().Context(), kindBox.Data.ReturnAddressID)
if rAErr != nil {
msg, code := httpmsg.Error(rAErr)
if kindBox.FieldErrors != nil {
return c.JSON(code, echo.Map{
"message": msg,
})
}
return echo.NewHTTPError(code, msg)
}
deliverReferTime, dRErr := h.referTimeAggSvc.GetReferTimeByID(c.Request().Context(), kindBox.Data.DeliverReferTimeID)
if dRErr != nil {
msg, code := httpmsg.Error(dRErr)
if kindBox.FieldErrors != nil {
return c.JSON(code, echo.Map{
"message": msg,
})
}
return echo.NewHTTPError(code, msg)
}
returnReferTime, rRErr := h.referTimeAggSvc.GetReferTimeByID(c.Request().Context(), kindBox.Data.ReturnReferTimeID)
if rRErr != nil {
msg, code := httpmsg.Error(rRErr)
if kindBox.FieldErrors != nil {
return c.JSON(code, echo.Map{
"message": msg,
})
}
return echo.NewHTTPError(code, msg)
}
resp := KindBoxAggregatedResponse{
KindBox: kindBox.Data,
Info: Info{
Benefactor: benefactor,
DeliverAddress: deliverAddress,
ReturnAddress: returnAddress,
DeliverReferTime: deliverReferTime,
ReturnReferTime: returnReferTime,
},
}
return c.JSON(http.StatusOK, resp)
}

View File

@ -1,9 +1,11 @@
package adminkindboxhandler
import (
adminaddressaggservice "git.gocasts.ir/ebhomengo/niki/service/admin/address_aggregator"
adminauthorizationservice "git.gocasts.ir/ebhomengo/niki/service/admin/authorization"
adminbenefactoraggsvc "git.gocasts.ir/ebhomengo/niki/service/admin/benefactor_aggregator"
adminkindboxservice "git.gocasts.ir/ebhomengo/niki/service/admin/kind_box"
adminrefertimeaggregatorservice "git.gocasts.ir/ebhomengo/niki/service/admin/refer_time_aggregator"
authservice "git.gocasts.ir/ebhomengo/niki/service/auth"
"git.gocasts.ir/ebhomengo/niki/service/notification"
)
@ -12,6 +14,8 @@ type Handler struct {
authSvc authservice.Service
adminKindBoxSvc adminkindboxservice.Service
adminBenefactorAggSvc adminbenefactoraggsvc.Service
addressAggSvc adminaddressaggservice.Service
referTimeAggSvc adminrefertimeaggregatorservice.Service
adminAuthorizeSvc adminauthorizationservice.Service
notificationSvc notification.Service
}
@ -19,6 +23,8 @@ type Handler struct {
func New(authSvc authservice.Service,
adminKindBoxSvc adminkindboxservice.Service,
adminBenefactorAggSvc adminbenefactoraggsvc.Service,
addressAggSvc adminaddressaggservice.Service,
referTimeAggSvc adminrefertimeaggregatorservice.Service,
adminAuthorizeSvc adminauthorizationservice.Service,
notificationSvc notification.Service,
) Handler {
@ -26,6 +32,8 @@ func New(authSvc authservice.Service,
authSvc: authSvc,
adminKindBoxSvc: adminKindBoxSvc,
adminBenefactorAggSvc: adminBenefactorAggSvc,
addressAggSvc: addressAggSvc,
referTimeAggSvc: referTimeAggSvc,
adminAuthorizeSvc: adminAuthorizeSvc,
notificationSvc: notificationSvc,
}

View File

@ -0,0 +1,19 @@
package adminkindboxreqhandler
import (
adminaddresshandler "git.gocasts.ir/ebhomengo/niki/delivery/http_server/admin/address"
adminbenefactorparam "git.gocasts.ir/ebhomengo/niki/param/admin/benefactor"
param "git.gocasts.ir/ebhomengo/niki/param/admin/kind_box_req"
adminrefertimeparam "git.gocasts.ir/ebhomengo/niki/param/admin/refer_time"
)
type Info struct {
Benefactor adminbenefactorparam.Data `json:"benefactor"`
DeliverAddress adminaddresshandler.Address `json:"deliver_address"`
DeliverReferTime adminrefertimeparam.Data `json:"deliver_refer_time"`
}
type KindBoxReqAggregatedResponse struct {
KindBoxReq param.Data `json:"kind_box_req"`
Info Info `json:"info"`
}

View File

@ -14,7 +14,7 @@ import (
// @Accept json
// @Produce json
// @Param id path int true "KindBoxReq ID"
// @Success 200 {object} param.GetKindBoxReqResponse
// @Success 200 {object} KindBoxReqAggregatedResponse
// @Failure 400 {string} "Bad Request"
// @Failure 401 {string} "invalid or expired jwt"
// @Failure 403 {string} "user not allowed"
@ -28,18 +28,62 @@ func (h Handler) Get(c echo.Context) error {
return echo.NewHTTPError(http.StatusBadRequest)
}
resp, err := h.adminKindBoxReqSvc.Get(c.Request().Context(), req)
kindBoxReq, err := h.adminKindBoxReqSvc.Get(c.Request().Context(), req)
if err != nil {
msg, code := httpmsg.Error(err)
if resp.FieldErrors != nil {
if kindBoxReq.FieldErrors != nil {
return c.JSON(code, echo.Map{
"message": msg,
"errors": resp.FieldErrors,
"errors": kindBoxReq.FieldErrors,
})
}
return echo.NewHTTPError(code, msg)
}
benefactor, bErr := h.adminBenefactorAggSvc.GetByID(c.Request().Context(), kindBoxReq.Data.BenefactorID)
if bErr != nil {
msg, code := httpmsg.Error(bErr)
if kindBoxReq.FieldErrors != nil {
return c.JSON(code, echo.Map{
"message": msg,
})
}
return echo.NewHTTPError(code, msg)
}
deliverAddress, dAErr := h.addressAggSvc.GetAggregatedByID(c.Request().Context(), kindBoxReq.Data.DeliverAddressID)
if dAErr != nil {
msg, code := httpmsg.Error(dAErr)
if kindBoxReq.FieldErrors != nil {
return c.JSON(code, echo.Map{
"message": msg,
})
}
return echo.NewHTTPError(code, msg)
}
deliverReferTime, dRErr := h.referTimeAggSvc.GetReferTimeByID(c.Request().Context(), kindBoxReq.Data.DeliverReferTimeID)
if dRErr != nil {
msg, code := httpmsg.Error(dRErr)
if kindBoxReq.FieldErrors != nil {
return c.JSON(code, echo.Map{
"message": msg,
})
}
return echo.NewHTTPError(code, msg)
}
resp := KindBoxReqAggregatedResponse{
KindBoxReq: kindBoxReq.Data,
Info: Info{
Benefactor: benefactor,
DeliverAddress: deliverAddress,
DeliverReferTime: deliverReferTime,
},
}
return c.JSON(http.StatusOK, resp)
}

View File

@ -1,9 +1,11 @@
package adminkindboxreqhandler
import (
adminaddressaggservice "git.gocasts.ir/ebhomengo/niki/service/admin/address_aggregator"
adminauthorizationservice "git.gocasts.ir/ebhomengo/niki/service/admin/authorization"
adminbenefactoraggsvc "git.gocasts.ir/ebhomengo/niki/service/admin/benefactor_aggregator"
adminkindboxreqservice "git.gocasts.ir/ebhomengo/niki/service/admin/kind_box_req"
adminrefertimeaggregatorservice "git.gocasts.ir/ebhomengo/niki/service/admin/refer_time_aggregator"
authservice "git.gocasts.ir/ebhomengo/niki/service/auth"
"git.gocasts.ir/ebhomengo/niki/service/notification"
)
@ -12,6 +14,8 @@ type Handler struct {
authSvc authservice.Service
adminKindBoxReqSvc adminkindboxreqservice.Service
adminBenefactorAggSvc adminbenefactoraggsvc.Service
addressAggSvc adminaddressaggservice.Service
referTimeAggSvc adminrefertimeaggregatorservice.Service
adminAuthorizeSvc adminauthorizationservice.Service
notificationSvc notification.Service
}
@ -19,6 +23,8 @@ type Handler struct {
func New(authSvc authservice.Service,
adminKindBoxReqSvc adminkindboxreqservice.Service,
adminBenefactorAggSvc adminbenefactoraggsvc.Service,
addressAggSvc adminaddressaggservice.Service,
referTimeAggSvc adminrefertimeaggregatorservice.Service,
adminAuthorizeSvc adminauthorizationservice.Service,
notificationSvc notification.Service,
) Handler {
@ -26,6 +32,8 @@ func New(authSvc authservice.Service,
authSvc: authSvc,
adminKindBoxReqSvc: adminKindBoxReqSvc,
adminBenefactorAggSvc: adminBenefactorAggSvc,
addressAggSvc: addressAggSvc,
referTimeAggSvc: referTimeAggSvc,
adminAuthorizeSvc: adminAuthorizeSvc,
notificationSvc: notificationSvc,
}

View File

@ -50,8 +50,8 @@ func New(
Router: echo.New(),
config: cfg,
adminHandler: adminhandler.New(svc.AdminAuthSvc, svc.AdminSvc, svc.AdminAuthorizeSvc),
adminKindBoxReqHandler: adminkindboxreqhandler.New(svc.AdminAuthSvc, svc.AdminKindBoxReqSvc, svc.AdminBenefactorAggSvc, svc.AdminAuthorizeSvc, svc.NotificationSvc),
adminKindBoxHandler: adminKindBoxHandler.New(svc.AdminAuthSvc, svc.AdminKindBoxSvc, svc.AdminBenefactorAggSvc, svc.AdminAuthorizeSvc, svc.NotificationSvc),
adminKindBoxReqHandler: adminkindboxreqhandler.New(svc.AdminAuthSvc, svc.AdminKindBoxReqSvc, svc.AdminBenefactorAggSvc, svc.AdminAddressAggSvc, svc.AdminReferTimeAggSvc, svc.AdminAuthorizeSvc, svc.NotificationSvc),
adminKindBoxHandler: adminKindBoxHandler.New(svc.AdminAuthSvc, svc.AdminKindBoxSvc, svc.AdminBenefactorAggSvc, svc.AdminAddressAggSvc, svc.AdminReferTimeAggSvc, svc.AdminAuthorizeSvc, svc.NotificationSvc),
adminAgentHandler: adminagenthandler.New(svc.AdminAuthSvc, svc.AdminAgentSvc, svc.AdminAuthorizeSvc),
adminBenefactorHandler: adminbenefactorhandler.New(svc.AdminAuthSvc, svc.AdminAuthorizeSvc, svc.AdminBenefactorSvc, svc.AdminAddressSvc, svc.AdminKindBoxSvc, svc.AdminKindBoxReqSvc),
adminReferTimeHandler: adminrefertimehandler.New(svc.AdminAuthSvc, svc.AdminReferTimeSvc, svc.AdminAuthorizeSvc),

View File

@ -452,7 +452,7 @@ const docTemplate = `{
],
"type": "string",
"description": "Filter by KindBox type",
"name": "filter_kind_box_type",
"name": "filter_type",
"in": "query"
},
{
@ -711,7 +711,7 @@ const docTemplate = `{
"200": {
"description": "OK",
"schema": {
"$ref": "#/definitions/adminkindboxparam.KindBoxGetResponse"
"$ref": "#/definitions/adminkindboxhandler.KindBoxAggregatedResponse"
}
},
"400": {
@ -719,6 +719,30 @@ const docTemplate = `{
"schema": {
"type": "string"
}
},
"401": {
"description": "invalid or expired jwt",
"schema": {
"type": "string"
}
},
"403": {
"description": "user not allowed",
"schema": {
"type": "string"
}
},
"404": {
"description": "record not found",
"schema": {
"type": "string"
}
},
"500": {
"description": "something went wrong",
"schema": {
"type": "string"
}
}
}
}
@ -1104,7 +1128,7 @@ const docTemplate = `{
"200": {
"description": "OK",
"schema": {
"$ref": "#/definitions/adminkindboxreqparam.GetKindBoxReqResponse"
"$ref": "#/definitions/adminkindboxreqhandler.KindBoxReqAggregatedResponse"
}
},
"400": {
@ -3208,6 +3232,28 @@ const docTemplate = `{
}
}
},
"adminaddresshandler.Address": {
"type": "object",
"properties": {
"address": {
"$ref": "#/definitions/adminaddressparam.Data"
},
"info": {
"$ref": "#/definitions/adminaddresshandler.Info"
}
}
},
"adminaddresshandler.Info": {
"type": "object",
"properties": {
"city": {
"$ref": "#/definitions/admincityparam.Data"
},
"province": {
"$ref": "#/definitions/adminprovinceparam.Data"
}
}
},
"adminaddressparam.Data": {
"type": "object",
"properties": {
@ -3343,12 +3389,15 @@ const docTemplate = `{
"adminbenefactorhandler.BenefactorAggregatedResponse": {
"type": "object",
"properties": {
"data": {
"$ref": "#/definitions/adminbenefactorhandler.Data"
"benefactor": {
"$ref": "#/definitions/adminbenefactoreparam.Data"
},
"info": {
"$ref": "#/definitions/adminbenefactorhandler.Info"
}
}
},
"adminbenefactorhandler.Data": {
"adminbenefactorhandler.Info": {
"type": "object",
"properties": {
"addresses": {
@ -3357,9 +3406,6 @@ const docTemplate = `{
"$ref": "#/definitions/adminaddressparam.Data"
}
},
"benefactor": {
"$ref": "#/definitions/adminbenefactoreparam.Data"
},
"kind_box_reqs": {
"type": "array",
"items": {
@ -3374,6 +3420,51 @@ const docTemplate = `{
}
}
},
"admincityparam.Data": {
"type": "object",
"properties": {
"id": {
"type": "integer"
},
"name": {
"type": "string"
},
"province_id": {
"type": "integer"
}
}
},
"adminkindboxhandler.Info": {
"type": "object",
"properties": {
"benefactor": {
"$ref": "#/definitions/adminbenefactoreparam.Data"
},
"deliver_address": {
"$ref": "#/definitions/adminaddresshandler.Address"
},
"deliver_refer_time": {
"$ref": "#/definitions/adminrefertimeparam.Data"
},
"return_address": {
"$ref": "#/definitions/adminaddresshandler.Address"
},
"return_refer_time": {
"$ref": "#/definitions/adminrefertimeparam.Data"
}
}
},
"adminkindboxhandler.KindBoxAggregatedResponse": {
"type": "object",
"properties": {
"info": {
"$ref": "#/definitions/adminkindboxhandler.Info"
},
"kind_box": {
"$ref": "#/definitions/adminkindboxparam.Data"
}
}
},
"adminkindboxparam.AssignReceiverRequest": {
"type": "object",
"properties": {
@ -3446,6 +3537,17 @@ const docTemplate = `{
}
}
},
"adminkindboxparam.Info": {
"type": "object",
"properties": {
"benefactors": {
"type": "array",
"items": {
"$ref": "#/definitions/adminbenefactoreparam.Data"
}
}
}
},
"adminkindboxparam.KindBoxGetAllResponse": {
"type": "object",
"properties": {
@ -3461,25 +3563,14 @@ const docTemplate = `{
"type": "string"
}
},
"info": {
"$ref": "#/definitions/adminkindboxparam.Info"
},
"pagination": {
"$ref": "#/definitions/param.PaginationResponse"
}
}
},
"adminkindboxparam.KindBoxGetResponse": {
"type": "object",
"properties": {
"data": {
"$ref": "#/definitions/adminkindboxparam.Data"
},
"field_errors": {
"type": "object",
"additionalProperties": {
"type": "string"
}
}
}
},
"adminkindboxparam.KindBoxUpdateRequest": {
"type": "object",
"properties": {
@ -3509,6 +3600,31 @@ const docTemplate = `{
}
}
},
"adminkindboxreqhandler.Info": {
"type": "object",
"properties": {
"benefactor": {
"$ref": "#/definitions/adminbenefactoreparam.Data"
},
"deliver_address": {
"$ref": "#/definitions/adminaddresshandler.Address"
},
"deliver_refer_time": {
"$ref": "#/definitions/adminrefertimeparam.Data"
}
}
},
"adminkindboxreqhandler.KindBoxReqAggregatedResponse": {
"type": "object",
"properties": {
"info": {
"$ref": "#/definitions/adminkindboxreqhandler.Info"
},
"kind_box_req": {
"$ref": "#/definitions/adminkindboxreqparam.Data"
}
}
},
"adminkindboxreqparam.AssignSenderRequest": {
"type": "object",
"properties": {
@ -3569,16 +3685,13 @@ const docTemplate = `{
}
}
},
"adminkindboxreqparam.GetKindBoxReqResponse": {
"adminkindboxreqparam.Info": {
"type": "object",
"properties": {
"data": {
"$ref": "#/definitions/adminkindboxreqparam.Data"
},
"field_errors": {
"type": "object",
"additionalProperties": {
"type": "string"
"benefactors": {
"type": "array",
"items": {
"$ref": "#/definitions/adminbenefactoreparam.Data"
}
}
}
@ -3667,6 +3780,9 @@ const docTemplate = `{
"type": "string"
}
},
"info": {
"$ref": "#/definitions/adminkindboxreqparam.Info"
},
"pagination": {
"$ref": "#/definitions/param.PaginationResponse"
}
@ -3736,6 +3852,31 @@ const docTemplate = `{
}
}
},
"adminprovinceparam.Data": {
"type": "object",
"properties": {
"id": {
"type": "integer"
},
"name": {
"type": "string"
}
}
},
"adminrefertimeparam.Data": {
"type": "object",
"properties": {
"duration": {
"type": "string"
},
"id": {
"type": "integer"
},
"status": {
"$ref": "#/definitions/entity.ReferTimeStatus"
}
}
},
"adminrefertimeparam.GetAllReferTimeResponse": {
"type": "object",
"properties": {

View File

@ -700,7 +700,7 @@
"200": {
"description": "OK",
"schema": {
"$ref": "#/definitions/adminkindboxparam.KindBoxGetResponse"
"$ref": "#/definitions/adminkindboxhandler.KindBoxAggregatedResponse"
}
},
"400": {
@ -708,6 +708,30 @@
"schema": {
"type": "string"
}
},
"401": {
"description": "invalid or expired jwt",
"schema": {
"type": "string"
}
},
"403": {
"description": "user not allowed",
"schema": {
"type": "string"
}
},
"404": {
"description": "record not found",
"schema": {
"type": "string"
}
},
"500": {
"description": "something went wrong",
"schema": {
"type": "string"
}
}
}
}
@ -1093,7 +1117,7 @@
"200": {
"description": "OK",
"schema": {
"$ref": "#/definitions/adminkindboxreqparam.GetKindBoxReqResponse"
"$ref": "#/definitions/adminkindboxreqhandler.KindBoxReqAggregatedResponse"
}
},
"400": {
@ -3197,6 +3221,28 @@
}
}
},
"adminaddresshandler.Address": {
"type": "object",
"properties": {
"address": {
"$ref": "#/definitions/adminaddressparam.Data"
},
"info": {
"$ref": "#/definitions/adminaddresshandler.Info"
}
}
},
"adminaddresshandler.Info": {
"type": "object",
"properties": {
"city": {
"$ref": "#/definitions/admincityparam.Data"
},
"province": {
"$ref": "#/definitions/adminprovinceparam.Data"
}
}
},
"adminaddressparam.Data": {
"type": "object",
"properties": {
@ -3332,12 +3378,15 @@
"adminbenefactorhandler.BenefactorAggregatedResponse": {
"type": "object",
"properties": {
"data": {
"$ref": "#/definitions/adminbenefactorhandler.Data"
"benefactor": {
"$ref": "#/definitions/adminbenefactoreparam.Data"
},
"info": {
"$ref": "#/definitions/adminbenefactorhandler.Info"
}
}
},
"adminbenefactorhandler.Data": {
"adminbenefactorhandler.Info": {
"type": "object",
"properties": {
"addresses": {
@ -3346,9 +3395,6 @@
"$ref": "#/definitions/adminaddressparam.Data"
}
},
"benefactor": {
"$ref": "#/definitions/adminbenefactoreparam.Data"
},
"kind_box_reqs": {
"type": "array",
"items": {
@ -3363,6 +3409,51 @@
}
}
},
"admincityparam.Data": {
"type": "object",
"properties": {
"id": {
"type": "integer"
},
"name": {
"type": "string"
},
"province_id": {
"type": "integer"
}
}
},
"adminkindboxhandler.Info": {
"type": "object",
"properties": {
"benefactor": {
"$ref": "#/definitions/adminbenefactoreparam.Data"
},
"deliver_address": {
"$ref": "#/definitions/adminaddresshandler.Address"
},
"deliver_refer_time": {
"$ref": "#/definitions/adminrefertimeparam.Data"
},
"return_address": {
"$ref": "#/definitions/adminaddresshandler.Address"
},
"return_refer_time": {
"$ref": "#/definitions/adminrefertimeparam.Data"
}
}
},
"adminkindboxhandler.KindBoxAggregatedResponse": {
"type": "object",
"properties": {
"info": {
"$ref": "#/definitions/adminkindboxhandler.Info"
},
"kind_box": {
"$ref": "#/definitions/adminkindboxparam.Data"
}
}
},
"adminkindboxparam.AssignReceiverRequest": {
"type": "object",
"properties": {
@ -3435,6 +3526,17 @@
}
}
},
"adminkindboxparam.Info": {
"type": "object",
"properties": {
"benefactors": {
"type": "array",
"items": {
"$ref": "#/definitions/adminbenefactoreparam.Data"
}
}
}
},
"adminkindboxparam.KindBoxGetAllResponse": {
"type": "object",
"properties": {
@ -3450,25 +3552,14 @@
"type": "string"
}
},
"info": {
"$ref": "#/definitions/adminkindboxparam.Info"
},
"pagination": {
"$ref": "#/definitions/param.PaginationResponse"
}
}
},
"adminkindboxparam.KindBoxGetResponse": {
"type": "object",
"properties": {
"data": {
"$ref": "#/definitions/adminkindboxparam.Data"
},
"field_errors": {
"type": "object",
"additionalProperties": {
"type": "string"
}
}
}
},
"adminkindboxparam.KindBoxUpdateRequest": {
"type": "object",
"properties": {
@ -3498,6 +3589,31 @@
}
}
},
"adminkindboxreqhandler.Info": {
"type": "object",
"properties": {
"benefactor": {
"$ref": "#/definitions/adminbenefactoreparam.Data"
},
"deliver_address": {
"$ref": "#/definitions/adminaddresshandler.Address"
},
"deliver_refer_time": {
"$ref": "#/definitions/adminrefertimeparam.Data"
}
}
},
"adminkindboxreqhandler.KindBoxReqAggregatedResponse": {
"type": "object",
"properties": {
"info": {
"$ref": "#/definitions/adminkindboxreqhandler.Info"
},
"kind_box_req": {
"$ref": "#/definitions/adminkindboxreqparam.Data"
}
}
},
"adminkindboxreqparam.AssignSenderRequest": {
"type": "object",
"properties": {
@ -3558,16 +3674,13 @@
}
}
},
"adminkindboxreqparam.GetKindBoxReqResponse": {
"adminkindboxreqparam.Info": {
"type": "object",
"properties": {
"data": {
"$ref": "#/definitions/adminkindboxreqparam.Data"
},
"field_errors": {
"type": "object",
"additionalProperties": {
"type": "string"
"benefactors": {
"type": "array",
"items": {
"$ref": "#/definitions/adminbenefactoreparam.Data"
}
}
}
@ -3656,6 +3769,9 @@
"type": "string"
}
},
"info": {
"$ref": "#/definitions/adminkindboxreqparam.Info"
},
"pagination": {
"$ref": "#/definitions/param.PaginationResponse"
}
@ -3725,6 +3841,31 @@
}
}
},
"adminprovinceparam.Data": {
"type": "object",
"properties": {
"id": {
"type": "integer"
},
"name": {
"type": "string"
}
}
},
"adminrefertimeparam.Data": {
"type": "object",
"properties": {
"duration": {
"type": "string"
},
"id": {
"type": "integer"
},
"status": {
"$ref": "#/definitions/entity.ReferTimeStatus"
}
}
},
"adminrefertimeparam.GetAllReferTimeResponse": {
"type": "object",
"properties": {

View File

@ -101,6 +101,20 @@ definitions:
example: "1234567890"
type: string
type: object
adminaddresshandler.Address:
properties:
address:
$ref: '#/definitions/adminaddressparam.Data'
info:
$ref: '#/definitions/adminaddresshandler.Info'
type: object
adminaddresshandler.Info:
properties:
city:
$ref: '#/definitions/admincityparam.Data'
province:
$ref: '#/definitions/adminprovinceparam.Data'
type: object
adminaddressparam.Data:
properties:
address:
@ -189,17 +203,17 @@ definitions:
type: object
adminbenefactorhandler.BenefactorAggregatedResponse:
properties:
data:
$ref: '#/definitions/adminbenefactorhandler.Data'
benefactor:
$ref: '#/definitions/adminbenefactoreparam.Data'
info:
$ref: '#/definitions/adminbenefactorhandler.Info'
type: object
adminbenefactorhandler.Data:
adminbenefactorhandler.Info:
properties:
addresses:
items:
$ref: '#/definitions/adminaddressparam.Data'
type: array
benefactor:
$ref: '#/definitions/adminbenefactoreparam.Data'
kind_box_reqs:
items:
$ref: '#/definitions/adminkindboxreqparam.Data'
@ -209,6 +223,35 @@ definitions:
$ref: '#/definitions/adminkindboxparam.Data'
type: array
type: object
admincityparam.Data:
properties:
id:
type: integer
name:
type: string
province_id:
type: integer
type: object
adminkindboxhandler.Info:
properties:
benefactor:
$ref: '#/definitions/adminbenefactoreparam.Data'
deliver_address:
$ref: '#/definitions/adminaddresshandler.Address'
deliver_refer_time:
$ref: '#/definitions/adminrefertimeparam.Data'
return_address:
$ref: '#/definitions/adminaddresshandler.Address'
return_refer_time:
$ref: '#/definitions/adminrefertimeparam.Data'
type: object
adminkindboxhandler.KindBoxAggregatedResponse:
properties:
info:
$ref: '#/definitions/adminkindboxhandler.Info'
kind_box:
$ref: '#/definitions/adminkindboxparam.Data'
type: object
adminkindboxparam.AssignReceiverRequest:
properties:
receiver_agent_id:
@ -256,6 +299,13 @@ definitions:
amount:
type: integer
type: object
adminkindboxparam.Info:
properties:
benefactors:
items:
$ref: '#/definitions/adminbenefactoreparam.Data'
type: array
type: object
adminkindboxparam.KindBoxGetAllResponse:
properties:
data:
@ -266,18 +316,11 @@ definitions:
additionalProperties:
type: string
type: object
info:
$ref: '#/definitions/adminkindboxparam.Info'
pagination:
$ref: '#/definitions/param.PaginationResponse'
type: object
adminkindboxparam.KindBoxGetResponse:
properties:
data:
$ref: '#/definitions/adminkindboxparam.Data'
field_errors:
additionalProperties:
type: string
type: object
type: object
adminkindboxparam.KindBoxUpdateRequest:
properties:
amount:
@ -299,6 +342,22 @@ definitions:
example: 3
type: integer
type: object
adminkindboxreqhandler.Info:
properties:
benefactor:
$ref: '#/definitions/adminbenefactoreparam.Data'
deliver_address:
$ref: '#/definitions/adminaddresshandler.Address'
deliver_refer_time:
$ref: '#/definitions/adminrefertimeparam.Data'
type: object
adminkindboxreqhandler.KindBoxReqAggregatedResponse:
properties:
info:
$ref: '#/definitions/adminkindboxreqhandler.Info'
kind_box_req:
$ref: '#/definitions/adminkindboxreqparam.Data'
type: object
adminkindboxreqparam.AssignSenderRequest:
properties:
sender_agent_id:
@ -338,14 +397,12 @@ definitions:
status:
$ref: '#/definitions/entity.KindBoxReqStatus'
type: object
adminkindboxreqparam.GetKindBoxReqResponse:
adminkindboxreqparam.Info:
properties:
data:
$ref: '#/definitions/adminkindboxreqparam.Data'
field_errors:
additionalProperties:
type: string
type: object
benefactors:
items:
$ref: '#/definitions/adminbenefactoreparam.Data'
type: array
type: object
adminkindboxreqparam.KindBoxReqAcceptRequest:
properties:
@ -402,6 +459,8 @@ definitions:
additionalProperties:
type: string
type: object
info:
$ref: '#/definitions/adminkindboxreqparam.Info'
pagination:
$ref: '#/definitions/param.PaginationResponse'
type: object
@ -448,6 +507,22 @@ definitions:
example: 1
type: integer
type: object
adminprovinceparam.Data:
properties:
id:
type: integer
name:
type: string
type: object
adminrefertimeparam.Data:
properties:
duration:
type: string
id:
type: integer
status:
$ref: '#/definitions/entity.ReferTimeStatus'
type: object
adminrefertimeparam.GetAllReferTimeResponse:
properties:
data:
@ -1512,11 +1587,27 @@ paths:
"200":
description: OK
schema:
$ref: '#/definitions/adminkindboxparam.KindBoxGetResponse'
$ref: '#/definitions/adminkindboxhandler.KindBoxAggregatedResponse'
"400":
description: Bad request
schema:
type: string
"401":
description: invalid or expired jwt
schema:
type: string
"403":
description: user not allowed
schema:
type: string
"404":
description: record not found
schema:
type: string
"500":
description: something went wrong
schema:
type: string
security:
- AuthBearerAdmin: []
summary: Get a specific kind box by admin
@ -1818,7 +1909,7 @@ paths:
"200":
description: OK
schema:
$ref: '#/definitions/adminkindboxreqparam.GetKindBoxReqResponse'
$ref: '#/definitions/adminkindboxreqhandler.KindBoxReqAggregatedResponse'
"400":
description: Bad Request
schema:

View File

@ -11,3 +11,9 @@ type Address struct {
ProvinceID uint
BenefactorID uint
}
type AddressAggregated struct {
Address Address
Province Province
City City
}

View File

@ -1,11 +1,9 @@
package adminaddressparam
import "git.gocasts.ir/ebhomengo/niki/entity"
type AddressGetRequest struct {
AddressID uint
}
type AddressGetResponse struct {
Address entity.Address
Data Data
}

7
param/admin/city/data.go Normal file
View File

@ -0,0 +1,7 @@
package admincityparam
type Data struct {
ID uint `json:"id"`
Name string `json:"name"`
ProvinceId uint `json:"province_id"`
}

View File

@ -0,0 +1,6 @@
package adminprovinceparam
type Data struct {
ID uint `json:"id"`
Name string `json:"name"`
}

View File

@ -0,0 +1,11 @@
package adminrefertimeparam
import (
"git.gocasts.ir/ebhomengo/niki/entity"
)
type Data struct {
ID uint `json:"id"`
Duration string `json:"duration"`
Status entity.ReferTimeStatus `json:"status"`
}

View File

@ -1,11 +1,9 @@
package adminrefertimeparam
import "git.gocasts.ir/ebhomengo/niki/entity"
type GetReferTimeRequest struct {
ReferTimeID uint
}
type GetReferTimeResponse struct {
ReferTime entity.ReferTime
Data Data
}

View File

@ -4,8 +4,6 @@ import (
"context"
"database/sql"
"errors"
"time"
"git.gocasts.ir/ebhomengo/niki/entity"
errmsg "git.gocasts.ir/ebhomengo/niki/pkg/err_msg"
richerror "git.gocasts.ir/ebhomengo/niki/pkg/rich_error"
@ -65,14 +63,24 @@ func (d *DB) GetAddress(ctx context.Context, addressID, benefactorID uint) (enti
return address, nil
}
func scanAddress(scanner mysql.Scanner) (entity.Address, error) {
var createdAt, updatedAt time.Time
var deletedAt sql.NullTime
var address entity.Address
func (d *DB) GetAddressWithProvinceAndCityByID(ctx context.Context, addressID uint) (entity.AddressAggregated, error) {
const op = "mysqladdress.GetAddressWithProvinceAndCityByID"
err := scanner.Scan(&address.ID, &address.PostalCode, &address.Address, &address.Lat, &address.Lon,
&address.Name, &address.CityID, &address.ProvinceID, &address.BenefactorID,
&createdAt, &updatedAt, &deletedAt)
query := `select * from addresses join cities on city_id = cities.id join provinces on cities.province_id = provinces.id where addresses.id = ? and deleted_at is null`
row := d.conn.Conn().QueryRowContext(ctx, query, addressID)
return address, err
aggregateAddress, err := scanAddressAggregated(row)
if err != nil {
sErr := sql.ErrNoRows
//nolint
if errors.As(err, &sErr) {
return entity.AddressAggregated{}, richerror.New(op).WithMessage(errmsg.ErrorMsgNotFound).
WithKind(richerror.KindNotFound)
}
return entity.AddressAggregated{}, richerror.New(op).WithErr(err).
WithMessage(errmsg.ErrorMsgCantScanQueryResult).WithKind(richerror.KindUnexpected)
}
return aggregateAddress, nil
}

View File

@ -2,8 +2,6 @@ package mysqladdress
import (
"context"
"time"
"git.gocasts.ir/ebhomengo/niki/entity"
errmsg "git.gocasts.ir/ebhomengo/niki/pkg/err_msg"
richerror "git.gocasts.ir/ebhomengo/niki/pkg/rich_error"
@ -46,12 +44,3 @@ func (d *DB) GetAllCities(ctx context.Context) ([]entity.City, error) {
return cities, nil
}
func scanCity(scanner mysql.Scanner) (entity.City, error) {
var createdAt, updatedAt time.Time
var city entity.City
err := scanner.Scan(&city.ID, &city.Name, &city.ProvinceID, &createdAt, &updatedAt)
return city, err
}

View File

@ -2,8 +2,6 @@ package mysqladdress
import (
"context"
"time"
"git.gocasts.ir/ebhomengo/niki/entity"
errmsg "git.gocasts.ir/ebhomengo/niki/pkg/err_msg"
richerror "git.gocasts.ir/ebhomengo/niki/pkg/rich_error"
@ -46,12 +44,3 @@ func (d *DB) GetAllProvinces(ctx context.Context) ([]entity.Province, error) {
return provinces, nil
}
func scanProvince(scanner mysql.Scanner) (entity.Province, error) {
var createdAt, updatedAt time.Time
var province entity.Province
err := scanner.Scan(&province.ID, &province.Name, &createdAt, &updatedAt)
return province, err
}

View File

@ -0,0 +1,58 @@
package mysqladdress
import (
"database/sql"
"time"
"git.gocasts.ir/ebhomengo/niki/entity"
"git.gocasts.ir/ebhomengo/niki/repository/mysql"
)
func scanProvince(scanner mysql.Scanner) (entity.Province, error) {
var createdAt, updatedAt time.Time
var province entity.Province
err := scanner.Scan(&province.ID, &province.Name, &createdAt, &updatedAt)
return province, err
}
func scanCity(scanner mysql.Scanner) (entity.City, error) {
var createdAt, updatedAt time.Time
var city entity.City
err := scanner.Scan(&city.ID, &city.Name, &city.ProvinceID, &createdAt, &updatedAt)
return city, err
}
func scanAddress(scanner mysql.Scanner) (entity.Address, error) {
var createdAt, updatedAt time.Time
var deletedAt sql.NullTime
var address entity.Address
err := scanner.Scan(&address.ID, &address.PostalCode, &address.Address, &address.Lat, &address.Lon,
&address.Name, &address.CityID, &address.ProvinceID, &address.BenefactorID,
&createdAt, &updatedAt, &deletedAt)
return address, err
}
func scanAddressAggregated(scanner mysql.Scanner) (entity.AddressAggregated, error) {
var createdAt, updatedAt time.Time
var deletedAt sql.NullTime
var address entity.Address
var province entity.Province
var city entity.City
err := scanner.Scan(&address.ID, &address.PostalCode, &address.Address, &address.Lat, &address.Lon,
&address.Name, &address.CityID, &address.ProvinceID, &address.BenefactorID,
&createdAt, &updatedAt, &deletedAt,
&city.ID, &city.Name, &city.ProvinceID, &createdAt, &updatedAt,
&province.ID, &province.Name, &createdAt, &updatedAt)
return entity.AddressAggregated{
Address: address,
City: city,
Province: province,
}, err
}

View File

@ -9,8 +9,8 @@ import (
richerror "git.gocasts.ir/ebhomengo/niki/pkg/rich_error"
)
func (d *DB) GetBenefactorByIds(ctx context.Context, benefactorIDs []any) (map[uint]entity.Benefactor, error) {
const op = "mysqlbenefactor.GetBenefactorByIds"
func (d *DB) GetByIDs(ctx context.Context, benefactorIDs []any) (map[uint]entity.Benefactor, error) {
const op = "mysqlbenefactor.GetByIDs"
if len(benefactorIDs) <= 0 {
return nil, nil

View File

@ -15,5 +15,15 @@ func (s Service) GetAddressByID(ctx context.Context, req param.AddressGetRequest
return param.AddressGetResponse{}, richerror.New(op).WithErr(err)
}
return param.AddressGetResponse{Address: address}, nil
return param.AddressGetResponse{Data: param.Data{
ID: address.ID,
PostalCode: address.PostalCode,
Address: address.Address,
Name: address.Name,
Lat: address.Lat,
Lon: address.Lon,
CityID: address.CityID,
ProvinceID: address.ProvinceID,
BenefactorID: address.BenefactorID,
}}, nil
}

View File

@ -0,0 +1,44 @@
package adminaddressaggregatorservice
import (
"context"
adminaddresshandler "git.gocasts.ir/ebhomengo/niki/delivery/http_server/admin/address"
param "git.gocasts.ir/ebhomengo/niki/param/admin/address"
admincityparam "git.gocasts.ir/ebhomengo/niki/param/admin/city"
adminprovinceparam "git.gocasts.ir/ebhomengo/niki/param/admin/province"
richerror "git.gocasts.ir/ebhomengo/niki/pkg/rich_error"
)
func (s Service) GetAggregatedByID(ctx context.Context, addressID uint) (adminaddresshandler.Address, error) {
const op = "adminaddressaggregatorservice.GetAggregatedByID"
address, err := s.repo.GetAddressWithProvinceAndCityByID(ctx, addressID)
if err != nil {
return adminaddresshandler.Address{}, richerror.New(op).WithErr(err)
}
return adminaddresshandler.Address{
Address: param.Data{
ID: address.Address.ID,
PostalCode: address.Address.PostalCode,
Address: address.Address.Address,
Name: address.Address.Name,
Lat: address.Address.Lat,
Lon: address.Address.Lon,
CityID: address.Address.CityID,
ProvinceID: address.Address.ProvinceID,
BenefactorID: address.Address.BenefactorID,
},
Info: adminaddresshandler.Info{
Province: adminprovinceparam.Data{
ID: address.Province.ID,
Name: address.Province.Name,
},
City: admincityparam.Data{
ID: address.City.ID,
Name: address.City.Name,
ProvinceId: address.City.ProvinceID,
},
},
}, nil
}

View File

@ -0,0 +1,19 @@
package adminaddressaggregatorservice
import (
"context"
"git.gocasts.ir/ebhomengo/niki/entity"
)
type Repository interface {
GetAddressWithProvinceAndCityByID(ctx context.Context, addressId uint) (entity.AddressAggregated, error)
}
type Service struct {
repo Repository
}
func New(repo Repository) Service {
return Service{repo: repo}
}

View File

@ -8,11 +8,11 @@ import (
richerror "git.gocasts.ir/ebhomengo/niki/pkg/rich_error"
)
func (s Service) GetByIDs(ctx context.Context, benefactorIDs []any) ([]param.Data, error) {
func (s Service) GetByIDs(ctx context.Context, ids []any) ([]param.Data, error) {
const op = "adminbenefactoraggregatorservice.GetByIDs"
var data []param.Data
benefactors, err := s.repo.GetBenefactorByIds(ctx, benefactorIDs)
benefactors, err := s.repo.GetByIDs(ctx, ids)
if err != nil {
return nil, richerror.New(op).WithErr(err)
}
@ -31,3 +31,24 @@ func (s Service) GetByIDs(ctx context.Context, benefactorIDs []any) ([]param.Dat
}
return data, nil
}
func (s Service) GetByID(ctx context.Context, id uint) (param.Data, error) {
const op = "adminbenefactoraggregatorservice.GetByID"
bnf, gErr := s.repo.GetByID(ctx, id)
if gErr != nil {
return param.Data{}, richerror.New(op).WithErr(gErr)
}
return param.Data{
ID: bnf.ID,
FirstName: bnf.FirstName,
LastName: bnf.LastName,
PhoneNumber: bnf.PhoneNumber,
Description: bnf.Description,
Email: bnf.Email,
Gender: bnf.Gender,
BirthDate: response.GetNullDate(bnf.BirthDate),
Status: bnf.Status,
}, nil
}

View File

@ -7,7 +7,8 @@ import (
)
type Repository interface {
GetBenefactorByIds(ctx context.Context, benefactorIDs []any) (map[uint]entity.Benefactor, error)
GetByIDs(ctx context.Context, ids []any) (map[uint]entity.Benefactor, error)
GetByID(ctx context.Context, id uint) (entity.Benefactor, error)
}
type Service struct {

View File

@ -8,11 +8,17 @@ import (
)
func (s Service) GetReferTimeByID(ctx context.Context, req param.GetReferTimeRequest) (param.GetReferTimeResponse, error) {
const op = richerror.Op("refertimeservice.GetReferTimeByID")
const op = "adminrefertimeservice.GetReferTimeByID"
referTime, gErr := s.repo.Get(ctx, req.ReferTimeID)
if gErr != nil {
return param.GetReferTimeResponse{}, richerror.New(op).WithErr(gErr).WithKind(richerror.KindUnexpected)
}
return param.GetReferTimeResponse{ReferTime: referTime}, nil
return param.GetReferTimeResponse{
Data: param.Data{
ID: referTime.ID,
Status: referTime.Status,
Duration: referTime.Duration,
},
}, nil
}

View File

@ -0,0 +1,22 @@
package adminrefertimeaggregatorservice
import (
"context"
param "git.gocasts.ir/ebhomengo/niki/param/admin/refer_time"
richerror "git.gocasts.ir/ebhomengo/niki/pkg/rich_error"
)
func (s Service) GetReferTimeByID(ctx context.Context, id uint) (param.Data, error) {
const op = "adminrefertimeaggregatorservice.GetReferTimeByID"
referTime, gErr := s.repo.Get(ctx, id)
if gErr != nil {
return param.Data{}, richerror.New(op).WithErr(gErr).WithKind(richerror.KindUnexpected)
}
return param.Data{
ID: referTime.ID,
Status: referTime.Status,
Duration: referTime.Duration,
}, nil
}

View File

@ -0,0 +1,20 @@
package adminrefertimeaggregatorservice
import (
"context"
"git.gocasts.ir/ebhomengo/niki/entity"
)
type Service struct {
repo Repository
}
type Repository interface {
Get(ctx context.Context, referTimeID uint) (entity.ReferTime, error)
}
func New(repo Repository) Service {
return Service{
repo: repo,
}
}

View File

@ -14,6 +14,7 @@ import (
mysqlrefertime "git.gocasts.ir/ebhomengo/niki/repository/mysql/refer_time"
redisotp "git.gocasts.ir/ebhomengo/niki/repository/redis/otp"
adminaddressservice "git.gocasts.ir/ebhomengo/niki/service/admin/address"
adminaddressaggservice "git.gocasts.ir/ebhomengo/niki/service/admin/address_aggregator"
adminservice "git.gocasts.ir/ebhomengo/niki/service/admin/admin"
adminagentservice "git.gocasts.ir/ebhomengo/niki/service/admin/agent"
adminauthorizationservice "git.gocasts.ir/ebhomengo/niki/service/admin/authorization"
@ -22,6 +23,7 @@ import (
adminkindboxservice "git.gocasts.ir/ebhomengo/niki/service/admin/kind_box"
adminkindboxreqservice "git.gocasts.ir/ebhomengo/niki/service/admin/kind_box_req"
adminrefertimeservice "git.gocasts.ir/ebhomengo/niki/service/admin/refer_time"
adminrefertimeaggservice "git.gocasts.ir/ebhomengo/niki/service/admin/refer_time_aggregator"
agentkindboxservice "git.gocasts.ir/ebhomengo/niki/service/agent/kind_box"
agentkindboxreqservice "git.gocasts.ir/ebhomengo/niki/service/agent/kind_box_req"
"git.gocasts.ir/ebhomengo/niki/service/auth"
@ -64,6 +66,8 @@ type Service struct {
BenefactorReferTimeSvc benefactorrefertimeservice.Service
AdminReferTimeSvc adminrefertimeservice.Service
AdminBenefactorAggSvc adminbenefactoraggsvc.Service
AdminAddressAggSvc adminaddressaggservice.Service
AdminReferTimeAggSvc adminrefertimeaggservice.Service
}
func New(cfg config.Config, db *mysql.DB, rds *redis.Adapter, smsAdapter smscontract.SmsAdapter) *Service {
@ -86,7 +90,10 @@ func New(cfg config.Config, db *mysql.DB, rds *redis.Adapter, smsAdapter smscont
AdminBenefactorVld = adminbenefactorvalidator.New(benefactorRepo)
AdminBenefactorSvc = adminbenefactorservice.New(benefactorRepo, AdminAddressSvc, AdminBenefactorVld)
AdminAgentSvc = adminagentservice.New(agentRepo)
AdminBenefactorAggSvc = adminbenefactoraggsvc.New(benefactorRepo)
AdminAddressAggSvc = adminaddressaggservice.New(addressRepo)
AdminReferTimeAggSvc = adminrefertimeaggservice.New(referTimeRepo)
AdminVld = adminvalidator.New(adminRepo)
AdminSvc = adminservice.New(adminRepo, AdminAuthSvc, AdminVld)
@ -136,5 +143,7 @@ func New(cfg config.Config, db *mysql.DB, rds *redis.Adapter, smsAdapter smscont
BenefactorReferTimeSvc: BenefactorReferTimeSvc,
AdminReferTimeSvc: AdminReferTimeSvc,
AdminBenefactorAggSvc: AdminBenefactorAggSvc,
AdminAddressAggSvc: AdminAddressAggSvc,
AdminReferTimeAggSvc: AdminReferTimeAggSvc,
}
}

View File

@ -170,7 +170,7 @@ func (v Validator) isReturnReferTimeIDValid(ctx context.Context) validation.Rule
if err != nil {
return richerror.New(op).WithErr(err).WithMessage(errmsg.ErrorMsgReferTimeNotFound).WithKind(richerror.KindNotFound)
}
if resp.ReferTime.Status != entity.ReferTimeActiveStatus {
if resp.Data.Status != entity.ReferTimeActiveStatus {
return richerror.New(op).WithMessage(errmsg.ErrorMsgReferTimeIsNotActive).WithKind(richerror.KindInvalid)
}
return nil
@ -206,7 +206,7 @@ func (v Validator) doesBenefactorAddressExist(ctx context.Context, kindBoxID uin
return richerror.New(op).WithErr(err).WithMessage("failed to retrieve address").WithKind(richerror.KindUnexpected)
}
if addressResponse.Address.BenefactorID != benefactorID {
if addressResponse.Data.BenefactorID != benefactorID {
return richerror.New(op).WithMessage("the specified address does not belong to the benefactor").WithKind(richerror.KindInvalid)
}
return nil

View File

@ -104,7 +104,7 @@ func (v Validator) doesAddressExist(ctx context.Context, benefactorID uint) vali
if err != nil {
return fmt.Errorf(errmsg.ErrorMsgSomethingWentWrong)
}
if address.Address.BenefactorID != benefactorID {
if address.Data.BenefactorID != benefactorID {
return fmt.Errorf(errmsg.ErrorMsgNotFound)
}

View File

@ -238,7 +238,7 @@ func (v Validator) isReferTimeIDValid(ctx context.Context) validation.RuleFunc {
if gErr != nil {
return fmt.Errorf(errmsg.ErrorMsgReferTimeNotFound)
}
if resp.ReferTime.Status != entity.ReferTimeActiveStatus {
if resp.Data.Status != entity.ReferTimeActiveStatus {
return fmt.Errorf(errmsg.ErrorMsgReferTimeIsNotActive)
}
@ -280,7 +280,7 @@ func (v Validator) doesBenefactorAddressExist(ctx context.Context, kindBoxReqID
if gErr != nil {
return fmt.Errorf(errmsg.ErrorMsgSomethingWentWrong)
}
if address.Address.BenefactorID != kindBoxReq.BenefactorID {
if address.Data.BenefactorID != kindBoxReq.BenefactorID {
return fmt.Errorf(errmsg.ErrorMsgNotFound)
}