forked from ebhomengo/niki
1
0
Fork 0

Merge pull request 'fix(niki): agent structure refactor' (#171) from agent-structure-refactor into develop

Reviewed-on: ebhomengo/niki#171
This commit is contained in:
hossein 2024-09-16 04:52:06 +00:00
commit 47b7f7f216
39 changed files with 1242 additions and 875 deletions

View File

@ -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))
}

View File

@ -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 {

View File

@ -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 {

View File

@ -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 {

View File

@ -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,
}
}

View File

@ -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))
}

View File

@ -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) {

View File

@ -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": [
@ -1614,6 +1392,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": [
@ -3003,67 +3003,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": {
@ -3506,6 +3445,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": {

View File

@ -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": [
@ -1603,6 +1381,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": [
@ -2992,67 +2992,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": {
@ -3495,6 +3434,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": {

View File

@ -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:
@ -578,6 +538,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:
@ -1537,38 +1564,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:
@ -1601,121 +1596,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:
@ -1989,6 +1869,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:

View File

@ -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"`
}

View File

@ -1,4 +1,4 @@
package adminkindboxreqparam
package agentkindboxreqparam
type DeliverKindBoxReqRequest struct {
KindBoxReqID uint `json:"-" param:"id"`

View File

@ -1,4 +1,4 @@
package adminkindboxreqparam
package agentkindboxreqparam
import (
"git.gocasts.ir/ebhomengo/niki/param"

View File

@ -1,4 +1,4 @@
package adminkindboxreqparam
package agentkindboxreqparam
type DeliveryAwaitingGetRequest struct {
KindBoxReqID uint `param:"id"`

View File

@ -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,
}
}

View File

@ -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"
)

View File

@ -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"
)

View File

@ -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"
)

View File

@ -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,
}
}

View File

@ -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,

View File

@ -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)

View File

@ -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
}
}

View File

@ -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)

View File

@ -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
}
}

View File

@ -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)

View File

@ -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
}
}

View File

@ -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"

View File

@ -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"

View File

@ -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"

View File

@ -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
}
}

View File

@ -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
}
}

View File

@ -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
}
}