From b55ec32b21182d38f75daa2d050872c23de74ed8 Mon Sep 17 00:00:00 2001 From: Iman Mirazimi Date: Sun, 15 Sep 2024 11:06:09 +0330 Subject: [PATCH] fix(niki): agent structure refactor --- .../http_server/admin/kind_box_req/route.go | 3 - ...{get_all.go => get_all_return_awaiting.go} | 0 .../{get.go => get_return_awaiting.go} | 0 .../{admin => agent}/kind_box_req/deliver.go | 12 +- .../kind_box_req/get_all_delivery_awaiting.go | 10 +- .../kind_box_req/get_delivery_awaiting.go | 10 +- .../http_server/agent/kind_box_req/handler.go | 24 + .../http_server/agent/kind_box_req/route.go | 16 + delivery/http_server/server.go | 4 + docs/docs.go | 607 ++++++++++-------- docs/swagger.json | 607 ++++++++++-------- docs/swagger.yaml | 401 ++++++------ ...{get_all.go => get_all_return_awaiting.go} | 0 .../{get.go => get_awaiting_return.go} | 0 param/agent/kind_box_req/data.go | 22 + .../{admin => agent}/kind_box_req/deliver.go | 2 +- .../kind_box_req/get_all_delivery_awaiting.go | 2 +- .../kind_box_req/get_delivery_awaiting.go | 2 +- service/admin/kind_box_req/service.go | 17 +- ...{get_all.go => get_all_return_awaiting.go} | 0 .../{get.go => get_return_awaiting.go} | 0 .../{admin => agent}/kind_box_req/deliver.go | 4 +- .../kind_box_req/get_all_delivery_awaiting.go | 5 +- .../kind_box_req/get_delivery_awaiting.go | 5 +- service/agent/kind_box_req/service.go | 34 + service/service.go | 12 +- validator/admin/kind_box/get_all.go | 5 +- validator/admin/kind_box/validator.go | 42 +- validator/admin/kind_box_req/get_all.go | 5 +- validator/admin/kind_box_req/validator.go | 36 ++ ...{get_all.go => get_all_return_awaiting.go} | 5 +- .../{get.go => get_return_awaiting.go} | 0 validator/agent/kind_box/validator.go | 37 ++ .../{admin => agent}/kind_box_req/deliver.go | 5 +- .../kind_box_req/get_all_delivery_awaiting.go | 5 +- .../kind_box_req/get_delivery_awaiting.go | 5 +- validator/agent/kind_box_req/validator.go | 117 ++++ validator/filter.go | 26 - validator/sort.go | 30 - 39 files changed, 1242 insertions(+), 875 deletions(-) rename delivery/http_server/agent/kind_box/{get_all.go => get_all_return_awaiting.go} (100%) rename delivery/http_server/agent/kind_box/{get.go => get_return_awaiting.go} (100%) rename delivery/http_server/{admin => agent}/kind_box_req/deliver.go (83%) rename delivery/http_server/{admin => agent}/kind_box_req/get_all_delivery_awaiting.go (90%) rename delivery/http_server/{admin => agent}/kind_box_req/get_delivery_awaiting.go (80%) create mode 100644 delivery/http_server/agent/kind_box_req/handler.go create mode 100644 delivery/http_server/agent/kind_box_req/route.go rename param/agent/kind_box/{get_all.go => get_all_return_awaiting.go} (100%) rename param/agent/kind_box/{get.go => get_awaiting_return.go} (100%) create mode 100644 param/agent/kind_box_req/data.go rename param/{admin => agent}/kind_box_req/deliver.go (89%) rename param/{admin => agent}/kind_box_req/get_all_delivery_awaiting.go (93%) rename param/{admin => agent}/kind_box_req/get_delivery_awaiting.go (89%) rename service/agent/kind_box/{get_all.go => get_all_return_awaiting.go} (100%) rename service/agent/kind_box/{get.go => get_return_awaiting.go} (100%) rename service/{admin => agent}/kind_box_req/deliver.go (94%) rename service/{admin => agent}/kind_box_req/get_all_delivery_awaiting.go (94%) rename service/{admin => agent}/kind_box_req/get_delivery_awaiting.go (93%) create mode 100644 service/agent/kind_box_req/service.go rename validator/agent/kind_box/{get_all.go => get_all_return_awaiting.go} (83%) rename validator/agent/kind_box/{get.go => get_return_awaiting.go} (100%) rename validator/{admin => agent}/kind_box_req/deliver.go (92%) rename validator/{admin => agent}/kind_box_req/get_all_delivery_awaiting.go (92%) rename validator/{admin => agent}/kind_box_req/get_delivery_awaiting.go (90%) create mode 100644 validator/agent/kind_box_req/validator.go delete mode 100644 validator/filter.go delete mode 100644 validator/sort.go diff --git a/delivery/http_server/admin/kind_box_req/route.go b/delivery/http_server/admin/kind_box_req/route.go index 9b0592a..df548e6 100644 --- a/delivery/http_server/admin/kind_box_req/route.go +++ b/delivery/http_server/admin/kind_box_req/route.go @@ -13,11 +13,8 @@ func (h Handler) SetRoutes(e *echo.Echo) { r.POST("", h.AddKindBoxReq, middleware.AdminAuthorization(h.adminAuthorizeSvc, entity.AdminKindBoxReqAddPermission)) r.PATCH("/:id/accept-kind-box-req", h.Accept, middleware.AdminAuthorization(h.adminAuthorizeSvc, entity.AdminKindBoxReqAcceptPermission)) r.PATCH("/:id/reject-kind-box-req", h.Reject, middleware.AdminAuthorization(h.adminAuthorizeSvc, entity.AdminKindBoxReqRejectPermission)) - r.PATCH("/:id/deliver-kind-box-req", h.Deliver, middleware.AdminAuthorization(h.adminAuthorizeSvc, entity.AdminKindBoxReqDeliverPermission)) r.PATCH("/:id/assign-sender-agent", h.AssignSenderAgent, middleware.AdminAuthorization(h.adminAuthorizeSvc, entity.AdminKindBoxReqAssignSenderAgentPermission)) r.GET("", h.GetAll, middleware.AdminAuthorization(h.adminAuthorizeSvc, entity.AdminKindBoxReqGetAllPermission)) - r.GET("/awaiting-delivery/:id", h.GetAwaitingDelivery, middleware.AdminAuthorization(h.adminAuthorizeSvc, entity.AdminKindBoxReqGetAwaitingDeliveryPermission)) - r.GET("/awaiting-delivery", h.GetAllAwaitingDelivery, middleware.AdminAuthorization(h.adminAuthorizeSvc, entity.AdminKindBoxReqGetAwaitingDeliveryPermission)) r.PUT("/:id", h.Update, middleware.AdminAuthorization(h.adminAuthorizeSvc, entity.AdminKindBoxReqUpdatePermission)) r.GET("/:id", h.Get, middleware.AdminAuthorization(h.adminAuthorizeSvc, entity.AdminKindBoxReqGetPermission)) } diff --git a/delivery/http_server/agent/kind_box/get_all.go b/delivery/http_server/agent/kind_box/get_all_return_awaiting.go similarity index 100% rename from delivery/http_server/agent/kind_box/get_all.go rename to delivery/http_server/agent/kind_box/get_all_return_awaiting.go diff --git a/delivery/http_server/agent/kind_box/get.go b/delivery/http_server/agent/kind_box/get_return_awaiting.go similarity index 100% rename from delivery/http_server/agent/kind_box/get.go rename to delivery/http_server/agent/kind_box/get_return_awaiting.go diff --git a/delivery/http_server/admin/kind_box_req/deliver.go b/delivery/http_server/agent/kind_box_req/deliver.go similarity index 83% rename from delivery/http_server/admin/kind_box_req/deliver.go rename to delivery/http_server/agent/kind_box_req/deliver.go index edceb91..23fcad2 100644 --- a/delivery/http_server/admin/kind_box_req/deliver.go +++ b/delivery/http_server/agent/kind_box_req/deliver.go @@ -1,10 +1,10 @@ -package adminkindboxreqhandler +package agentkindboxreqhandler import ( "context" + param "git.gocasts.ir/ebhomengo/niki/param/agent/kind_box_req" "net/http" - param "git.gocasts.ir/ebhomengo/niki/param/admin/kind_box_req" errmsg "git.gocasts.ir/ebhomengo/niki/pkg/err_msg" httpmsg "git.gocasts.ir/ebhomengo/niki/pkg/http_msg" querier "git.gocasts.ir/ebhomengo/niki/pkg/query_transaction/sql" @@ -12,8 +12,8 @@ import ( ) // Deliver godoc -// @Summary Admin deliver a kindboxreq -// @Tags Admins KindBoxReqs +// @Summary Agent deliver a kindboxreq +// @Tags Agents KindBoxReqs // @Accept json // @Produce json // @Param id path int true "KindBoxReq ID" @@ -21,7 +21,7 @@ import ( // @Success 200 {object} param.DeliverKindBoxReqResponse // @Failure 400 {string} "Bad request" // @Security AuthBearerAdmin -// @Router /admins/kindboxreqs/{id}/deliver-kind-box-req [patch]. +// @Router /agents/kindboxreqs/{id}/deliver-kind-box-req [patch]. func (h Handler) Deliver(c echo.Context) error { var req param.DeliverKindBoxReqRequest @@ -31,7 +31,7 @@ func (h Handler) Deliver(c echo.Context) error { q := querier.GetQuerierFromContextOrNew(c.Request().Context()).Begin() ctx := context.WithValue(c.Request().Context(), querier.QuerierContextKey, q) - resp, sErr := h.adminKindBoxReqSvc.Deliver(ctx, req) + resp, sErr := h.agentKindBoxReqSvc.Deliver(ctx, req) if sErr != nil { msg, code := httpmsg.Error(sErr) if resp.FieldErrors != nil { diff --git a/delivery/http_server/admin/kind_box_req/get_all_delivery_awaiting.go b/delivery/http_server/agent/kind_box_req/get_all_delivery_awaiting.go similarity index 90% rename from delivery/http_server/admin/kind_box_req/get_all_delivery_awaiting.go rename to delivery/http_server/agent/kind_box_req/get_all_delivery_awaiting.go index b7d4c1d..d1d390d 100644 --- a/delivery/http_server/admin/kind_box_req/get_all_delivery_awaiting.go +++ b/delivery/http_server/agent/kind_box_req/get_all_delivery_awaiting.go @@ -1,10 +1,10 @@ -package adminkindboxreqhandler +package agentkindboxreqhandler import ( + param "git.gocasts.ir/ebhomengo/niki/param/agent/kind_box_req" "net/http" "git.gocasts.ir/ebhomengo/niki/entity" - param "git.gocasts.ir/ebhomengo/niki/param/admin/kind_box_req" "git.gocasts.ir/ebhomengo/niki/pkg/claim" httpmsg "git.gocasts.ir/ebhomengo/niki/pkg/http_msg" queryparam "git.gocasts.ir/ebhomengo/niki/pkg/query_param" @@ -14,7 +14,7 @@ import ( // GetAllAwaitingDelivery godoc // @Summary Get all awaiting delivery KindBox requests // @Description Retrieves a list of all awaiting KindBox requests with filtering, sorting, and pagination options -// @Tags Admins KindBoxReqs +// @Tags Agents KindBoxReqs // @Accept json // @Produce json // @Param filter_id query int false "Filter by ID" @@ -32,7 +32,7 @@ import ( // @Success 200 {object} param.DeliveryAwaitingGetAllResponse // @Failure 400 {string} "Bad request" // @Security AuthBearerAdmin -// @Router /admins/kindboxreqs/awaiting-delivery [get]. +// @Router /agents/kindboxreqs/awaiting-delivery [get]. func (h Handler) GetAllAwaitingDelivery(c echo.Context) error { var req param.DeliveryAwaitingGetAllRequest @@ -42,7 +42,7 @@ func (h Handler) GetAllAwaitingDelivery(c echo.Context) error { req.Filter = queryparam.GetFilterParams(c) req.Filter["sender_agent_id"] = claim.GetClaimsFromEchoContext(c).UserID req.Filter["status"] = entity.KindBoxReqAssignedSenderAgentStatus - resp, sErr := h.adminKindBoxReqSvc.GetAllAwaitingDelivery(c.Request().Context(), req) + resp, sErr := h.agentKindBoxReqSvc.GetAllAwaitingDelivery(c.Request().Context(), req) if sErr != nil { msg, code := httpmsg.Error(sErr) if resp.FieldErrors != nil { diff --git a/delivery/http_server/admin/kind_box_req/get_delivery_awaiting.go b/delivery/http_server/agent/kind_box_req/get_delivery_awaiting.go similarity index 80% rename from delivery/http_server/admin/kind_box_req/get_delivery_awaiting.go rename to delivery/http_server/agent/kind_box_req/get_delivery_awaiting.go index 337db68..1b8bf0b 100644 --- a/delivery/http_server/admin/kind_box_req/get_delivery_awaiting.go +++ b/delivery/http_server/agent/kind_box_req/get_delivery_awaiting.go @@ -1,9 +1,9 @@ -package adminkindboxreqhandler +package agentkindboxreqhandler import ( + param "git.gocasts.ir/ebhomengo/niki/param/agent/kind_box_req" "net/http" - param "git.gocasts.ir/ebhomengo/niki/param/admin/kind_box_req" "git.gocasts.ir/ebhomengo/niki/pkg/claim" httpmsg "git.gocasts.ir/ebhomengo/niki/pkg/http_msg" "github.com/labstack/echo/v4" @@ -11,14 +11,14 @@ import ( // GetAwaitingDelivery godoc // @Summary Get a kind box reqs that is awaiting delivery by agent -// @Tags Admins KindBoxReqs +// @Tags Agents KindBoxReqs // @Accept json // @Produce json // @Param id path int true "KindBoxReq ID" // @Success 200 {object} param.DeliveryAwaitingGetResponse // @Failure 400 {string} "Bad request" // @Security AuthBearerAdmin -// @Router /admins/kindboxreqs/awaiting-delivery/{id} [get]. +// @Router /agents/kindboxreqs/awaiting-delivery/{id} [get]. func (h Handler) GetAwaitingDelivery(c echo.Context) error { var req param.DeliveryAwaitingGetRequest if bErr := c.Bind(&req); bErr != nil { @@ -28,7 +28,7 @@ func (h Handler) GetAwaitingDelivery(c echo.Context) error { claims := claim.GetClaimsFromEchoContext(c) req.AgentID = claims.UserID - resp, sErr := h.adminKindBoxReqSvc.GetAwaitingDelivery(c.Request().Context(), req) + resp, sErr := h.agentKindBoxReqSvc.GetAwaitingDelivery(c.Request().Context(), req) if sErr != nil { msg, code := httpmsg.Error(sErr) if resp.FieldErrors != nil { diff --git a/delivery/http_server/agent/kind_box_req/handler.go b/delivery/http_server/agent/kind_box_req/handler.go new file mode 100644 index 0000000..357cfa0 --- /dev/null +++ b/delivery/http_server/agent/kind_box_req/handler.go @@ -0,0 +1,24 @@ +package agentkindboxreqhandler + +import ( + adminauthorizationservice "git.gocasts.ir/ebhomengo/niki/service/admin/authorization" + agentkindboxreqservice "git.gocasts.ir/ebhomengo/niki/service/agent/kind_box_req" + authservice "git.gocasts.ir/ebhomengo/niki/service/auth" +) + +type Handler struct { + authSvc authservice.Service + agentKindBoxReqSvc agentkindboxreqservice.Service + adminAuthorizeSvc adminauthorizationservice.Service +} + +func New(authSvc authservice.Service, + agentKindBoxReqSvc agentkindboxreqservice.Service, + adminAuthorizeSvc adminauthorizationservice.Service, +) Handler { + return Handler{ + authSvc: authSvc, + agentKindBoxReqSvc: agentKindBoxReqSvc, + adminAuthorizeSvc: adminAuthorizeSvc, + } +} diff --git a/delivery/http_server/agent/kind_box_req/route.go b/delivery/http_server/agent/kind_box_req/route.go new file mode 100644 index 0000000..076e28b --- /dev/null +++ b/delivery/http_server/agent/kind_box_req/route.go @@ -0,0 +1,16 @@ +package agentkindboxreqhandler + +import ( + "git.gocasts.ir/ebhomengo/niki/delivery/http_server/middleware" + "git.gocasts.ir/ebhomengo/niki/entity" + "github.com/labstack/echo/v4" +) + +func (h Handler) SetRoutes(e *echo.Echo) { + r := e.Group("/agents/kindboxreqs") + + r.Use(middleware.Auth(h.authSvc)) + r.GET("/awaiting-delivery/:id", h.GetAwaitingDelivery, middleware.AdminAuthorization(h.adminAuthorizeSvc, entity.AdminKindBoxReqGetAwaitingDeliveryPermission)) + r.GET("/awaiting-delivery", h.GetAllAwaitingDelivery, middleware.AdminAuthorization(h.adminAuthorizeSvc, entity.AdminKindBoxReqGetAwaitingDeliveryPermission)) + r.PATCH("/:id/deliver-kind-box-req", h.Deliver, middleware.AdminAuthorization(h.adminAuthorizeSvc, entity.AdminKindBoxReqDeliverPermission)) +} diff --git a/delivery/http_server/server.go b/delivery/http_server/server.go index 780dca8..8eb4a15 100644 --- a/delivery/http_server/server.go +++ b/delivery/http_server/server.go @@ -2,6 +2,7 @@ package httpserver import ( "fmt" + agentkindboxreqhandler "git.gocasts.ir/ebhomengo/niki/delivery/http_server/agent/kind_box_req" "git.gocasts.ir/ebhomengo/niki/config" adminhandler "git.gocasts.ir/ebhomengo/niki/delivery/http_server/admin/admin" @@ -28,6 +29,7 @@ type Server struct { adminKindBoxHandler adminKindBoxHandler.Handler adminAgentHandler adminagenthandler.Handler agentKindBoxHandler agentkindboxhandler.Handler + agentKindBoxReqHandler agentkindboxreqhandler.Handler benefactorHandler benefactorhandler.Handler benefactorKindBoxReqHandler benefactorkindboxreqhandler.Handler benefactorAddressHandler benefactoraddresshandler.Handler @@ -46,6 +48,7 @@ func New( adminKindBoxHandler: adminKindBoxHandler.New(svc.AdminAuthSvc, svc.AdminKindBoxSvc, svc.AdminAuthorizeSvc, svc.NotificationSvc), adminAgentHandler: adminagenthandler.New(svc.AdminAuthSvc, svc.AdminAgentSvc, svc.AdminAuthorizeSvc), agentKindBoxHandler: agentkindboxhandler.New(svc.AdminAuthSvc, svc.AgentKindBoxSvc, svc.AdminAuthorizeSvc), + agentKindBoxReqHandler: agentkindboxreqhandler.New(svc.AdminAuthSvc, svc.AgentKindBoxReqSvc, svc.AdminAuthorizeSvc), benefactorHandler: benefactorhandler.New(svc.BenefactorAuthSvc, svc.BenefactorSvc), benefactorKindBoxReqHandler: benefactorkindboxreqhandler.New(svc.BenefactorAuthSvc, svc.BenefactorKindBoxReqSvc, svc.NotificationSvc), benefactorAddressHandler: benefactoraddresshandler.New(svc.BenefactorAuthSvc, svc.BenefactorAddressSvc), @@ -83,6 +86,7 @@ func (s Server) RegisterRoutes() { s.adminKindBoxReqHandler.SetRoutes(s.Router) s.adminKindBoxHandler.SetRoutes(s.Router) s.agentKindBoxHandler.SetRoutes(s.Router) + s.agentKindBoxReqHandler.SetRoutes(s.Router) } func registerSwagger(s *echo.Echo) { diff --git a/docs/docs.go b/docs/docs.go index 4ca78a4..e5ca8dc 100644 --- a/docs/docs.go +++ b/docs/docs.go @@ -709,177 +709,6 @@ const docTemplate = `{ } } }, - "/admins/kindboxreqs/awaiting-delivery": { - "get": { - "security": [ - { - "AuthBearerAdmin": [] - } - ], - "description": "Retrieves a list of all awaiting KindBox requests with filtering, sorting, and pagination options", - "consumes": [ - "application/json" - ], - "produces": [ - "application/json" - ], - "tags": [ - "Admins KindBoxReqs" - ], - "summary": "Get all awaiting delivery KindBox requests", - "parameters": [ - { - "type": "integer", - "description": "Filter by ID", - "name": "filter_id", - "in": "query" - }, - { - "type": "integer", - "description": "Filter by benefactor ID", - "name": "filter_benefactor_id", - "in": "query" - }, - { - "enum": [ - "on-table", - "cylindrical", - "stand-up" - ], - "type": "string", - "format": "enum", - "description": "Filter by KindBox type", - "name": "filter_kind_box_type", - "in": "query" - }, - { - "type": "integer", - "description": "Filter by count requested", - "name": "filter_count_requested", - "in": "query" - }, - { - "type": "integer", - "description": "Filter by count accepted", - "name": "filter_count_accepted", - "in": "query" - }, - { - "type": "integer", - "description": "Filter by deliver refer time ID", - "name": "filter_deliver_refer_time_id", - "in": "query" - }, - { - "type": "string", - "format": "date", - "description": "Filter by deliver refer date", - "name": "filter_deliver_refer_date", - "in": "query" - }, - { - "type": "integer", - "description": "Filter by deliver address ID", - "name": "filter_deliver_address_id", - "in": "query" - }, - { - "type": "integer", - "description": "Page number", - "name": "page_number", - "in": "query" - }, - { - "type": "integer", - "description": "Page size", - "name": "page_size", - "in": "query" - }, - { - "enum": [ - "id", - "benefactor_id", - "kind_box_type", - "count_requested", - "count_accepted", - "deliver_refer_time_id", - "deliver_refer_date", - "deliver_address_id" - ], - "type": "string", - "description": "Sort by field", - "name": "sort_field", - "in": "query" - }, - { - "enum": [ - "asc", - "desc" - ], - "type": "string", - "description": "Sort order", - "name": "sort_direction", - "in": "query" - } - ], - "responses": { - "200": { - "description": "OK", - "schema": { - "$ref": "#/definitions/adminkindboxreqparam.DeliveryAwaitingGetAllResponse" - } - }, - "400": { - "description": "Bad request", - "schema": { - "type": "string" - } - } - } - } - }, - "/admins/kindboxreqs/awaiting-delivery/{id}": { - "get": { - "security": [ - { - "AuthBearerAdmin": [] - } - ], - "consumes": [ - "application/json" - ], - "produces": [ - "application/json" - ], - "tags": [ - "Admins KindBoxReqs" - ], - "summary": "Get a kind box reqs that is awaiting delivery by agent", - "parameters": [ - { - "type": "integer", - "description": "KindBoxReq ID", - "name": "id", - "in": "path", - "required": true - } - ], - "responses": { - "200": { - "description": "OK", - "schema": { - "$ref": "#/definitions/adminkindboxreqparam.DeliveryAwaitingGetResponse" - } - }, - "400": { - "description": "Bad request", - "schema": { - "type": "string" - } - } - } - } - }, "/admins/kindboxreqs/{id}": { "get": { "security": [ @@ -1094,57 +923,6 @@ const docTemplate = `{ } } }, - "/admins/kindboxreqs/{id}/deliver-kind-box-req": { - "patch": { - "security": [ - { - "AuthBearerAdmin": [] - } - ], - "consumes": [ - "application/json" - ], - "produces": [ - "application/json" - ], - "tags": [ - "Admins KindBoxReqs" - ], - "summary": "Admin deliver a kindboxreq", - "parameters": [ - { - "type": "integer", - "description": "KindBoxReq ID", - "name": "id", - "in": "path", - "required": true - }, - { - "description": "KindBoxReq deliver request details", - "name": "Request", - "in": "body", - "required": true, - "schema": { - "$ref": "#/definitions/adminkindboxreqparam.DeliverKindBoxReqRequest" - } - } - ], - "responses": { - "200": { - "description": "OK", - "schema": { - "$ref": "#/definitions/adminkindboxreqparam.DeliverKindBoxReqResponse" - } - }, - "400": { - "description": "Bad request", - "schema": { - "type": "string" - } - } - } - } - }, "/admins/kindboxreqs/{id}/reject-kind-box-req": { "patch": { "security": [ @@ -1563,6 +1341,228 @@ const docTemplate = `{ } } }, + "/agents/kindboxreqs/awaiting-delivery": { + "get": { + "security": [ + { + "AuthBearerAdmin": [] + } + ], + "description": "Retrieves a list of all awaiting KindBox requests with filtering, sorting, and pagination options", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "Agents KindBoxReqs" + ], + "summary": "Get all awaiting delivery KindBox requests", + "parameters": [ + { + "type": "integer", + "description": "Filter by ID", + "name": "filter_id", + "in": "query" + }, + { + "type": "integer", + "description": "Filter by benefactor ID", + "name": "filter_benefactor_id", + "in": "query" + }, + { + "enum": [ + "on-table", + "cylindrical", + "stand-up" + ], + "type": "string", + "format": "enum", + "description": "Filter by KindBox type", + "name": "filter_kind_box_type", + "in": "query" + }, + { + "type": "integer", + "description": "Filter by count requested", + "name": "filter_count_requested", + "in": "query" + }, + { + "type": "integer", + "description": "Filter by count accepted", + "name": "filter_count_accepted", + "in": "query" + }, + { + "type": "integer", + "description": "Filter by deliver refer time ID", + "name": "filter_deliver_refer_time_id", + "in": "query" + }, + { + "type": "string", + "format": "date", + "description": "Filter by deliver refer date", + "name": "filter_deliver_refer_date", + "in": "query" + }, + { + "type": "integer", + "description": "Filter by deliver address ID", + "name": "filter_deliver_address_id", + "in": "query" + }, + { + "type": "integer", + "description": "Page number", + "name": "page_number", + "in": "query" + }, + { + "type": "integer", + "description": "Page size", + "name": "page_size", + "in": "query" + }, + { + "enum": [ + "id", + "benefactor_id", + "kind_box_type", + "count_requested", + "count_accepted", + "deliver_refer_time_id", + "deliver_refer_date", + "deliver_address_id" + ], + "type": "string", + "description": "Sort by field", + "name": "sort_field", + "in": "query" + }, + { + "enum": [ + "asc", + "desc" + ], + "type": "string", + "description": "Sort order", + "name": "sort_direction", + "in": "query" + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/agentkindboxreqparam.DeliveryAwaitingGetAllResponse" + } + }, + "400": { + "description": "Bad request", + "schema": { + "type": "string" + } + } + } + } + }, + "/agents/kindboxreqs/awaiting-delivery/{id}": { + "get": { + "security": [ + { + "AuthBearerAdmin": [] + } + ], + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "Agents KindBoxReqs" + ], + "summary": "Get a kind box reqs that is awaiting delivery by agent", + "parameters": [ + { + "type": "integer", + "description": "KindBoxReq ID", + "name": "id", + "in": "path", + "required": true + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/agentkindboxreqparam.DeliveryAwaitingGetResponse" + } + }, + "400": { + "description": "Bad request", + "schema": { + "type": "string" + } + } + } + } + }, + "/agents/kindboxreqs/{id}/deliver-kind-box-req": { + "patch": { + "security": [ + { + "AuthBearerAdmin": [] + } + ], + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "Agents KindBoxReqs" + ], + "summary": "Agent deliver a kindboxreq", + "parameters": [ + { + "type": "integer", + "description": "KindBoxReq ID", + "name": "id", + "in": "path", + "required": true + }, + { + "description": "KindBoxReq deliver request details", + "name": "Request", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/agentkindboxreqparam.DeliverKindBoxReqRequest" + } + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/agentkindboxreqparam.DeliverKindBoxReqResponse" + } + }, + "400": { + "description": "Bad request", + "schema": { + "type": "string" + } + } + } + } + }, "/benefactors/addresses": { "get": { "security": [ @@ -2907,67 +2907,6 @@ const docTemplate = `{ } } }, - "adminkindboxreqparam.DeliverKindBoxReqRequest": { - "type": "object", - "properties": { - "serial_numbers": { - "type": "array", - "items": { - "type": "string" - }, - "example": [ - "1", - "2", - "3" - ] - } - } - }, - "adminkindboxreqparam.DeliverKindBoxReqResponse": { - "type": "object", - "properties": { - "field_errors": { - "type": "object", - "additionalProperties": { - "type": "string" - } - } - } - }, - "adminkindboxreqparam.DeliveryAwaitingGetAllResponse": { - "type": "object", - "properties": { - "data": { - "type": "array", - "items": { - "$ref": "#/definitions/adminkindboxreqparam.Data" - } - }, - "field_errors": { - "type": "object", - "additionalProperties": { - "type": "string" - } - }, - "pagination": { - "$ref": "#/definitions/param.PaginationResponse" - } - } - }, - "adminkindboxreqparam.DeliveryAwaitingGetResponse": { - "type": "object", - "properties": { - "data": { - "$ref": "#/definitions/adminkindboxreqparam.Data" - }, - "field_errors": { - "type": "object", - "additionalProperties": { - "type": "string" - } - } - } - }, "adminkindboxreqparam.GetKindBoxReqResponse": { "type": "object", "properties": { @@ -3390,6 +3329,108 @@ const docTemplate = `{ } } }, + "agentkindboxreqparam.Data": { + "type": "object", + "properties": { + "benefactor_id": { + "type": "integer" + }, + "count_accepted": { + "type": "integer" + }, + "count_requested": { + "type": "integer" + }, + "deliver_address_id": { + "type": "integer" + }, + "deliver_refer_date": { + "type": "string" + }, + "deliver_refer_time_id": { + "type": "integer" + }, + "delivered_at": { + "type": "string" + }, + "description": { + "type": "string" + }, + "id": { + "type": "integer" + }, + "kind_box_type": { + "$ref": "#/definitions/entity.KindBoxType" + }, + "sender_agent_id": { + "type": "integer" + }, + "status": { + "$ref": "#/definitions/entity.KindBoxReqStatus" + } + } + }, + "agentkindboxreqparam.DeliverKindBoxReqRequest": { + "type": "object", + "properties": { + "serial_numbers": { + "type": "array", + "items": { + "type": "string" + }, + "example": [ + "1", + "2", + "3" + ] + } + } + }, + "agentkindboxreqparam.DeliverKindBoxReqResponse": { + "type": "object", + "properties": { + "field_errors": { + "type": "object", + "additionalProperties": { + "type": "string" + } + } + } + }, + "agentkindboxreqparam.DeliveryAwaitingGetAllResponse": { + "type": "object", + "properties": { + "data": { + "type": "array", + "items": { + "$ref": "#/definitions/agentkindboxreqparam.Data" + } + }, + "field_errors": { + "type": "object", + "additionalProperties": { + "type": "string" + } + }, + "pagination": { + "$ref": "#/definitions/param.PaginationResponse" + } + } + }, + "agentkindboxreqparam.DeliveryAwaitingGetResponse": { + "type": "object", + "properties": { + "data": { + "$ref": "#/definitions/agentkindboxreqparam.Data" + }, + "field_errors": { + "type": "object", + "additionalProperties": { + "type": "string" + } + } + } + }, "benefactoreparam.Data": { "type": "object", "properties": { diff --git a/docs/swagger.json b/docs/swagger.json index b1559fd..ed06d8c 100644 --- a/docs/swagger.json +++ b/docs/swagger.json @@ -698,177 +698,6 @@ } } }, - "/admins/kindboxreqs/awaiting-delivery": { - "get": { - "security": [ - { - "AuthBearerAdmin": [] - } - ], - "description": "Retrieves a list of all awaiting KindBox requests with filtering, sorting, and pagination options", - "consumes": [ - "application/json" - ], - "produces": [ - "application/json" - ], - "tags": [ - "Admins KindBoxReqs" - ], - "summary": "Get all awaiting delivery KindBox requests", - "parameters": [ - { - "type": "integer", - "description": "Filter by ID", - "name": "filter_id", - "in": "query" - }, - { - "type": "integer", - "description": "Filter by benefactor ID", - "name": "filter_benefactor_id", - "in": "query" - }, - { - "enum": [ - "on-table", - "cylindrical", - "stand-up" - ], - "type": "string", - "format": "enum", - "description": "Filter by KindBox type", - "name": "filter_kind_box_type", - "in": "query" - }, - { - "type": "integer", - "description": "Filter by count requested", - "name": "filter_count_requested", - "in": "query" - }, - { - "type": "integer", - "description": "Filter by count accepted", - "name": "filter_count_accepted", - "in": "query" - }, - { - "type": "integer", - "description": "Filter by deliver refer time ID", - "name": "filter_deliver_refer_time_id", - "in": "query" - }, - { - "type": "string", - "format": "date", - "description": "Filter by deliver refer date", - "name": "filter_deliver_refer_date", - "in": "query" - }, - { - "type": "integer", - "description": "Filter by deliver address ID", - "name": "filter_deliver_address_id", - "in": "query" - }, - { - "type": "integer", - "description": "Page number", - "name": "page_number", - "in": "query" - }, - { - "type": "integer", - "description": "Page size", - "name": "page_size", - "in": "query" - }, - { - "enum": [ - "id", - "benefactor_id", - "kind_box_type", - "count_requested", - "count_accepted", - "deliver_refer_time_id", - "deliver_refer_date", - "deliver_address_id" - ], - "type": "string", - "description": "Sort by field", - "name": "sort_field", - "in": "query" - }, - { - "enum": [ - "asc", - "desc" - ], - "type": "string", - "description": "Sort order", - "name": "sort_direction", - "in": "query" - } - ], - "responses": { - "200": { - "description": "OK", - "schema": { - "$ref": "#/definitions/adminkindboxreqparam.DeliveryAwaitingGetAllResponse" - } - }, - "400": { - "description": "Bad request", - "schema": { - "type": "string" - } - } - } - } - }, - "/admins/kindboxreqs/awaiting-delivery/{id}": { - "get": { - "security": [ - { - "AuthBearerAdmin": [] - } - ], - "consumes": [ - "application/json" - ], - "produces": [ - "application/json" - ], - "tags": [ - "Admins KindBoxReqs" - ], - "summary": "Get a kind box reqs that is awaiting delivery by agent", - "parameters": [ - { - "type": "integer", - "description": "KindBoxReq ID", - "name": "id", - "in": "path", - "required": true - } - ], - "responses": { - "200": { - "description": "OK", - "schema": { - "$ref": "#/definitions/adminkindboxreqparam.DeliveryAwaitingGetResponse" - } - }, - "400": { - "description": "Bad request", - "schema": { - "type": "string" - } - } - } - } - }, "/admins/kindboxreqs/{id}": { "get": { "security": [ @@ -1083,57 +912,6 @@ } } }, - "/admins/kindboxreqs/{id}/deliver-kind-box-req": { - "patch": { - "security": [ - { - "AuthBearerAdmin": [] - } - ], - "consumes": [ - "application/json" - ], - "produces": [ - "application/json" - ], - "tags": [ - "Admins KindBoxReqs" - ], - "summary": "Admin deliver a kindboxreq", - "parameters": [ - { - "type": "integer", - "description": "KindBoxReq ID", - "name": "id", - "in": "path", - "required": true - }, - { - "description": "KindBoxReq deliver request details", - "name": "Request", - "in": "body", - "required": true, - "schema": { - "$ref": "#/definitions/adminkindboxreqparam.DeliverKindBoxReqRequest" - } - } - ], - "responses": { - "200": { - "description": "OK", - "schema": { - "$ref": "#/definitions/adminkindboxreqparam.DeliverKindBoxReqResponse" - } - }, - "400": { - "description": "Bad request", - "schema": { - "type": "string" - } - } - } - } - }, "/admins/kindboxreqs/{id}/reject-kind-box-req": { "patch": { "security": [ @@ -1552,6 +1330,228 @@ } } }, + "/agents/kindboxreqs/awaiting-delivery": { + "get": { + "security": [ + { + "AuthBearerAdmin": [] + } + ], + "description": "Retrieves a list of all awaiting KindBox requests with filtering, sorting, and pagination options", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "Agents KindBoxReqs" + ], + "summary": "Get all awaiting delivery KindBox requests", + "parameters": [ + { + "type": "integer", + "description": "Filter by ID", + "name": "filter_id", + "in": "query" + }, + { + "type": "integer", + "description": "Filter by benefactor ID", + "name": "filter_benefactor_id", + "in": "query" + }, + { + "enum": [ + "on-table", + "cylindrical", + "stand-up" + ], + "type": "string", + "format": "enum", + "description": "Filter by KindBox type", + "name": "filter_kind_box_type", + "in": "query" + }, + { + "type": "integer", + "description": "Filter by count requested", + "name": "filter_count_requested", + "in": "query" + }, + { + "type": "integer", + "description": "Filter by count accepted", + "name": "filter_count_accepted", + "in": "query" + }, + { + "type": "integer", + "description": "Filter by deliver refer time ID", + "name": "filter_deliver_refer_time_id", + "in": "query" + }, + { + "type": "string", + "format": "date", + "description": "Filter by deliver refer date", + "name": "filter_deliver_refer_date", + "in": "query" + }, + { + "type": "integer", + "description": "Filter by deliver address ID", + "name": "filter_deliver_address_id", + "in": "query" + }, + { + "type": "integer", + "description": "Page number", + "name": "page_number", + "in": "query" + }, + { + "type": "integer", + "description": "Page size", + "name": "page_size", + "in": "query" + }, + { + "enum": [ + "id", + "benefactor_id", + "kind_box_type", + "count_requested", + "count_accepted", + "deliver_refer_time_id", + "deliver_refer_date", + "deliver_address_id" + ], + "type": "string", + "description": "Sort by field", + "name": "sort_field", + "in": "query" + }, + { + "enum": [ + "asc", + "desc" + ], + "type": "string", + "description": "Sort order", + "name": "sort_direction", + "in": "query" + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/agentkindboxreqparam.DeliveryAwaitingGetAllResponse" + } + }, + "400": { + "description": "Bad request", + "schema": { + "type": "string" + } + } + } + } + }, + "/agents/kindboxreqs/awaiting-delivery/{id}": { + "get": { + "security": [ + { + "AuthBearerAdmin": [] + } + ], + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "Agents KindBoxReqs" + ], + "summary": "Get a kind box reqs that is awaiting delivery by agent", + "parameters": [ + { + "type": "integer", + "description": "KindBoxReq ID", + "name": "id", + "in": "path", + "required": true + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/agentkindboxreqparam.DeliveryAwaitingGetResponse" + } + }, + "400": { + "description": "Bad request", + "schema": { + "type": "string" + } + } + } + } + }, + "/agents/kindboxreqs/{id}/deliver-kind-box-req": { + "patch": { + "security": [ + { + "AuthBearerAdmin": [] + } + ], + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "Agents KindBoxReqs" + ], + "summary": "Agent deliver a kindboxreq", + "parameters": [ + { + "type": "integer", + "description": "KindBoxReq ID", + "name": "id", + "in": "path", + "required": true + }, + { + "description": "KindBoxReq deliver request details", + "name": "Request", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/agentkindboxreqparam.DeliverKindBoxReqRequest" + } + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/agentkindboxreqparam.DeliverKindBoxReqResponse" + } + }, + "400": { + "description": "Bad request", + "schema": { + "type": "string" + } + } + } + } + }, "/benefactors/addresses": { "get": { "security": [ @@ -2896,67 +2896,6 @@ } } }, - "adminkindboxreqparam.DeliverKindBoxReqRequest": { - "type": "object", - "properties": { - "serial_numbers": { - "type": "array", - "items": { - "type": "string" - }, - "example": [ - "1", - "2", - "3" - ] - } - } - }, - "adminkindboxreqparam.DeliverKindBoxReqResponse": { - "type": "object", - "properties": { - "field_errors": { - "type": "object", - "additionalProperties": { - "type": "string" - } - } - } - }, - "adminkindboxreqparam.DeliveryAwaitingGetAllResponse": { - "type": "object", - "properties": { - "data": { - "type": "array", - "items": { - "$ref": "#/definitions/adminkindboxreqparam.Data" - } - }, - "field_errors": { - "type": "object", - "additionalProperties": { - "type": "string" - } - }, - "pagination": { - "$ref": "#/definitions/param.PaginationResponse" - } - } - }, - "adminkindboxreqparam.DeliveryAwaitingGetResponse": { - "type": "object", - "properties": { - "data": { - "$ref": "#/definitions/adminkindboxreqparam.Data" - }, - "field_errors": { - "type": "object", - "additionalProperties": { - "type": "string" - } - } - } - }, "adminkindboxreqparam.GetKindBoxReqResponse": { "type": "object", "properties": { @@ -3379,6 +3318,108 @@ } } }, + "agentkindboxreqparam.Data": { + "type": "object", + "properties": { + "benefactor_id": { + "type": "integer" + }, + "count_accepted": { + "type": "integer" + }, + "count_requested": { + "type": "integer" + }, + "deliver_address_id": { + "type": "integer" + }, + "deliver_refer_date": { + "type": "string" + }, + "deliver_refer_time_id": { + "type": "integer" + }, + "delivered_at": { + "type": "string" + }, + "description": { + "type": "string" + }, + "id": { + "type": "integer" + }, + "kind_box_type": { + "$ref": "#/definitions/entity.KindBoxType" + }, + "sender_agent_id": { + "type": "integer" + }, + "status": { + "$ref": "#/definitions/entity.KindBoxReqStatus" + } + } + }, + "agentkindboxreqparam.DeliverKindBoxReqRequest": { + "type": "object", + "properties": { + "serial_numbers": { + "type": "array", + "items": { + "type": "string" + }, + "example": [ + "1", + "2", + "3" + ] + } + } + }, + "agentkindboxreqparam.DeliverKindBoxReqResponse": { + "type": "object", + "properties": { + "field_errors": { + "type": "object", + "additionalProperties": { + "type": "string" + } + } + } + }, + "agentkindboxreqparam.DeliveryAwaitingGetAllResponse": { + "type": "object", + "properties": { + "data": { + "type": "array", + "items": { + "$ref": "#/definitions/agentkindboxreqparam.Data" + } + }, + "field_errors": { + "type": "object", + "additionalProperties": { + "type": "string" + } + }, + "pagination": { + "$ref": "#/definitions/param.PaginationResponse" + } + } + }, + "agentkindboxreqparam.DeliveryAwaitingGetResponse": { + "type": "object", + "properties": { + "data": { + "$ref": "#/definitions/agentkindboxreqparam.Data" + }, + "field_errors": { + "type": "object", + "additionalProperties": { + "type": "string" + } + } + } + }, "benefactoreparam.Data": { "type": "object", "properties": { diff --git a/docs/swagger.yaml b/docs/swagger.yaml index 98c9827..c01c107 100644 --- a/docs/swagger.yaml +++ b/docs/swagger.yaml @@ -252,46 +252,6 @@ definitions: status: $ref: '#/definitions/entity.KindBoxReqStatus' type: object - adminkindboxreqparam.DeliverKindBoxReqRequest: - properties: - serial_numbers: - example: - - "1" - - "2" - - "3" - items: - type: string - type: array - type: object - adminkindboxreqparam.DeliverKindBoxReqResponse: - properties: - field_errors: - additionalProperties: - type: string - type: object - type: object - adminkindboxreqparam.DeliveryAwaitingGetAllResponse: - properties: - data: - items: - $ref: '#/definitions/adminkindboxreqparam.Data' - type: array - field_errors: - additionalProperties: - type: string - type: object - pagination: - $ref: '#/definitions/param.PaginationResponse' - type: object - adminkindboxreqparam.DeliveryAwaitingGetResponse: - properties: - data: - $ref: '#/definitions/adminkindboxreqparam.Data' - field_errors: - additionalProperties: - type: string - type: object - type: object adminkindboxreqparam.GetKindBoxReqResponse: properties: data: @@ -565,6 +525,73 @@ definitions: serial_number: type: string type: object + agentkindboxreqparam.Data: + properties: + benefactor_id: + type: integer + count_accepted: + type: integer + count_requested: + type: integer + deliver_address_id: + type: integer + deliver_refer_date: + type: string + deliver_refer_time_id: + type: integer + delivered_at: + type: string + description: + type: string + id: + type: integer + kind_box_type: + $ref: '#/definitions/entity.KindBoxType' + sender_agent_id: + type: integer + status: + $ref: '#/definitions/entity.KindBoxReqStatus' + type: object + agentkindboxreqparam.DeliverKindBoxReqRequest: + properties: + serial_numbers: + example: + - "1" + - "2" + - "3" + items: + type: string + type: array + type: object + agentkindboxreqparam.DeliverKindBoxReqResponse: + properties: + field_errors: + additionalProperties: + type: string + type: object + type: object + agentkindboxreqparam.DeliveryAwaitingGetAllResponse: + properties: + data: + items: + $ref: '#/definitions/agentkindboxreqparam.Data' + type: array + field_errors: + additionalProperties: + type: string + type: object + pagination: + $ref: '#/definitions/param.PaginationResponse' + type: object + agentkindboxreqparam.DeliveryAwaitingGetResponse: + properties: + data: + $ref: '#/definitions/agentkindboxreqparam.Data' + field_errors: + additionalProperties: + type: string + type: object + type: object benefactoreparam.Data: properties: first_name: @@ -1514,38 +1541,6 @@ paths: summary: Admin Assign Sender Agent to kindboxreq tags: - Admins KindBoxReqs - /admins/kindboxreqs/{id}/deliver-kind-box-req: - patch: - consumes: - - application/json - parameters: - - description: KindBoxReq ID - in: path - name: id - required: true - type: integer - - description: KindBoxReq deliver request details - in: body - name: Request - required: true - schema: - $ref: '#/definitions/adminkindboxreqparam.DeliverKindBoxReqRequest' - produces: - - application/json - responses: - "200": - description: OK - schema: - $ref: '#/definitions/adminkindboxreqparam.DeliverKindBoxReqResponse' - "400": - description: Bad request - schema: - type: string - security: - - AuthBearerAdmin: [] - summary: Admin deliver a kindboxreq - tags: - - Admins KindBoxReqs /admins/kindboxreqs/{id}/reject-kind-box-req: patch: consumes: @@ -1578,121 +1573,6 @@ paths: summary: Reject a kindboxreq by admin tags: - Admins KindBoxReqs - /admins/kindboxreqs/awaiting-delivery: - get: - consumes: - - application/json - description: Retrieves a list of all awaiting KindBox requests with filtering, - sorting, and pagination options - parameters: - - description: Filter by ID - in: query - name: filter_id - type: integer - - description: Filter by benefactor ID - in: query - name: filter_benefactor_id - type: integer - - description: Filter by KindBox type - enum: - - on-table - - cylindrical - - stand-up - format: enum - in: query - name: filter_kind_box_type - type: string - - description: Filter by count requested - in: query - name: filter_count_requested - type: integer - - description: Filter by count accepted - in: query - name: filter_count_accepted - type: integer - - description: Filter by deliver refer time ID - in: query - name: filter_deliver_refer_time_id - type: integer - - description: Filter by deliver refer date - format: date - in: query - name: filter_deliver_refer_date - type: string - - description: Filter by deliver address ID - in: query - name: filter_deliver_address_id - type: integer - - description: Page number - in: query - name: page_number - type: integer - - description: Page size - in: query - name: page_size - type: integer - - description: Sort by field - enum: - - id - - benefactor_id - - kind_box_type - - count_requested - - count_accepted - - deliver_refer_time_id - - deliver_refer_date - - deliver_address_id - in: query - name: sort_field - type: string - - description: Sort order - enum: - - asc - - desc - in: query - name: sort_direction - type: string - produces: - - application/json - responses: - "200": - description: OK - schema: - $ref: '#/definitions/adminkindboxreqparam.DeliveryAwaitingGetAllResponse' - "400": - description: Bad request - schema: - type: string - security: - - AuthBearerAdmin: [] - summary: Get all awaiting delivery KindBox requests - tags: - - Admins KindBoxReqs - /admins/kindboxreqs/awaiting-delivery/{id}: - get: - consumes: - - application/json - parameters: - - description: KindBoxReq ID - in: path - name: id - required: true - type: integer - produces: - - application/json - responses: - "200": - description: OK - schema: - $ref: '#/definitions/adminkindboxreqparam.DeliveryAwaitingGetResponse' - "400": - description: Bad request - schema: - type: string - security: - - AuthBearerAdmin: [] - summary: Get a kind box reqs that is awaiting delivery by agent - tags: - - Admins KindBoxReqs /admins/login-by-phone: post: consumes: @@ -1933,6 +1813,153 @@ paths: summary: Return KindBox from benefactor by agent tags: - Agents KindBoxes + /agents/kindboxreqs/{id}/deliver-kind-box-req: + patch: + consumes: + - application/json + parameters: + - description: KindBoxReq ID + in: path + name: id + required: true + type: integer + - description: KindBoxReq deliver request details + in: body + name: Request + required: true + schema: + $ref: '#/definitions/agentkindboxreqparam.DeliverKindBoxReqRequest' + produces: + - application/json + responses: + "200": + description: OK + schema: + $ref: '#/definitions/agentkindboxreqparam.DeliverKindBoxReqResponse' + "400": + description: Bad request + schema: + type: string + security: + - AuthBearerAdmin: [] + summary: Agent deliver a kindboxreq + tags: + - Agents KindBoxReqs + /agents/kindboxreqs/awaiting-delivery: + get: + consumes: + - application/json + description: Retrieves a list of all awaiting KindBox requests with filtering, + sorting, and pagination options + parameters: + - description: Filter by ID + in: query + name: filter_id + type: integer + - description: Filter by benefactor ID + in: query + name: filter_benefactor_id + type: integer + - description: Filter by KindBox type + enum: + - on-table + - cylindrical + - stand-up + format: enum + in: query + name: filter_kind_box_type + type: string + - description: Filter by count requested + in: query + name: filter_count_requested + type: integer + - description: Filter by count accepted + in: query + name: filter_count_accepted + type: integer + - description: Filter by deliver refer time ID + in: query + name: filter_deliver_refer_time_id + type: integer + - description: Filter by deliver refer date + format: date + in: query + name: filter_deliver_refer_date + type: string + - description: Filter by deliver address ID + in: query + name: filter_deliver_address_id + type: integer + - description: Page number + in: query + name: page_number + type: integer + - description: Page size + in: query + name: page_size + type: integer + - description: Sort by field + enum: + - id + - benefactor_id + - kind_box_type + - count_requested + - count_accepted + - deliver_refer_time_id + - deliver_refer_date + - deliver_address_id + in: query + name: sort_field + type: string + - description: Sort order + enum: + - asc + - desc + in: query + name: sort_direction + type: string + produces: + - application/json + responses: + "200": + description: OK + schema: + $ref: '#/definitions/agentkindboxreqparam.DeliveryAwaitingGetAllResponse' + "400": + description: Bad request + schema: + type: string + security: + - AuthBearerAdmin: [] + summary: Get all awaiting delivery KindBox requests + tags: + - Agents KindBoxReqs + /agents/kindboxreqs/awaiting-delivery/{id}: + get: + consumes: + - application/json + parameters: + - description: KindBoxReq ID + in: path + name: id + required: true + type: integer + produces: + - application/json + responses: + "200": + description: OK + schema: + $ref: '#/definitions/agentkindboxreqparam.DeliveryAwaitingGetResponse' + "400": + description: Bad request + schema: + type: string + security: + - AuthBearerAdmin: [] + summary: Get a kind box reqs that is awaiting delivery by agent + tags: + - Agents KindBoxReqs /benefactors/addresses: get: consumes: diff --git a/param/agent/kind_box/get_all.go b/param/agent/kind_box/get_all_return_awaiting.go similarity index 100% rename from param/agent/kind_box/get_all.go rename to param/agent/kind_box/get_all_return_awaiting.go diff --git a/param/agent/kind_box/get.go b/param/agent/kind_box/get_awaiting_return.go similarity index 100% rename from param/agent/kind_box/get.go rename to param/agent/kind_box/get_awaiting_return.go diff --git a/param/agent/kind_box_req/data.go b/param/agent/kind_box_req/data.go new file mode 100644 index 0000000..b73b104 --- /dev/null +++ b/param/agent/kind_box_req/data.go @@ -0,0 +1,22 @@ +package agentkindboxreqparam + +import ( + "time" + + "git.gocasts.ir/ebhomengo/niki/entity" +) + +type Data struct { + ID uint `json:"id"` + BenefactorID uint `json:"benefactor_id"` + KindBoxType entity.KindBoxType `json:"kind_box_type"` + CountRequested uint `json:"count_requested"` + CountAccepted uint `json:"count_accepted"` + Description string `json:"description"` + Status entity.KindBoxReqStatus `json:"status"` + DeliverReferTimeID uint `json:"deliver_refer_time_id"` + DeliverReferDate time.Time `json:"deliver_refer_date"` + DeliverAddressID uint `json:"deliver_address_id"` + SenderAgentID uint `json:"sender_agent_id"` + DeliveredAt time.Time `json:"delivered_at"` +} diff --git a/param/admin/kind_box_req/deliver.go b/param/agent/kind_box_req/deliver.go similarity index 89% rename from param/admin/kind_box_req/deliver.go rename to param/agent/kind_box_req/deliver.go index 5cb861d..c08b2b4 100644 --- a/param/admin/kind_box_req/deliver.go +++ b/param/agent/kind_box_req/deliver.go @@ -1,4 +1,4 @@ -package adminkindboxreqparam +package agentkindboxreqparam type DeliverKindBoxReqRequest struct { KindBoxReqID uint `json:"-" param:"id"` diff --git a/param/admin/kind_box_req/get_all_delivery_awaiting.go b/param/agent/kind_box_req/get_all_delivery_awaiting.go similarity index 93% rename from param/admin/kind_box_req/get_all_delivery_awaiting.go rename to param/agent/kind_box_req/get_all_delivery_awaiting.go index aa11285..2634e7d 100644 --- a/param/admin/kind_box_req/get_all_delivery_awaiting.go +++ b/param/agent/kind_box_req/get_all_delivery_awaiting.go @@ -1,4 +1,4 @@ -package adminkindboxreqparam +package agentkindboxreqparam import ( "git.gocasts.ir/ebhomengo/niki/param" diff --git a/param/admin/kind_box_req/get_delivery_awaiting.go b/param/agent/kind_box_req/get_delivery_awaiting.go similarity index 89% rename from param/admin/kind_box_req/get_delivery_awaiting.go rename to param/agent/kind_box_req/get_delivery_awaiting.go index 2569285..ed914fe 100644 --- a/param/admin/kind_box_req/get_delivery_awaiting.go +++ b/param/agent/kind_box_req/get_delivery_awaiting.go @@ -1,4 +1,4 @@ -package adminkindboxreqparam +package agentkindboxreqparam type DeliveryAwaitingGetRequest struct { KindBoxReqID uint `param:"id"` diff --git a/service/admin/kind_box_req/service.go b/service/admin/kind_box_req/service.go index db48842..76fc1bc 100644 --- a/service/admin/kind_box_req/service.go +++ b/service/admin/kind_box_req/service.go @@ -5,7 +5,6 @@ import ( "git.gocasts.ir/ebhomengo/niki/entity" params "git.gocasts.ir/ebhomengo/niki/param" - param "git.gocasts.ir/ebhomengo/niki/param/admin/kind_box" validator "git.gocasts.ir/ebhomengo/niki/validator/admin/kind_box_req" ) @@ -21,20 +20,14 @@ type Repository interface { UpdateKindBoxReq(ctx context.Context, kindBoxReq entity.KindBoxReq) error } -type KindBoxSvc interface { - AddBatchKindBox(ctx context.Context, req param.AddKindBoxRequest) (param.AddKindBoxResponse, error) -} - type Service struct { - repo Repository - kindBoxSvc KindBoxSvc - vld validator.Validator + repo Repository + vld validator.Validator } -func New(repository Repository, kindBoxSvc KindBoxSvc, vld validator.Validator) Service { +func New(repository Repository, vld validator.Validator) Service { return Service{ - repo: repository, - kindBoxSvc: kindBoxSvc, - vld: vld, + repo: repository, + vld: vld, } } diff --git a/service/agent/kind_box/get_all.go b/service/agent/kind_box/get_all_return_awaiting.go similarity index 100% rename from service/agent/kind_box/get_all.go rename to service/agent/kind_box/get_all_return_awaiting.go diff --git a/service/agent/kind_box/get.go b/service/agent/kind_box/get_return_awaiting.go similarity index 100% rename from service/agent/kind_box/get.go rename to service/agent/kind_box/get_return_awaiting.go diff --git a/service/admin/kind_box_req/deliver.go b/service/agent/kind_box_req/deliver.go similarity index 94% rename from service/admin/kind_box_req/deliver.go rename to service/agent/kind_box_req/deliver.go index ae5feb3..b665bf3 100644 --- a/service/admin/kind_box_req/deliver.go +++ b/service/agent/kind_box_req/deliver.go @@ -1,11 +1,11 @@ -package adminkindboxreqservice +package agentkindboxreqservice import ( "context" + param "git.gocasts.ir/ebhomengo/niki/param/agent/kind_box_req" "time" kindboxParam "git.gocasts.ir/ebhomengo/niki/param/admin/kind_box" - param "git.gocasts.ir/ebhomengo/niki/param/admin/kind_box_req" richerror "git.gocasts.ir/ebhomengo/niki/pkg/rich_error" ) diff --git a/service/admin/kind_box_req/get_all_delivery_awaiting.go b/service/agent/kind_box_req/get_all_delivery_awaiting.go similarity index 94% rename from service/admin/kind_box_req/get_all_delivery_awaiting.go rename to service/agent/kind_box_req/get_all_delivery_awaiting.go index 732e0d2..6a07616 100644 --- a/service/admin/kind_box_req/get_all_delivery_awaiting.go +++ b/service/agent/kind_box_req/get_all_delivery_awaiting.go @@ -1,10 +1,9 @@ -package adminkindboxreqservice +package agentkindboxreqservice import ( "context" - paginationparam "git.gocasts.ir/ebhomengo/niki/param" - param "git.gocasts.ir/ebhomengo/niki/param/admin/kind_box_req" + param "git.gocasts.ir/ebhomengo/niki/param/agent/kind_box_req" richerror "git.gocasts.ir/ebhomengo/niki/pkg/rich_error" ) diff --git a/service/admin/kind_box_req/get_delivery_awaiting.go b/service/agent/kind_box_req/get_delivery_awaiting.go similarity index 93% rename from service/admin/kind_box_req/get_delivery_awaiting.go rename to service/agent/kind_box_req/get_delivery_awaiting.go index 8c51af3..e44267c 100644 --- a/service/admin/kind_box_req/get_delivery_awaiting.go +++ b/service/agent/kind_box_req/get_delivery_awaiting.go @@ -1,9 +1,8 @@ -package adminkindboxreqservice +package agentkindboxreqservice import ( "context" - - param "git.gocasts.ir/ebhomengo/niki/param/admin/kind_box_req" + param "git.gocasts.ir/ebhomengo/niki/param/agent/kind_box_req" richerror "git.gocasts.ir/ebhomengo/niki/pkg/rich_error" ) diff --git a/service/agent/kind_box_req/service.go b/service/agent/kind_box_req/service.go new file mode 100644 index 0000000..1ee66d7 --- /dev/null +++ b/service/agent/kind_box_req/service.go @@ -0,0 +1,34 @@ +package agentkindboxreqservice + +import ( + "context" + param "git.gocasts.ir/ebhomengo/niki/param/admin/kind_box" + + "git.gocasts.ir/ebhomengo/niki/entity" + params "git.gocasts.ir/ebhomengo/niki/param" + validator "git.gocasts.ir/ebhomengo/niki/validator/agent/kind_box_req" +) + +type Repository interface { + GetAllKindBoxReq(ctx context.Context, filter params.FilterRequest, pagination params.PaginationRequest, sort params.SortRequest) ([]entity.KindBoxReq, uint, error) + DeliverKindBoxReq(ctx context.Context, kindBoxReqID uint) error + GetAwaitingDeliveryByAgent(ctx context.Context, kindBoxReqID uint, agentID uint) (entity.KindBoxReq, error) + GetByID(ctx context.Context, id uint) (entity.KindBoxReq, error) +} + +type KindBoxSvc interface { + AddBatchKindBox(ctx context.Context, req param.AddKindBoxRequest) (param.AddKindBoxResponse, error) +} + +type Service struct { + repo Repository + kindBoxSvc KindBoxSvc + vld validator.Validator +} + +func New(repo Repository, vld validator.Validator) Service { + return Service{ + repo: repo, + vld: vld, + } +} diff --git a/service/service.go b/service/service.go index f00ae19..f0fd632 100644 --- a/service/service.go +++ b/service/service.go @@ -22,6 +22,7 @@ import ( adminkindboxreqservice "git.gocasts.ir/ebhomengo/niki/service/admin/kind_box_req" adminrefertimeservice "git.gocasts.ir/ebhomengo/niki/service/admin/refer_time" 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" benefactoraddressservice "git.gocasts.ir/ebhomengo/niki/service/benefactor/address" benefactorservice "git.gocasts.ir/ebhomengo/niki/service/benefactor/benefactor" @@ -33,6 +34,7 @@ import ( adminkindboxvalidator "git.gocasts.ir/ebhomengo/niki/validator/admin/kind_box" adminkindboxreqvalidator "git.gocasts.ir/ebhomengo/niki/validator/admin/kind_box_req" agentkindboxvalidator "git.gocasts.ir/ebhomengo/niki/validator/agent/kind_box" + agentkindboxreqvalidator "git.gocasts.ir/ebhomengo/niki/validator/agent/kind_box_req" benefactoraddressvalidator "git.gocasts.ir/ebhomengo/niki/validator/benefactor/address" benefactorvalidator "git.gocasts.ir/ebhomengo/niki/validator/benefactor/benefactor" benefactorkindboxvalidator "git.gocasts.ir/ebhomengo/niki/validator/benefactor/kind_box" @@ -47,6 +49,7 @@ type Service struct { AdminSvc adminservice.Service AdminAgentSvc adminagentservice.Service AgentKindBoxSvc agentkindboxservice.Service + AgentKindBoxReqSvc agentkindboxreqservice.Service BenefactorAuthSvc auth.Service BenefactorKindBoxSvc benefactorkindboxservice.Service BenefactorKindBoxReqSvc benefactorkindboxreqservice.Service @@ -79,11 +82,13 @@ func New(cfg config.Config, db *mysql.DB, rds *redis.Adapter, smsAdapter smscont AdminKindBoxVld = adminkindboxvalidator.New(kindBoxRepo, AdminAgentSvc, AdminBenefactorSvc, AdminReferTimeSvc, AdminAddressSvc) AdminKindBoxSvc = adminkindboxservice.New(kindBoxRepo, AdminKindBoxVld) AdminKindBoxReqVld = adminkindboxreqvalidator.New(kindBoxReqRepo, AdminSvc, AdminAgentSvc, AdminBenefactorSvc, AdminReferTimeSvc, AdminAddressSvc) - AdminKindBoxReqSvc = adminkindboxreqservice.New(kindBoxReqRepo, AdminKindBoxSvc, AdminKindBoxReqVld) + AdminKindBoxReqSvc = adminkindboxreqservice.New(kindBoxReqRepo, AdminKindBoxReqVld) ) var ( - AgentKindBoxVld = agentkindboxvalidator.New(kindBoxRepo) - AgentKindBoxSvc = agentkindboxservice.New(kindBoxRepo, AgentKindBoxVld) + AgentKindBoxVld = agentkindboxvalidator.New(kindBoxRepo) + AgentKindBoxSvc = agentkindboxservice.New(kindBoxRepo, AgentKindBoxVld) + AgentKindBoxReqVld = agentkindboxreqvalidator.New(kindBoxReqRepo) + AgentKindBoxReqSvc = agentkindboxreqservice.New(kindBoxReqRepo, AgentKindBoxReqVld) ) var ( BenefactorAuthSvc = auth.New(cfg.BenefactorAuth) @@ -108,6 +113,7 @@ func New(cfg config.Config, db *mysql.DB, rds *redis.Adapter, smsAdapter smscont AdminSvc: AdminSvc, AdminAgentSvc: AdminAgentSvc, AgentKindBoxSvc: AgentKindBoxSvc, + AgentKindBoxReqSvc: AgentKindBoxReqSvc, BenefactorAuthSvc: BenefactorAuthSvc, BenefactorKindBoxSvc: BenefactorKindBoxSvc, BenefactorKindBoxReqSvc: BenefactorKindBoxReqSvc, diff --git a/validator/admin/kind_box/get_all.go b/validator/admin/kind_box/get_all.go index 1a797fc..0ab8979 100644 --- a/validator/admin/kind_box/get_all.go +++ b/validator/admin/kind_box/get_all.go @@ -6,7 +6,6 @@ import ( param "git.gocasts.ir/ebhomengo/niki/param/admin/kind_box" errmsg "git.gocasts.ir/ebhomengo/niki/pkg/err_msg" richerror "git.gocasts.ir/ebhomengo/niki/pkg/rich_error" - "git.gocasts.ir/ebhomengo/niki/validator" validation "github.com/go-ozzo/ozzo-validation/v4" ) @@ -20,8 +19,8 @@ func (v Validator) ValidateGetAll(req param.KindBoxGetAllRequest) (map[string]st "return_address_id", "receiver_agent_id", "returned_at", } if err := validation.ValidateStruct(&req, - validation.Field(&req.Filter, validation.By(validator.AreFilterFieldsValid(validFields))), - validation.Field(&req.Sort, validation.By(validator.AreSortFieldsValid(validFields))), + validation.Field(&req.Filter, validation.By(v.AreFilterFieldsValid(validFields))), + validation.Field(&req.Sort, validation.By(v.AreSortFieldsValid(validFields))), ); err != nil { fieldErrors := make(map[string]string) diff --git a/validator/admin/kind_box/validator.go b/validator/admin/kind_box/validator.go index 030e56d..4e32b03 100644 --- a/validator/admin/kind_box/validator.go +++ b/validator/admin/kind_box/validator.go @@ -4,6 +4,8 @@ import ( "context" "errors" "fmt" + params "git.gocasts.ir/ebhomengo/niki/param" + "slices" "time" entity "git.gocasts.ir/ebhomengo/niki/entity" @@ -98,7 +100,6 @@ func (v Validator) doesBenefactorExist(ctx context.Context) validation.RuleFunc } } - func (v Validator) doesBenefactorHaveKindBox(ctx context.Context, kindBoxID uint, benefactorID uint) validation.RuleFunc { return func(value interface{}) error { const op = "Validator.doesBenefactorHaveKindBox" @@ -220,7 +221,6 @@ func (v Validator) isDateValid(value interface{}) error { return nil } - func (v Validator) isAmountValid(ctx context.Context) validation.RuleFunc { return func(value interface{}) error { const op = "Validator.isAmountValid" @@ -232,7 +232,7 @@ func (v Validator) isAmountValid(ctx context.Context) validation.RuleFunc { } } -//processing errors +// processing errors func (v Validator) processValidationErrors(err error, fieldErrors map[string]string) { var errV validation.Errors if errors.As(err, &errV) { @@ -243,3 +243,39 @@ func (v Validator) processValidationErrors(err error, fieldErrors map[string]str } } } + +func (v Validator) AreSortFieldsValid(validSortFields []string) validation.RuleFunc { + return func(value interface{}) error { + sort, ok := value.(params.SortRequest) + if !ok { + return fmt.Errorf(errmsg.ErrorMsgSomethingWentWrong) + } + if sort.Field == "" && sort.Direction != "" { + return fmt.Errorf(errmsg.ErrorMsgSortFieldIsRequired) + } + if sort.Direction != "" && sort.Direction != params.AscSortDirection && sort.Direction != params.DescSortDirection { + return fmt.Errorf(errmsg.ErrorMsgSortDirectionShouldBeAscOrDesc) + } + if sort.Field != "" && !slices.Contains(validSortFields, sort.Field) { + return fmt.Errorf(errmsg.ErrorMsgSortFieldIsNotValid) + } + + return nil + } +} + +func (v Validator) AreFilterFieldsValid(validFilters []string) validation.RuleFunc { + return func(value interface{}) error { + filters, ok := value.(params.FilterRequest) + if !ok { + return fmt.Errorf(errmsg.ErrorMsgSomethingWentWrong) + } + for filter := range filters { + if !slices.Contains(validFilters, filter) { + return fmt.Errorf(errmsg.ErrorMsgFiltersAreNotValid) + } + } + + return nil + } +} diff --git a/validator/admin/kind_box_req/get_all.go b/validator/admin/kind_box_req/get_all.go index 0b97cc2..edd1a05 100644 --- a/validator/admin/kind_box_req/get_all.go +++ b/validator/admin/kind_box_req/get_all.go @@ -6,7 +6,6 @@ import ( param "git.gocasts.ir/ebhomengo/niki/param/admin/kind_box_req" errmsg "git.gocasts.ir/ebhomengo/niki/pkg/err_msg" richerror "git.gocasts.ir/ebhomengo/niki/pkg/rich_error" - "git.gocasts.ir/ebhomengo/niki/validator" validation "github.com/go-ozzo/ozzo-validation/v4" ) @@ -19,8 +18,8 @@ func (v Validator) ValidateGetAll(req param.KindBoxReqGetAllRequest) (map[string "deliver_address_id", "delivered_at", } if err := validation.ValidateStruct(&req, - validation.Field(&req.Filter, validation.By(validator.AreFilterFieldsValid(validFields))), - validation.Field(&req.Sort, validation.By(validator.AreSortFieldsValid(validFields))), + validation.Field(&req.Filter, validation.By(v.AreFilterFieldsValid(validFields))), + validation.Field(&req.Sort, validation.By(v.AreSortFieldsValid(validFields))), ); err != nil { fieldErrors := make(map[string]string) diff --git a/validator/admin/kind_box_req/validator.go b/validator/admin/kind_box_req/validator.go index a19723f..dd05eef 100644 --- a/validator/admin/kind_box_req/validator.go +++ b/validator/admin/kind_box_req/validator.go @@ -304,3 +304,39 @@ func (v Validator) IsSerialNumbersCountValid(ctx context.Context, kindBoxReqID u return nil } } + +func (v Validator) AreSortFieldsValid(validSortFields []string) validation.RuleFunc { + return func(value interface{}) error { + sort, ok := value.(params.SortRequest) + if !ok { + return fmt.Errorf(errmsg.ErrorMsgSomethingWentWrong) + } + if sort.Field == "" && sort.Direction != "" { + return fmt.Errorf(errmsg.ErrorMsgSortFieldIsRequired) + } + if sort.Direction != "" && sort.Direction != params.AscSortDirection && sort.Direction != params.DescSortDirection { + return fmt.Errorf(errmsg.ErrorMsgSortDirectionShouldBeAscOrDesc) + } + if sort.Field != "" && !slices.Contains(validSortFields, sort.Field) { + return fmt.Errorf(errmsg.ErrorMsgSortFieldIsNotValid) + } + + return nil + } +} + +func (v Validator) AreFilterFieldsValid(validFilters []string) validation.RuleFunc { + return func(value interface{}) error { + filters, ok := value.(params.FilterRequest) + if !ok { + return fmt.Errorf(errmsg.ErrorMsgSomethingWentWrong) + } + for filter := range filters { + if !slices.Contains(validFilters, filter) { + return fmt.Errorf(errmsg.ErrorMsgFiltersAreNotValid) + } + } + + return nil + } +} diff --git a/validator/agent/kind_box/get_all.go b/validator/agent/kind_box/get_all_return_awaiting.go similarity index 83% rename from validator/agent/kind_box/get_all.go rename to validator/agent/kind_box/get_all_return_awaiting.go index 9b2bfd3..1bc9240 100644 --- a/validator/agent/kind_box/get_all.go +++ b/validator/agent/kind_box/get_all_return_awaiting.go @@ -6,7 +6,6 @@ import ( param "git.gocasts.ir/ebhomengo/niki/param/agent/kind_box" errmsg "git.gocasts.ir/ebhomengo/niki/pkg/err_msg" richerror "git.gocasts.ir/ebhomengo/niki/pkg/rich_error" - "git.gocasts.ir/ebhomengo/niki/validator" validation "github.com/go-ozzo/ozzo-validation/v4" ) @@ -19,8 +18,8 @@ func (v Validator) ValidateGetAll(req param.GetAllRequest) (map[string]string, e "return_refer_time_id", "return_refer_date", "return_address_id", } if err := validation.ValidateStruct(&req, - validation.Field(&req.Filter, validation.By(validator.AreFilterFieldsValid(validFields))), - validation.Field(&req.Sort, validation.By(validator.AreSortFieldsValid(validFields))), + validation.Field(&req.Filter, validation.By(v.AreFilterFieldsValid(validFields))), + validation.Field(&req.Sort, validation.By(v.AreSortFieldsValid(validFields))), ); err != nil { fieldErrors := make(map[string]string) diff --git a/validator/agent/kind_box/get.go b/validator/agent/kind_box/get_return_awaiting.go similarity index 100% rename from validator/agent/kind_box/get.go rename to validator/agent/kind_box/get_return_awaiting.go diff --git a/validator/agent/kind_box/validator.go b/validator/agent/kind_box/validator.go index 2cd0869..4339054 100644 --- a/validator/agent/kind_box/validator.go +++ b/validator/agent/kind_box/validator.go @@ -3,6 +3,8 @@ package agentkindboxvalidator import ( "context" "fmt" + params "git.gocasts.ir/ebhomengo/niki/param" + "slices" errmsg "git.gocasts.ir/ebhomengo/niki/pkg/err_msg" validation "github.com/go-ozzo/ozzo-validation/v4" @@ -37,3 +39,38 @@ func (v Validator) doesKindBoxExistForAgent(ctx context.Context, agentID uint) v return nil } } +func (v Validator) AreSortFieldsValid(validSortFields []string) validation.RuleFunc { + return func(value interface{}) error { + sort, ok := value.(params.SortRequest) + if !ok { + return fmt.Errorf(errmsg.ErrorMsgSomethingWentWrong) + } + if sort.Field == "" && sort.Direction != "" { + return fmt.Errorf(errmsg.ErrorMsgSortFieldIsRequired) + } + if sort.Direction != "" && sort.Direction != params.AscSortDirection && sort.Direction != params.DescSortDirection { + return fmt.Errorf(errmsg.ErrorMsgSortDirectionShouldBeAscOrDesc) + } + if sort.Field != "" && !slices.Contains(validSortFields, sort.Field) { + return fmt.Errorf(errmsg.ErrorMsgSortFieldIsNotValid) + } + + return nil + } +} + +func (v Validator) AreFilterFieldsValid(validFilters []string) validation.RuleFunc { + return func(value interface{}) error { + filters, ok := value.(params.FilterRequest) + if !ok { + return fmt.Errorf(errmsg.ErrorMsgSomethingWentWrong) + } + for filter := range filters { + if !slices.Contains(validFilters, filter) { + return fmt.Errorf(errmsg.ErrorMsgFiltersAreNotValid) + } + } + + return nil + } +} diff --git a/validator/admin/kind_box_req/deliver.go b/validator/agent/kind_box_req/deliver.go similarity index 92% rename from validator/admin/kind_box_req/deliver.go rename to validator/agent/kind_box_req/deliver.go index c6d0b75..068bf75 100644 --- a/validator/admin/kind_box_req/deliver.go +++ b/validator/agent/kind_box_req/deliver.go @@ -1,10 +1,9 @@ -package adminkindboxreqvalidator +package agentkindboxreqvalidator import ( "context" "errors" - - param "git.gocasts.ir/ebhomengo/niki/param/admin/kind_box_req" + param "git.gocasts.ir/ebhomengo/niki/param/agent/kind_box_req" errmsg "git.gocasts.ir/ebhomengo/niki/pkg/err_msg" richerror "git.gocasts.ir/ebhomengo/niki/pkg/rich_error" validation "github.com/go-ozzo/ozzo-validation/v4" diff --git a/validator/admin/kind_box_req/get_all_delivery_awaiting.go b/validator/agent/kind_box_req/get_all_delivery_awaiting.go similarity index 92% rename from validator/admin/kind_box_req/get_all_delivery_awaiting.go rename to validator/agent/kind_box_req/get_all_delivery_awaiting.go index b28a215..b37e104 100644 --- a/validator/admin/kind_box_req/get_all_delivery_awaiting.go +++ b/validator/agent/kind_box_req/get_all_delivery_awaiting.go @@ -1,9 +1,8 @@ -package adminkindboxreqvalidator +package agentkindboxreqvalidator import ( "errors" - - kbrparam "git.gocasts.ir/ebhomengo/niki/param/admin/kind_box_req" + kbrparam "git.gocasts.ir/ebhomengo/niki/param/agent/kind_box_req" errmsg "git.gocasts.ir/ebhomengo/niki/pkg/err_msg" richerror "git.gocasts.ir/ebhomengo/niki/pkg/rich_error" validation "github.com/go-ozzo/ozzo-validation/v4" diff --git a/validator/admin/kind_box_req/get_delivery_awaiting.go b/validator/agent/kind_box_req/get_delivery_awaiting.go similarity index 90% rename from validator/admin/kind_box_req/get_delivery_awaiting.go rename to validator/agent/kind_box_req/get_delivery_awaiting.go index b0dbc08..00499fe 100644 --- a/validator/admin/kind_box_req/get_delivery_awaiting.go +++ b/validator/agent/kind_box_req/get_delivery_awaiting.go @@ -1,9 +1,8 @@ -package adminkindboxreqvalidator +package agentkindboxreqvalidator import ( "errors" - - param "git.gocasts.ir/ebhomengo/niki/param/admin/kind_box_req" + param "git.gocasts.ir/ebhomengo/niki/param/agent/kind_box_req" errmsg "git.gocasts.ir/ebhomengo/niki/pkg/err_msg" richerror "git.gocasts.ir/ebhomengo/niki/pkg/rich_error" validation "github.com/go-ozzo/ozzo-validation/v4" diff --git a/validator/agent/kind_box_req/validator.go b/validator/agent/kind_box_req/validator.go new file mode 100644 index 0000000..393c984 --- /dev/null +++ b/validator/agent/kind_box_req/validator.go @@ -0,0 +1,117 @@ +package agentkindboxreqvalidator + +import ( + "context" + "errors" + "fmt" + "git.gocasts.ir/ebhomengo/niki/entity" + params "git.gocasts.ir/ebhomengo/niki/param" + "slices" + + errmsg "git.gocasts.ir/ebhomengo/niki/pkg/err_msg" + validation "github.com/go-ozzo/ozzo-validation/v4" +) + +type Repository interface { + KindBoxRequestExist(ctx context.Context, id uint) (bool, error) + GetByID(ctx context.Context, id uint) (entity.KindBoxReq, error) +} + +type Validator struct { + repo Repository +} + +func New(repo Repository) Validator { + return Validator{repo: repo} +} + +func (v Validator) doesKindBoxRequestExist(ctx context.Context) validation.RuleFunc { + return func(value interface{}) error { + kindboxreqID, ok := value.(uint) + if !ok { + return fmt.Errorf(errmsg.ErrorMsgSomethingWentWrong) + } + if isExist, err := v.repo.KindBoxRequestExist(ctx, kindboxreqID); !isExist || err != nil { + if err != nil { + return err + } + if !isExist { + return errors.New("kind box request is not exist") + } + } + + return nil + } +} + +func (v Validator) IsSerialNumbersCountValid(ctx context.Context, kindBoxReqID uint) validation.RuleFunc { + return func(value interface{}) error { + serialNumbers, ok := value.([]string) + if !ok { + return fmt.Errorf(errmsg.ErrorMsgSomethingWentWrong) + } + kindBoxReq, gErr := v.repo.GetByID(ctx, kindBoxReqID) + if gErr != nil { + return fmt.Errorf(errmsg.ErrorMsgSomethingWentWrong) + } + if len(serialNumbers) != 0 && len(serialNumbers) > int(kindBoxReq.CountAccepted) { + return fmt.Errorf(errmsg.ErrorMsgInvalidSerialNumberRange) + } + + return nil + } +} + +func (v Validator) areFilterFieldsValid(validFilters []string) validation.RuleFunc { + return func(value interface{}) error { + filters, ok := value.(params.FilterRequest) + if !ok { + return fmt.Errorf(errmsg.ErrorMsgSomethingWentWrong) + } + for filter := range filters { + if !slices.Contains(validFilters, filter) { + return fmt.Errorf(errmsg.ErrorMsgFiltersAreNotValid) + } + } + + return nil + } +} + +func (v Validator) areSortFieldsValid(validSortFields []string) validation.RuleFunc { + return func(value interface{}) error { + sort, ok := value.(params.SortRequest) + if !ok { + return fmt.Errorf(errmsg.ErrorMsgSomethingWentWrong) + } + if sort.Field == "" && sort.Direction != "" { + return fmt.Errorf(errmsg.ErrorMsgSortFieldIsRequired) + } + if sort.Direction != "" && sort.Direction != params.AscSortDirection && sort.Direction != params.DescSortDirection { + return fmt.Errorf(errmsg.ErrorMsgSortDirectionShouldBeAscOrDesc) + } + if sort.Field != "" && !slices.Contains(validSortFields, sort.Field) { + return fmt.Errorf(errmsg.ErrorMsgSortFieldIsNotValid) + } + + return nil + } +} + +func (v Validator) checkKindBoxReqStatusForDelivering(ctx context.Context) validation.RuleFunc { + return func(value interface{}) error { + kindboxreqID, ok := value.(uint) + if !ok { + return fmt.Errorf(errmsg.ErrorMsgSomethingWentWrong) + } + kindBoxReq, err := v.repo.GetByID(ctx, kindboxreqID) + if err != nil { + return err + } + if kindBoxReq.Status != entity.KindBoxReqAssignedSenderAgentStatus { + return fmt.Errorf(errmsg.ErrorMsgDeliverKindBoxReqStatus) + } + + return nil + } +} diff --git a/validator/filter.go b/validator/filter.go deleted file mode 100644 index 4e30ac8..0000000 --- a/validator/filter.go +++ /dev/null @@ -1,26 +0,0 @@ -package validator - -import ( - "fmt" - "slices" - - params "git.gocasts.ir/ebhomengo/niki/param" - errmsg "git.gocasts.ir/ebhomengo/niki/pkg/err_msg" - validation "github.com/go-ozzo/ozzo-validation/v4" -) - -func AreFilterFieldsValid(validFilters []string) validation.RuleFunc { - return func(value interface{}) error { - filters, ok := value.(params.FilterRequest) - if !ok { - return fmt.Errorf(errmsg.ErrorMsgSomethingWentWrong) - } - for filter := range filters { - if !slices.Contains(validFilters, filter) { - return fmt.Errorf(errmsg.ErrorMsgFiltersAreNotValid) - } - } - - return nil - } -} diff --git a/validator/sort.go b/validator/sort.go deleted file mode 100644 index 64d777e..0000000 --- a/validator/sort.go +++ /dev/null @@ -1,30 +0,0 @@ -package validator - -import ( - "fmt" - "slices" - - params "git.gocasts.ir/ebhomengo/niki/param" - errmsg "git.gocasts.ir/ebhomengo/niki/pkg/err_msg" - validation "github.com/go-ozzo/ozzo-validation/v4" -) - -func AreSortFieldsValid(validSortFields []string) validation.RuleFunc { - return func(value interface{}) error { - sort, ok := value.(params.SortRequest) - if !ok { - return fmt.Errorf(errmsg.ErrorMsgSomethingWentWrong) - } - if sort.Field == "" && sort.Direction != "" { - return fmt.Errorf(errmsg.ErrorMsgSortFieldIsRequired) - } - if sort.Direction != "" && sort.Direction != params.AscSortDirection && sort.Direction != params.DescSortDirection { - return fmt.Errorf(errmsg.ErrorMsgSortDirectionShouldBeAscOrDesc) - } - if sort.Field != "" && !slices.Contains(validSortFields, sort.Field) { - return fmt.Errorf(errmsg.ErrorMsgSortFieldIsNotValid) - } - - return nil - } -}