Merge pull request 'feat(admin): append nested data in kindbox and kindboxreq(#208)' (#209) from stage/hamed/agregate-kindbox into develop

Reviewed-on: ebhomengo/niki#209
This commit is contained in:
hossein 2024-11-19 15:51:32 +00:00
commit a239bb089c
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" adminkindboxreqparam "git.gocasts.ir/ebhomengo/niki/param/admin/kind_box_req"
) )
type Data struct { type Info struct {
Benefactor param.Data `json:"benefactor"`
Addresses []adminaddressparam.Data `json:"addresses"` Addresses []adminaddressparam.Data `json:"addresses"`
KindBoxes []adminkindboxparam.Data `json:"kind_boxes"` KindBoxes []adminkindboxparam.Data `json:"kind_boxes"`
KindBoxReqs []adminkindboxreqparam.Data `json:"kind_box_reqs"` KindBoxReqs []adminkindboxreqparam.Data `json:"kind_box_reqs"`
} }
type BenefactorAggregatedResponse struct { 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{ resp := BenefactorAggregatedResponse{
Data: Data{ Benefactor: bnf.Data,
Benefactor: bnf.Data, Info: Info{
Addresses: addresses.Data, Addresses: addresses.Data,
KindBoxes: kindBoxes.Data, KindBoxes: kindBoxes.Data,
KindBoxReqs: kindBoxReqs.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 // @Accept json
// @Produce json // @Produce json
// @Param id path int true "Kind box ID" // @Param id path int true "Kind box ID"
// @Success 200 {object} param.KindBoxGetResponse // @Success 200 {object} KindBoxAggregatedResponse
// @Failure 400 {string} "Bad request" // @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 // @Security AuthBearerAdmin
// @Router /admins/kindboxes/{id} [get]. // @Router /admins/kindboxes/{id} [get].
func (h Handler) Get(c echo.Context) error { 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) 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 { if sErr != nil {
msg, code := httpmsg.Error(sErr) msg, code := httpmsg.Error(sErr)
if resp.FieldErrors != nil { if kindBox.FieldErrors != nil {
return c.JSON(code, echo.Map{ return c.JSON(code, echo.Map{
"message": msg, "message": msg,
"errors": resp.FieldErrors, "errors": kindBox.FieldErrors,
}) })
} }
return echo.NewHTTPError(code, msg) 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) return c.JSON(http.StatusOK, resp)
} }

View File

@ -1,9 +1,11 @@
package adminkindboxhandler package adminkindboxhandler
import ( import (
adminaddressaggservice "git.gocasts.ir/ebhomengo/niki/service/admin/address_aggregator"
adminauthorizationservice "git.gocasts.ir/ebhomengo/niki/service/admin/authorization" adminauthorizationservice "git.gocasts.ir/ebhomengo/niki/service/admin/authorization"
adminbenefactoraggsvc "git.gocasts.ir/ebhomengo/niki/service/admin/benefactor_aggregator" adminbenefactoraggsvc "git.gocasts.ir/ebhomengo/niki/service/admin/benefactor_aggregator"
adminkindboxservice "git.gocasts.ir/ebhomengo/niki/service/admin/kind_box" 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" authservice "git.gocasts.ir/ebhomengo/niki/service/auth"
"git.gocasts.ir/ebhomengo/niki/service/notification" "git.gocasts.ir/ebhomengo/niki/service/notification"
) )
@ -12,6 +14,8 @@ type Handler struct {
authSvc authservice.Service authSvc authservice.Service
adminKindBoxSvc adminkindboxservice.Service adminKindBoxSvc adminkindboxservice.Service
adminBenefactorAggSvc adminbenefactoraggsvc.Service adminBenefactorAggSvc adminbenefactoraggsvc.Service
addressAggSvc adminaddressaggservice.Service
referTimeAggSvc adminrefertimeaggregatorservice.Service
adminAuthorizeSvc adminauthorizationservice.Service adminAuthorizeSvc adminauthorizationservice.Service
notificationSvc notification.Service notificationSvc notification.Service
} }
@ -19,6 +23,8 @@ type Handler struct {
func New(authSvc authservice.Service, func New(authSvc authservice.Service,
adminKindBoxSvc adminkindboxservice.Service, adminKindBoxSvc adminkindboxservice.Service,
adminBenefactorAggSvc adminbenefactoraggsvc.Service, adminBenefactorAggSvc adminbenefactoraggsvc.Service,
addressAggSvc adminaddressaggservice.Service,
referTimeAggSvc adminrefertimeaggregatorservice.Service,
adminAuthorizeSvc adminauthorizationservice.Service, adminAuthorizeSvc adminauthorizationservice.Service,
notificationSvc notification.Service, notificationSvc notification.Service,
) Handler { ) Handler {
@ -26,6 +32,8 @@ func New(authSvc authservice.Service,
authSvc: authSvc, authSvc: authSvc,
adminKindBoxSvc: adminKindBoxSvc, adminKindBoxSvc: adminKindBoxSvc,
adminBenefactorAggSvc: adminBenefactorAggSvc, adminBenefactorAggSvc: adminBenefactorAggSvc,
addressAggSvc: addressAggSvc,
referTimeAggSvc: referTimeAggSvc,
adminAuthorizeSvc: adminAuthorizeSvc, adminAuthorizeSvc: adminAuthorizeSvc,
notificationSvc: notificationSvc, 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 // @Accept json
// @Produce json // @Produce json
// @Param id path int true "KindBoxReq ID" // @Param id path int true "KindBoxReq ID"
// @Success 200 {object} param.GetKindBoxReqResponse // @Success 200 {object} KindBoxReqAggregatedResponse
// @Failure 400 {string} "Bad Request" // @Failure 400 {string} "Bad Request"
// @Failure 401 {string} "invalid or expired jwt" // @Failure 401 {string} "invalid or expired jwt"
// @Failure 403 {string} "user not allowed" // @Failure 403 {string} "user not allowed"
@ -28,18 +28,62 @@ func (h Handler) Get(c echo.Context) error {
return echo.NewHTTPError(http.StatusBadRequest) 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 { if err != nil {
msg, code := httpmsg.Error(err) msg, code := httpmsg.Error(err)
if resp.FieldErrors != nil { if kindBoxReq.FieldErrors != nil {
return c.JSON(code, echo.Map{ return c.JSON(code, echo.Map{
"message": msg, "message": msg,
"errors": resp.FieldErrors, "errors": kindBoxReq.FieldErrors,
}) })
} }
return echo.NewHTTPError(code, msg) 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) return c.JSON(http.StatusOK, resp)
} }

View File

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

View File

@ -50,8 +50,8 @@ func New(
Router: echo.New(), Router: echo.New(),
config: cfg, config: cfg,
adminHandler: adminhandler.New(svc.AdminAuthSvc, svc.AdminSvc, svc.AdminAuthorizeSvc), adminHandler: adminhandler.New(svc.AdminAuthSvc, svc.AdminSvc, svc.AdminAuthorizeSvc),
adminKindBoxReqHandler: adminkindboxreqhandler.New(svc.AdminAuthSvc, svc.AdminKindBoxReqSvc, 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.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), adminAgentHandler: adminagenthandler.New(svc.AdminAuthSvc, svc.AdminAgentSvc, svc.AdminAuthorizeSvc),
adminBenefactorHandler: adminbenefactorhandler.New(svc.AdminAuthSvc, svc.AdminAuthorizeSvc, svc.AdminBenefactorSvc, svc.AdminAddressSvc, svc.AdminKindBoxSvc, svc.AdminKindBoxReqSvc), adminBenefactorHandler: adminbenefactorhandler.New(svc.AdminAuthSvc, svc.AdminAuthorizeSvc, svc.AdminBenefactorSvc, svc.AdminAddressSvc, svc.AdminKindBoxSvc, svc.AdminKindBoxReqSvc),
adminReferTimeHandler: adminrefertimehandler.New(svc.AdminAuthSvc, svc.AdminReferTimeSvc, svc.AdminAuthorizeSvc), adminReferTimeHandler: adminrefertimehandler.New(svc.AdminAuthSvc, svc.AdminReferTimeSvc, svc.AdminAuthorizeSvc),

View File

@ -452,7 +452,7 @@ const docTemplate = `{
], ],
"type": "string", "type": "string",
"description": "Filter by KindBox type", "description": "Filter by KindBox type",
"name": "filter_kind_box_type", "name": "filter_type",
"in": "query" "in": "query"
}, },
{ {
@ -711,7 +711,7 @@ const docTemplate = `{
"200": { "200": {
"description": "OK", "description": "OK",
"schema": { "schema": {
"$ref": "#/definitions/adminkindboxparam.KindBoxGetResponse" "$ref": "#/definitions/adminkindboxhandler.KindBoxAggregatedResponse"
} }
}, },
"400": { "400": {
@ -719,6 +719,30 @@ const docTemplate = `{
"schema": { "schema": {
"type": "string" "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": { "200": {
"description": "OK", "description": "OK",
"schema": { "schema": {
"$ref": "#/definitions/adminkindboxreqparam.GetKindBoxReqResponse" "$ref": "#/definitions/adminkindboxreqhandler.KindBoxReqAggregatedResponse"
} }
}, },
"400": { "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": { "adminaddressparam.Data": {
"type": "object", "type": "object",
"properties": { "properties": {
@ -3343,12 +3389,15 @@ const docTemplate = `{
"adminbenefactorhandler.BenefactorAggregatedResponse": { "adminbenefactorhandler.BenefactorAggregatedResponse": {
"type": "object", "type": "object",
"properties": { "properties": {
"data": { "benefactor": {
"$ref": "#/definitions/adminbenefactorhandler.Data" "$ref": "#/definitions/adminbenefactoreparam.Data"
},
"info": {
"$ref": "#/definitions/adminbenefactorhandler.Info"
} }
} }
}, },
"adminbenefactorhandler.Data": { "adminbenefactorhandler.Info": {
"type": "object", "type": "object",
"properties": { "properties": {
"addresses": { "addresses": {
@ -3357,9 +3406,6 @@ const docTemplate = `{
"$ref": "#/definitions/adminaddressparam.Data" "$ref": "#/definitions/adminaddressparam.Data"
} }
}, },
"benefactor": {
"$ref": "#/definitions/adminbenefactoreparam.Data"
},
"kind_box_reqs": { "kind_box_reqs": {
"type": "array", "type": "array",
"items": { "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": { "adminkindboxparam.AssignReceiverRequest": {
"type": "object", "type": "object",
"properties": { "properties": {
@ -3446,6 +3537,17 @@ const docTemplate = `{
} }
} }
}, },
"adminkindboxparam.Info": {
"type": "object",
"properties": {
"benefactors": {
"type": "array",
"items": {
"$ref": "#/definitions/adminbenefactoreparam.Data"
}
}
}
},
"adminkindboxparam.KindBoxGetAllResponse": { "adminkindboxparam.KindBoxGetAllResponse": {
"type": "object", "type": "object",
"properties": { "properties": {
@ -3461,25 +3563,14 @@ const docTemplate = `{
"type": "string" "type": "string"
} }
}, },
"info": {
"$ref": "#/definitions/adminkindboxparam.Info"
},
"pagination": { "pagination": {
"$ref": "#/definitions/param.PaginationResponse" "$ref": "#/definitions/param.PaginationResponse"
} }
} }
}, },
"adminkindboxparam.KindBoxGetResponse": {
"type": "object",
"properties": {
"data": {
"$ref": "#/definitions/adminkindboxparam.Data"
},
"field_errors": {
"type": "object",
"additionalProperties": {
"type": "string"
}
}
}
},
"adminkindboxparam.KindBoxUpdateRequest": { "adminkindboxparam.KindBoxUpdateRequest": {
"type": "object", "type": "object",
"properties": { "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": { "adminkindboxreqparam.AssignSenderRequest": {
"type": "object", "type": "object",
"properties": { "properties": {
@ -3569,16 +3685,13 @@ const docTemplate = `{
} }
} }
}, },
"adminkindboxreqparam.GetKindBoxReqResponse": { "adminkindboxreqparam.Info": {
"type": "object", "type": "object",
"properties": { "properties": {
"data": { "benefactors": {
"$ref": "#/definitions/adminkindboxreqparam.Data" "type": "array",
}, "items": {
"field_errors": { "$ref": "#/definitions/adminbenefactoreparam.Data"
"type": "object",
"additionalProperties": {
"type": "string"
} }
} }
} }
@ -3667,6 +3780,9 @@ const docTemplate = `{
"type": "string" "type": "string"
} }
}, },
"info": {
"$ref": "#/definitions/adminkindboxreqparam.Info"
},
"pagination": { "pagination": {
"$ref": "#/definitions/param.PaginationResponse" "$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": { "adminrefertimeparam.GetAllReferTimeResponse": {
"type": "object", "type": "object",
"properties": { "properties": {

View File

@ -700,7 +700,7 @@
"200": { "200": {
"description": "OK", "description": "OK",
"schema": { "schema": {
"$ref": "#/definitions/adminkindboxparam.KindBoxGetResponse" "$ref": "#/definitions/adminkindboxhandler.KindBoxAggregatedResponse"
} }
}, },
"400": { "400": {
@ -708,6 +708,30 @@
"schema": { "schema": {
"type": "string" "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": { "200": {
"description": "OK", "description": "OK",
"schema": { "schema": {
"$ref": "#/definitions/adminkindboxreqparam.GetKindBoxReqResponse" "$ref": "#/definitions/adminkindboxreqhandler.KindBoxReqAggregatedResponse"
} }
}, },
"400": { "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": { "adminaddressparam.Data": {
"type": "object", "type": "object",
"properties": { "properties": {
@ -3332,12 +3378,15 @@
"adminbenefactorhandler.BenefactorAggregatedResponse": { "adminbenefactorhandler.BenefactorAggregatedResponse": {
"type": "object", "type": "object",
"properties": { "properties": {
"data": { "benefactor": {
"$ref": "#/definitions/adminbenefactorhandler.Data" "$ref": "#/definitions/adminbenefactoreparam.Data"
},
"info": {
"$ref": "#/definitions/adminbenefactorhandler.Info"
} }
} }
}, },
"adminbenefactorhandler.Data": { "adminbenefactorhandler.Info": {
"type": "object", "type": "object",
"properties": { "properties": {
"addresses": { "addresses": {
@ -3346,9 +3395,6 @@
"$ref": "#/definitions/adminaddressparam.Data" "$ref": "#/definitions/adminaddressparam.Data"
} }
}, },
"benefactor": {
"$ref": "#/definitions/adminbenefactoreparam.Data"
},
"kind_box_reqs": { "kind_box_reqs": {
"type": "array", "type": "array",
"items": { "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": { "adminkindboxparam.AssignReceiverRequest": {
"type": "object", "type": "object",
"properties": { "properties": {
@ -3435,6 +3526,17 @@
} }
} }
}, },
"adminkindboxparam.Info": {
"type": "object",
"properties": {
"benefactors": {
"type": "array",
"items": {
"$ref": "#/definitions/adminbenefactoreparam.Data"
}
}
}
},
"adminkindboxparam.KindBoxGetAllResponse": { "adminkindboxparam.KindBoxGetAllResponse": {
"type": "object", "type": "object",
"properties": { "properties": {
@ -3450,25 +3552,14 @@
"type": "string" "type": "string"
} }
}, },
"info": {
"$ref": "#/definitions/adminkindboxparam.Info"
},
"pagination": { "pagination": {
"$ref": "#/definitions/param.PaginationResponse" "$ref": "#/definitions/param.PaginationResponse"
} }
} }
}, },
"adminkindboxparam.KindBoxGetResponse": {
"type": "object",
"properties": {
"data": {
"$ref": "#/definitions/adminkindboxparam.Data"
},
"field_errors": {
"type": "object",
"additionalProperties": {
"type": "string"
}
}
}
},
"adminkindboxparam.KindBoxUpdateRequest": { "adminkindboxparam.KindBoxUpdateRequest": {
"type": "object", "type": "object",
"properties": { "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": { "adminkindboxreqparam.AssignSenderRequest": {
"type": "object", "type": "object",
"properties": { "properties": {
@ -3558,16 +3674,13 @@
} }
} }
}, },
"adminkindboxreqparam.GetKindBoxReqResponse": { "adminkindboxreqparam.Info": {
"type": "object", "type": "object",
"properties": { "properties": {
"data": { "benefactors": {
"$ref": "#/definitions/adminkindboxreqparam.Data" "type": "array",
}, "items": {
"field_errors": { "$ref": "#/definitions/adminbenefactoreparam.Data"
"type": "object",
"additionalProperties": {
"type": "string"
} }
} }
} }
@ -3656,6 +3769,9 @@
"type": "string" "type": "string"
} }
}, },
"info": {
"$ref": "#/definitions/adminkindboxreqparam.Info"
},
"pagination": { "pagination": {
"$ref": "#/definitions/param.PaginationResponse" "$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": { "adminrefertimeparam.GetAllReferTimeResponse": {
"type": "object", "type": "object",
"properties": { "properties": {

View File

@ -101,6 +101,20 @@ definitions:
example: "1234567890" example: "1234567890"
type: string type: string
type: object 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: adminaddressparam.Data:
properties: properties:
address: address:
@ -189,17 +203,17 @@ definitions:
type: object type: object
adminbenefactorhandler.BenefactorAggregatedResponse: adminbenefactorhandler.BenefactorAggregatedResponse:
properties: properties:
data: benefactor:
$ref: '#/definitions/adminbenefactorhandler.Data' $ref: '#/definitions/adminbenefactoreparam.Data'
info:
$ref: '#/definitions/adminbenefactorhandler.Info'
type: object type: object
adminbenefactorhandler.Data: adminbenefactorhandler.Info:
properties: properties:
addresses: addresses:
items: items:
$ref: '#/definitions/adminaddressparam.Data' $ref: '#/definitions/adminaddressparam.Data'
type: array type: array
benefactor:
$ref: '#/definitions/adminbenefactoreparam.Data'
kind_box_reqs: kind_box_reqs:
items: items:
$ref: '#/definitions/adminkindboxreqparam.Data' $ref: '#/definitions/adminkindboxreqparam.Data'
@ -209,6 +223,35 @@ definitions:
$ref: '#/definitions/adminkindboxparam.Data' $ref: '#/definitions/adminkindboxparam.Data'
type: array type: array
type: object 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: adminkindboxparam.AssignReceiverRequest:
properties: properties:
receiver_agent_id: receiver_agent_id:
@ -256,6 +299,13 @@ definitions:
amount: amount:
type: integer type: integer
type: object type: object
adminkindboxparam.Info:
properties:
benefactors:
items:
$ref: '#/definitions/adminbenefactoreparam.Data'
type: array
type: object
adminkindboxparam.KindBoxGetAllResponse: adminkindboxparam.KindBoxGetAllResponse:
properties: properties:
data: data:
@ -266,18 +316,11 @@ definitions:
additionalProperties: additionalProperties:
type: string type: string
type: object type: object
info:
$ref: '#/definitions/adminkindboxparam.Info'
pagination: pagination:
$ref: '#/definitions/param.PaginationResponse' $ref: '#/definitions/param.PaginationResponse'
type: object type: object
adminkindboxparam.KindBoxGetResponse:
properties:
data:
$ref: '#/definitions/adminkindboxparam.Data'
field_errors:
additionalProperties:
type: string
type: object
type: object
adminkindboxparam.KindBoxUpdateRequest: adminkindboxparam.KindBoxUpdateRequest:
properties: properties:
amount: amount:
@ -299,6 +342,22 @@ definitions:
example: 3 example: 3
type: integer type: integer
type: object 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: adminkindboxreqparam.AssignSenderRequest:
properties: properties:
sender_agent_id: sender_agent_id:
@ -338,14 +397,12 @@ definitions:
status: status:
$ref: '#/definitions/entity.KindBoxReqStatus' $ref: '#/definitions/entity.KindBoxReqStatus'
type: object type: object
adminkindboxreqparam.GetKindBoxReqResponse: adminkindboxreqparam.Info:
properties: properties:
data: benefactors:
$ref: '#/definitions/adminkindboxreqparam.Data' items:
field_errors: $ref: '#/definitions/adminbenefactoreparam.Data'
additionalProperties: type: array
type: string
type: object
type: object type: object
adminkindboxreqparam.KindBoxReqAcceptRequest: adminkindboxreqparam.KindBoxReqAcceptRequest:
properties: properties:
@ -402,6 +459,8 @@ definitions:
additionalProperties: additionalProperties:
type: string type: string
type: object type: object
info:
$ref: '#/definitions/adminkindboxreqparam.Info'
pagination: pagination:
$ref: '#/definitions/param.PaginationResponse' $ref: '#/definitions/param.PaginationResponse'
type: object type: object
@ -448,6 +507,22 @@ definitions:
example: 1 example: 1
type: integer type: integer
type: object 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: adminrefertimeparam.GetAllReferTimeResponse:
properties: properties:
data: data:
@ -1512,11 +1587,27 @@ paths:
"200": "200":
description: OK description: OK
schema: schema:
$ref: '#/definitions/adminkindboxparam.KindBoxGetResponse' $ref: '#/definitions/adminkindboxhandler.KindBoxAggregatedResponse'
"400": "400":
description: Bad request description: Bad request
schema: schema:
type: string 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: security:
- AuthBearerAdmin: [] - AuthBearerAdmin: []
summary: Get a specific kind box by admin summary: Get a specific kind box by admin
@ -1818,7 +1909,7 @@ paths:
"200": "200":
description: OK description: OK
schema: schema:
$ref: '#/definitions/adminkindboxreqparam.GetKindBoxReqResponse' $ref: '#/definitions/adminkindboxreqhandler.KindBoxReqAggregatedResponse'
"400": "400":
description: Bad Request description: Bad Request
schema: schema:

View File

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

View File

@ -1,11 +1,9 @@
package adminaddressparam package adminaddressparam
import "git.gocasts.ir/ebhomengo/niki/entity"
type AddressGetRequest struct { type AddressGetRequest struct {
AddressID uint AddressID uint
} }
type AddressGetResponse struct { 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 package adminrefertimeparam
import "git.gocasts.ir/ebhomengo/niki/entity"
type GetReferTimeRequest struct { type GetReferTimeRequest struct {
ReferTimeID uint ReferTimeID uint
} }
type GetReferTimeResponse struct { type GetReferTimeResponse struct {
ReferTime entity.ReferTime Data Data
} }

View File

@ -4,8 +4,6 @@ import (
"context" "context"
"database/sql" "database/sql"
"errors" "errors"
"time"
"git.gocasts.ir/ebhomengo/niki/entity" "git.gocasts.ir/ebhomengo/niki/entity"
errmsg "git.gocasts.ir/ebhomengo/niki/pkg/err_msg" errmsg "git.gocasts.ir/ebhomengo/niki/pkg/err_msg"
richerror "git.gocasts.ir/ebhomengo/niki/pkg/rich_error" 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 return address, nil
} }
func scanAddress(scanner mysql.Scanner) (entity.Address, error) { func (d *DB) GetAddressWithProvinceAndCityByID(ctx context.Context, addressID uint) (entity.AddressAggregated, error) {
var createdAt, updatedAt time.Time const op = "mysqladdress.GetAddressWithProvinceAndCityByID"
var deletedAt sql.NullTime
var address entity.Address
err := scanner.Scan(&address.ID, &address.PostalCode, &address.Address, &address.Lat, &address.Lon, 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`
&address.Name, &address.CityID, &address.ProvinceID, &address.BenefactorID, row := d.conn.Conn().QueryRowContext(ctx, query, addressID)
&createdAt, &updatedAt, &deletedAt)
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 ( import (
"context" "context"
"time"
"git.gocasts.ir/ebhomengo/niki/entity" "git.gocasts.ir/ebhomengo/niki/entity"
errmsg "git.gocasts.ir/ebhomengo/niki/pkg/err_msg" errmsg "git.gocasts.ir/ebhomengo/niki/pkg/err_msg"
richerror "git.gocasts.ir/ebhomengo/niki/pkg/rich_error" 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 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 ( import (
"context" "context"
"time"
"git.gocasts.ir/ebhomengo/niki/entity" "git.gocasts.ir/ebhomengo/niki/entity"
errmsg "git.gocasts.ir/ebhomengo/niki/pkg/err_msg" errmsg "git.gocasts.ir/ebhomengo/niki/pkg/err_msg"
richerror "git.gocasts.ir/ebhomengo/niki/pkg/rich_error" 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 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" richerror "git.gocasts.ir/ebhomengo/niki/pkg/rich_error"
) )
func (d *DB) GetBenefactorByIds(ctx context.Context, benefactorIDs []any) (map[uint]entity.Benefactor, error) { func (d *DB) GetByIDs(ctx context.Context, benefactorIDs []any) (map[uint]entity.Benefactor, error) {
const op = "mysqlbenefactor.GetBenefactorByIds" const op = "mysqlbenefactor.GetByIDs"
if len(benefactorIDs) <= 0 { if len(benefactorIDs) <= 0 {
return nil, nil 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{}, 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" 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" const op = "adminbenefactoraggregatorservice.GetByIDs"
var data []param.Data var data []param.Data
benefactors, err := s.repo.GetBenefactorByIds(ctx, benefactorIDs) benefactors, err := s.repo.GetByIDs(ctx, ids)
if err != nil { if err != nil {
return nil, richerror.New(op).WithErr(err) 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 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 { 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 { type Service struct {

View File

@ -8,11 +8,17 @@ import (
) )
func (s Service) GetReferTimeByID(ctx context.Context, req param.GetReferTimeRequest) (param.GetReferTimeResponse, error) { 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) referTime, gErr := s.repo.Get(ctx, req.ReferTimeID)
if gErr != nil { if gErr != nil {
return param.GetReferTimeResponse{}, richerror.New(op).WithErr(gErr).WithKind(richerror.KindUnexpected) 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" mysqlrefertime "git.gocasts.ir/ebhomengo/niki/repository/mysql/refer_time"
redisotp "git.gocasts.ir/ebhomengo/niki/repository/redis/otp" redisotp "git.gocasts.ir/ebhomengo/niki/repository/redis/otp"
adminaddressservice "git.gocasts.ir/ebhomengo/niki/service/admin/address" 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" adminservice "git.gocasts.ir/ebhomengo/niki/service/admin/admin"
adminagentservice "git.gocasts.ir/ebhomengo/niki/service/admin/agent" adminagentservice "git.gocasts.ir/ebhomengo/niki/service/admin/agent"
adminauthorizationservice "git.gocasts.ir/ebhomengo/niki/service/admin/authorization" adminauthorizationservice "git.gocasts.ir/ebhomengo/niki/service/admin/authorization"
@ -22,6 +23,7 @@ import (
adminkindboxservice "git.gocasts.ir/ebhomengo/niki/service/admin/kind_box" adminkindboxservice "git.gocasts.ir/ebhomengo/niki/service/admin/kind_box"
adminkindboxreqservice "git.gocasts.ir/ebhomengo/niki/service/admin/kind_box_req" adminkindboxreqservice "git.gocasts.ir/ebhomengo/niki/service/admin/kind_box_req"
adminrefertimeservice "git.gocasts.ir/ebhomengo/niki/service/admin/refer_time" 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" agentkindboxservice "git.gocasts.ir/ebhomengo/niki/service/agent/kind_box"
agentkindboxreqservice "git.gocasts.ir/ebhomengo/niki/service/agent/kind_box_req" agentkindboxreqservice "git.gocasts.ir/ebhomengo/niki/service/agent/kind_box_req"
"git.gocasts.ir/ebhomengo/niki/service/auth" "git.gocasts.ir/ebhomengo/niki/service/auth"
@ -64,6 +66,8 @@ type Service struct {
BenefactorReferTimeSvc benefactorrefertimeservice.Service BenefactorReferTimeSvc benefactorrefertimeservice.Service
AdminReferTimeSvc adminrefertimeservice.Service AdminReferTimeSvc adminrefertimeservice.Service
AdminBenefactorAggSvc adminbenefactoraggsvc.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 { func New(cfg config.Config, db *mysql.DB, rds *redis.Adapter, smsAdapter smscontract.SmsAdapter) *Service {
@ -78,15 +82,18 @@ func New(cfg config.Config, db *mysql.DB, rds *redis.Adapter, smsAdapter smscont
) )
redisOtp := redisotp.New(rds) redisOtp := redisotp.New(rds)
var ( var (
AdminAuthSvc = auth.New(cfg.AdminAuth) AdminAuthSvc = auth.New(cfg.AdminAuth)
AdminAuthorizeSvc = adminauthorizationservice.New(adminRepo) AdminAuthorizeSvc = adminauthorizationservice.New(adminRepo)
AdminReferTimeVld = adminrefertimevalidator.New() AdminReferTimeVld = adminrefertimevalidator.New()
AdminReferTimeSvc = adminrefertimeservice.New(referTimeRepo, AdminReferTimeVld) AdminReferTimeSvc = adminrefertimeservice.New(referTimeRepo, AdminReferTimeVld)
AdminAddressSvc = adminaddressservice.New(addressRepo) AdminAddressSvc = adminaddressservice.New(addressRepo)
AdminBenefactorVld = adminbenefactorvalidator.New(benefactorRepo) AdminBenefactorVld = adminbenefactorvalidator.New(benefactorRepo)
AdminBenefactorSvc = adminbenefactorservice.New(benefactorRepo, AdminAddressSvc, AdminBenefactorVld) AdminBenefactorSvc = adminbenefactorservice.New(benefactorRepo, AdminAddressSvc, AdminBenefactorVld)
AdminAgentSvc = adminagentservice.New(agentRepo) AdminAgentSvc = adminagentservice.New(agentRepo)
AdminBenefactorAggSvc = adminbenefactoraggsvc.New(benefactorRepo) AdminBenefactorAggSvc = adminbenefactoraggsvc.New(benefactorRepo)
AdminAddressAggSvc = adminaddressaggservice.New(addressRepo)
AdminReferTimeAggSvc = adminrefertimeaggservice.New(referTimeRepo)
AdminVld = adminvalidator.New(adminRepo) AdminVld = adminvalidator.New(adminRepo)
AdminSvc = adminservice.New(adminRepo, AdminAuthSvc, AdminVld) 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, BenefactorReferTimeSvc: BenefactorReferTimeSvc,
AdminReferTimeSvc: AdminReferTimeSvc, AdminReferTimeSvc: AdminReferTimeSvc,
AdminBenefactorAggSvc: AdminBenefactorAggSvc, AdminBenefactorAggSvc: AdminBenefactorAggSvc,
AdminAddressAggSvc: AdminAddressAggSvc,
AdminReferTimeAggSvc: AdminReferTimeAggSvc,
} }
} }

View File

@ -170,7 +170,7 @@ func (v Validator) isReturnReferTimeIDValid(ctx context.Context) validation.Rule
if err != nil { if err != nil {
return richerror.New(op).WithErr(err).WithMessage(errmsg.ErrorMsgReferTimeNotFound).WithKind(richerror.KindNotFound) 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 richerror.New(op).WithMessage(errmsg.ErrorMsgReferTimeIsNotActive).WithKind(richerror.KindInvalid)
} }
return nil 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) 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 richerror.New(op).WithMessage("the specified address does not belong to the benefactor").WithKind(richerror.KindInvalid)
} }
return nil return nil

View File

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

View File

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