feat(niki): get-getall kindboxreq with page-filter-sort by benefactor

This commit is contained in:
Iman Mirazimi 2024-07-03 20:48:06 +03:30
parent 47bc77baee
commit ec769748fe
31 changed files with 1651 additions and 87 deletions

View File

@ -74,7 +74,7 @@ func TestAdd(t *testing.T) {
{ {
name: "invalid or expired jwt", name: "invalid or expired jwt",
requestBody: benefactorkindboxreqparam.KindBoxReqAddRequest{ requestBody: benefactorkindboxreqparam.KindBoxReqAddRequest{
TypeID: 1, KindBoxType: 1,
AddressID: address.Address.ID, AddressID: address.Address.ID,
ReferDate: time.Now(), ReferDate: time.Now(),
CountRequested: 1, CountRequested: 1,
@ -96,7 +96,7 @@ func TestAdd(t *testing.T) {
expectedStatus: http.StatusUnprocessableEntity, expectedStatus: http.StatusUnprocessableEntity,
expectedBody: `{ expectedBody: `{
"errors":{ "errors":{
"type_id":"cannot be blank" "kind_box_type":"cannot be blank"
}, },
"message":"invalid input" "message":"invalid input"
}`, }`,
@ -104,7 +104,7 @@ func TestAdd(t *testing.T) {
{ {
name: "Added successfully", name: "Added successfully",
requestBody: benefactorkindboxreqparam.KindBoxReqAddRequest{ requestBody: benefactorkindboxreqparam.KindBoxReqAddRequest{
TypeID: 2, KindBoxType: 2,
AddressID: address.Address.ID, AddressID: address.Address.ID,
ReferDate: time.Now(), ReferDate: time.Now(),
CountRequested: 2, CountRequested: 2,

View File

@ -0,0 +1,62 @@
package benefactorkindboxreqhandler
import (
param "git.gocasts.ir/ebhomengo/niki/param/benefactor/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"
"github.com/labstack/echo/v4"
"net/http"
)
// GetAll godoc
// @Summary Get all KindBox requests
// @Description Retrieves a list of all KindBox requests with filtering, sorting, and pagination options
// @Tags KindBoxReq
// @Accept json
// @Produce json
// @Param filter_id query int false "Filter by ID"
// @Param filter_benefactor_id query int false "Filter by benefactor ID"
// @Param filter_kind_box_type query entity.KindBoxType false "Filter by KindBox type" Format(enum)
// @Param filter_status query string false "Filter by KindBoxReq Status" Enums(pending,accepted,assigned-sender-agent,rejected,delivered)
// @Param filter_count_requested query int false "Filter by count requested"
// @Param filter_count_accepted query int false "Filter by count accepted"
// @Param filter_deliver_refer_time_id query int false "Filter by deliver refer time ID"
// @Param filter_deliver_refer_date query string false "Filter by deliver refer date" Format(date)
// @Param filter_deliver_address_id query int false "Filter by deliver address ID"
// @Param page_number query int false "Page number"
// @Param page_size query int false "Page size"
// @Param sort_field query string false "Sort by field" Enums(id,benefactor_id,kind_box_type,count_requested,count_accepted,deliver_refer_time_id,deliver_refer_date,deliver_address_id)
// @Param sort_direction query string false "Sort order" Enums(asc,desc)
// @Success 200 {object} param.GetAllResponse
// @Failure 400 {string} "Bad request"
// @Security AuthBearerBenefactor
// @Router /benefactor/kindboxreqs/ [get]
func (h Handler) GetAll(c echo.Context) error {
var req param.GetAllRequest
if bErr := c.Bind(&req); bErr != nil {
return echo.NewHTTPError(http.StatusBadRequest)
}
req.Filter = queryparam.GetFilterParams(c)
if fieldErrors, err := h.benefactorKindBoxReqVld.ValidateGetAll(req); err != nil {
msg, code := httpmsg.Error(err)
return c.JSON(code, echo.Map{
"message": msg,
"errors": fieldErrors,
})
}
req.Filter["benefactor_id"] = claim.GetClaimsFromEchoContext(c).UserID
resp, sErr := h.benefactorKindBoxReqSvc.GetAll(c.Request().Context(), req)
if sErr != nil {
msg, code := httpmsg.Error(sErr)
return echo.NewHTTPError(code, msg)
}
return c.JSON(http.StatusOK, resp)
}

View File

@ -17,4 +17,5 @@ func (h Handler) SetRoutes(e *echo.Echo) {
r.POST("/", h.Add) r.POST("/", h.Add)
r.GET("/:id", h.Get) r.GET("/:id", h.Get)
r.DELETE("/:id", h.Delete) r.DELETE("/:id", h.Delete)
r.GET("/", h.GetAll)
} }

View File

@ -315,6 +315,49 @@ const docTemplate = `{
} }
} }
}, },
"/admin/kindboxes/{id}": {
"get": {
"security": [
{
"AuthBearerAdmin": []
}
],
"description": "This endpoint retrieves a specific kind box by admin",
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"KindBox"
],
"summary": "Get a specific kind box by admin",
"parameters": [
{
"type": "integer",
"description": "Kind box ID",
"name": "id",
"in": "path",
"required": true
}
],
"responses": {
"200": {
"description": "OK",
"schema": {
"$ref": "#/definitions/adminkindboxparam.KindBoxGetResponse"
}
},
"400": {
"description": "Bad request",
"schema": {
"type": "string"
}
}
}
}
},
"/admin/kindboxreqs": { "/admin/kindboxreqs": {
"get": { "get": {
"security": [ "security": [
@ -360,6 +403,48 @@ const docTemplate = `{
} }
} }
} }
},
"post": {
"security": [
{
"AuthBearerAdmin": []
}
],
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"KindBoxReq"
],
"summary": "Add a new kind box request for a benefactor by admin",
"parameters": [
{
"description": "New kind box request details",
"name": "Request",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/adminkindboxreqparam.KindBoxReqAddRequest"
}
}
],
"responses": {
"200": {
"description": "OK",
"schema": {
"$ref": "#/definitions/adminkindboxreqparam.KindBoxReqAddResponse"
}
},
"400": {
"description": "Bad request",
"schema": {
"type": "string"
}
}
}
} }
}, },
"/admin/kindboxreqs/accept-kind-box-req/{id}": { "/admin/kindboxreqs/accept-kind-box-req/{id}": {
@ -464,6 +549,135 @@ const docTemplate = `{
} }
} }
}, },
"/admin/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": [
"KindBoxReq"
],
"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": [
1,
2,
3
],
"type": "integer",
"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"
}
}
}
}
},
"/admin/kindboxreqs/awaiting-delivery/{id}": { "/admin/kindboxreqs/awaiting-delivery/{id}": {
"get": { "get": {
"security": [ "security": [
@ -715,7 +929,7 @@ const docTemplate = `{
} }
} }
}, },
"/benefactor/kindboxes/": { "/benefactor/kindboxes": {
"get": { "get": {
"security": [ "security": [
{ {
@ -791,7 +1005,198 @@ const docTemplate = `{
} }
} }
}, },
"/benefactor/kindboxes/{id}/emptying-requests": {
"patch": {
"security": [
{
"AuthBearerBenefactor": []
}
],
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"Benefactor"
],
"summary": "Register a new emptying request for a kind box by benefactor",
"parameters": [
{
"type": "integer",
"description": "KindBox ID",
"name": "id",
"in": "path",
"required": true
},
{
"description": "Request body",
"name": "Request",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/benefactorkindboxparam.KindBoxRegisterEmptyingRequest"
}
}
],
"responses": {
"204": {
"description": "No content",
"schema": {
"type": "string"
}
},
"400": {
"description": "Bad request",
"schema": {
"type": "string"
}
}
}
}
},
"/benefactor/kindboxreqs/": { "/benefactor/kindboxreqs/": {
"get": {
"security": [
{
"AuthBearerBenefactor": []
}
],
"description": "Retrieves a list of all KindBox requests with filtering, sorting, and pagination options",
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"KindBoxReq"
],
"summary": "Get all 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": [
1,
2,
3
],
"type": "integer",
"format": "enum",
"description": "Filter by KindBox type",
"name": "filter_kind_box_type",
"in": "query"
},
{
"enum": [
"pending",
"accepted",
"assigned-sender-agent",
"rejected",
"delivered"
],
"type": "string",
"description": "Filter by KindBoxReq Status",
"name": "filter_status",
"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/benefactorkindboxreqparam.GetAllResponse"
}
},
"400": {
"description": "Bad request",
"schema": {
"type": "string"
}
}
}
},
"post": { "post": {
"security": [ "security": [
{ {
@ -1115,6 +1520,59 @@ const docTemplate = `{
} }
} }
}, },
"adminkindboxparam.KindBoxGetResponse": {
"type": "object",
"properties": {
"amount": {
"type": "integer"
},
"benefactorID": {
"type": "integer"
},
"deliverAddressID": {
"type": "integer"
},
"deliverReferDate": {
"type": "string"
},
"deliveredAt": {
"type": "string"
},
"id": {
"type": "integer"
},
"kindBoxReqID": {
"type": "integer"
},
"kindBoxType": {
"$ref": "#/definitions/entity.KindBoxType"
},
"receiverAgentID": {
"type": "integer"
},
"returnAddressID": {
"type": "integer"
},
"returnReferDate": {
"type": "string"
},
"returnReferTimeID": {
"type": "integer"
},
"returnedAt": {
"type": "string"
},
"senderAgentID": {
"type": "integer"
},
"serialNumber": {
"type": "string"
},
"status": {
"$ref": "#/definitions/entity.KindBoxStatus"
}
}
},
"adminkindboxreqparam.AssignSenderRequest": { "adminkindboxreqparam.AssignSenderRequest": {
"type": "object", "type": "object",
"properties": { "properties": {
@ -1129,6 +1587,20 @@ const docTemplate = `{
"adminkindboxreqparam.DeliverKindBoxReqResponse": { "adminkindboxreqparam.DeliverKindBoxReqResponse": {
"type": "object" "type": "object"
}, },
"adminkindboxreqparam.DeliveryAwaitingGetAllResponse": {
"type": "object",
"properties": {
"all_awaiting_kind_box_req": {
"type": "array",
"items": {
"$ref": "#/definitions/entity.KindBoxReq"
}
},
"pagination": {
"$ref": "#/definitions/param.PaginationResponse"
}
}
},
"adminkindboxreqparam.DeliveryAwaitingGetResponse": { "adminkindboxreqparam.DeliveryAwaitingGetResponse": {
"type": "object", "type": "object",
"properties": { "properties": {
@ -1201,10 +1673,47 @@ const docTemplate = `{
} }
} }
}, },
"adminkindboxreqparam.KindBoxReqAddRequest": {
"type": "object",
"properties": {
"benefactor_id": {
"type": "integer",
"example": 1
},
"count_requested": {
"type": "integer",
"example": 2
},
"deliver_address_id": {
"type": "integer",
"example": 1
},
"deliver_refer_date": {
"type": "string",
"example": "2025-01-02 15:04:05"
},
"kind_box_type": {
"allOf": [
{
"$ref": "#/definitions/entity.KindBoxType"
}
],
"example": 1
}
}
},
"adminkindboxreqparam.KindBoxReqAddResponse": {
"type": "object",
"properties": {
"kindBoxReq": {
"$ref": "#/definitions/entity.KindBoxReq"
}
}
},
"adminkindboxreqparam.KindBoxReqGetAllResponse": { "adminkindboxreqparam.KindBoxReqGetAllResponse": {
"type": "object", "type": "object",
"properties": { "properties": {
"all_kind_box_req": { "all_awaiting_kind_box_req": {
"type": "array", "type": "array",
"items": { "items": {
"$ref": "#/definitions/entity.KindBoxReq" "$ref": "#/definitions/entity.KindBoxReq"
@ -1552,6 +2061,9 @@ const docTemplate = `{
"kindBoxReqID": { "kindBoxReqID": {
"type": "integer" "type": "integer"
}, },
"kindBoxType": {
"$ref": "#/definitions/entity.KindBoxType"
},
"receiverAgentID": { "receiverAgentID": {
"type": "integer" "type": "integer"
}, },
@ -1575,9 +2087,37 @@ const docTemplate = `{
}, },
"status": { "status": {
"$ref": "#/definitions/entity.KindBoxStatus" "$ref": "#/definitions/entity.KindBoxStatus"
}
}
},
"benefactorkindboxparam.KindBoxRegisterEmptyingRequest": {
"type": "object",
"properties": {
"return_address_id": {
"type": "integer",
"example": 1
}, },
"type": { "return_refer_date": {
"$ref": "#/definitions/entity.KindBoxType" "type": "string",
"example": "2025-01-02T15:04:05Z"
},
"return_refer_time_id": {
"type": "integer",
"example": 1
}
}
},
"benefactorkindboxreqparam.GetAllResponse": {
"type": "object",
"properties": {
"all_kind_box_req": {
"type": "array",
"items": {
"$ref": "#/definitions/entity.KindBoxReq"
}
},
"pagination": {
"$ref": "#/definitions/param.PaginationResponse"
} }
} }
}, },
@ -1604,7 +2144,7 @@ const docTemplate = `{
"type": "integer", "type": "integer",
"example": 1 "example": 1
}, },
"type_id": { "kind_box_type": {
"allOf": [ "allOf": [
{ {
"$ref": "#/definitions/entity.KindBoxType" "$ref": "#/definitions/entity.KindBoxType"

View File

@ -304,6 +304,49 @@
} }
} }
}, },
"/admin/kindboxes/{id}": {
"get": {
"security": [
{
"AuthBearerAdmin": []
}
],
"description": "This endpoint retrieves a specific kind box by admin",
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"KindBox"
],
"summary": "Get a specific kind box by admin",
"parameters": [
{
"type": "integer",
"description": "Kind box ID",
"name": "id",
"in": "path",
"required": true
}
],
"responses": {
"200": {
"description": "OK",
"schema": {
"$ref": "#/definitions/adminkindboxparam.KindBoxGetResponse"
}
},
"400": {
"description": "Bad request",
"schema": {
"type": "string"
}
}
}
}
},
"/admin/kindboxreqs": { "/admin/kindboxreqs": {
"get": { "get": {
"security": [ "security": [
@ -349,6 +392,48 @@
} }
} }
} }
},
"post": {
"security": [
{
"AuthBearerAdmin": []
}
],
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"KindBoxReq"
],
"summary": "Add a new kind box request for a benefactor by admin",
"parameters": [
{
"description": "New kind box request details",
"name": "Request",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/adminkindboxreqparam.KindBoxReqAddRequest"
}
}
],
"responses": {
"200": {
"description": "OK",
"schema": {
"$ref": "#/definitions/adminkindboxreqparam.KindBoxReqAddResponse"
}
},
"400": {
"description": "Bad request",
"schema": {
"type": "string"
}
}
}
} }
}, },
"/admin/kindboxreqs/accept-kind-box-req/{id}": { "/admin/kindboxreqs/accept-kind-box-req/{id}": {
@ -453,6 +538,135 @@
} }
} }
}, },
"/admin/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": [
"KindBoxReq"
],
"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": [
1,
2,
3
],
"type": "integer",
"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"
}
}
}
}
},
"/admin/kindboxreqs/awaiting-delivery/{id}": { "/admin/kindboxreqs/awaiting-delivery/{id}": {
"get": { "get": {
"security": [ "security": [
@ -704,7 +918,7 @@
} }
} }
}, },
"/benefactor/kindboxes/": { "/benefactor/kindboxes": {
"get": { "get": {
"security": [ "security": [
{ {
@ -780,7 +994,198 @@
} }
} }
}, },
"/benefactor/kindboxes/{id}/emptying-requests": {
"patch": {
"security": [
{
"AuthBearerBenefactor": []
}
],
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"Benefactor"
],
"summary": "Register a new emptying request for a kind box by benefactor",
"parameters": [
{
"type": "integer",
"description": "KindBox ID",
"name": "id",
"in": "path",
"required": true
},
{
"description": "Request body",
"name": "Request",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/benefactorkindboxparam.KindBoxRegisterEmptyingRequest"
}
}
],
"responses": {
"204": {
"description": "No content",
"schema": {
"type": "string"
}
},
"400": {
"description": "Bad request",
"schema": {
"type": "string"
}
}
}
}
},
"/benefactor/kindboxreqs/": { "/benefactor/kindboxreqs/": {
"get": {
"security": [
{
"AuthBearerBenefactor": []
}
],
"description": "Retrieves a list of all KindBox requests with filtering, sorting, and pagination options",
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"KindBoxReq"
],
"summary": "Get all 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": [
1,
2,
3
],
"type": "integer",
"format": "enum",
"description": "Filter by KindBox type",
"name": "filter_kind_box_type",
"in": "query"
},
{
"enum": [
"pending",
"accepted",
"assigned-sender-agent",
"rejected",
"delivered"
],
"type": "string",
"description": "Filter by KindBoxReq Status",
"name": "filter_status",
"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/benefactorkindboxreqparam.GetAllResponse"
}
},
"400": {
"description": "Bad request",
"schema": {
"type": "string"
}
}
}
},
"post": { "post": {
"security": [ "security": [
{ {
@ -1104,6 +1509,59 @@
} }
} }
}, },
"adminkindboxparam.KindBoxGetResponse": {
"type": "object",
"properties": {
"amount": {
"type": "integer"
},
"benefactorID": {
"type": "integer"
},
"deliverAddressID": {
"type": "integer"
},
"deliverReferDate": {
"type": "string"
},
"deliveredAt": {
"type": "string"
},
"id": {
"type": "integer"
},
"kindBoxReqID": {
"type": "integer"
},
"kindBoxType": {
"$ref": "#/definitions/entity.KindBoxType"
},
"receiverAgentID": {
"type": "integer"
},
"returnAddressID": {
"type": "integer"
},
"returnReferDate": {
"type": "string"
},
"returnReferTimeID": {
"type": "integer"
},
"returnedAt": {
"type": "string"
},
"senderAgentID": {
"type": "integer"
},
"serialNumber": {
"type": "string"
},
"status": {
"$ref": "#/definitions/entity.KindBoxStatus"
}
}
},
"adminkindboxreqparam.AssignSenderRequest": { "adminkindboxreqparam.AssignSenderRequest": {
"type": "object", "type": "object",
"properties": { "properties": {
@ -1118,6 +1576,20 @@
"adminkindboxreqparam.DeliverKindBoxReqResponse": { "adminkindboxreqparam.DeliverKindBoxReqResponse": {
"type": "object" "type": "object"
}, },
"adminkindboxreqparam.DeliveryAwaitingGetAllResponse": {
"type": "object",
"properties": {
"all_awaiting_kind_box_req": {
"type": "array",
"items": {
"$ref": "#/definitions/entity.KindBoxReq"
}
},
"pagination": {
"$ref": "#/definitions/param.PaginationResponse"
}
}
},
"adminkindboxreqparam.DeliveryAwaitingGetResponse": { "adminkindboxreqparam.DeliveryAwaitingGetResponse": {
"type": "object", "type": "object",
"properties": { "properties": {
@ -1190,10 +1662,47 @@
} }
} }
}, },
"adminkindboxreqparam.KindBoxReqAddRequest": {
"type": "object",
"properties": {
"benefactor_id": {
"type": "integer",
"example": 1
},
"count_requested": {
"type": "integer",
"example": 2
},
"deliver_address_id": {
"type": "integer",
"example": 1
},
"deliver_refer_date": {
"type": "string",
"example": "2025-01-02 15:04:05"
},
"kind_box_type": {
"allOf": [
{
"$ref": "#/definitions/entity.KindBoxType"
}
],
"example": 1
}
}
},
"adminkindboxreqparam.KindBoxReqAddResponse": {
"type": "object",
"properties": {
"kindBoxReq": {
"$ref": "#/definitions/entity.KindBoxReq"
}
}
},
"adminkindboxreqparam.KindBoxReqGetAllResponse": { "adminkindboxreqparam.KindBoxReqGetAllResponse": {
"type": "object", "type": "object",
"properties": { "properties": {
"all_kind_box_req": { "all_awaiting_kind_box_req": {
"type": "array", "type": "array",
"items": { "items": {
"$ref": "#/definitions/entity.KindBoxReq" "$ref": "#/definitions/entity.KindBoxReq"
@ -1541,6 +2050,9 @@
"kindBoxReqID": { "kindBoxReqID": {
"type": "integer" "type": "integer"
}, },
"kindBoxType": {
"$ref": "#/definitions/entity.KindBoxType"
},
"receiverAgentID": { "receiverAgentID": {
"type": "integer" "type": "integer"
}, },
@ -1564,9 +2076,37 @@
}, },
"status": { "status": {
"$ref": "#/definitions/entity.KindBoxStatus" "$ref": "#/definitions/entity.KindBoxStatus"
}
}
},
"benefactorkindboxparam.KindBoxRegisterEmptyingRequest": {
"type": "object",
"properties": {
"return_address_id": {
"type": "integer",
"example": 1
}, },
"type": { "return_refer_date": {
"$ref": "#/definitions/entity.KindBoxType" "type": "string",
"example": "2025-01-02T15:04:05Z"
},
"return_refer_time_id": {
"type": "integer",
"example": 1
}
}
},
"benefactorkindboxreqparam.GetAllResponse": {
"type": "object",
"properties": {
"all_kind_box_req": {
"type": "array",
"items": {
"$ref": "#/definitions/entity.KindBoxReq"
}
},
"pagination": {
"$ref": "#/definitions/param.PaginationResponse"
} }
} }
}, },
@ -1593,7 +2133,7 @@
"type": "integer", "type": "integer",
"example": 1 "example": 1
}, },
"type_id": { "kind_box_type": {
"allOf": [ "allOf": [
{ {
"$ref": "#/definitions/entity.KindBoxType" "$ref": "#/definitions/entity.KindBoxType"

View File

@ -77,6 +77,41 @@ definitions:
receiver_agent_id: receiver_agent_id:
type: integer type: integer
type: object type: object
adminkindboxparam.KindBoxGetResponse:
properties:
amount:
type: integer
benefactorID:
type: integer
deliverAddressID:
type: integer
deliverReferDate:
type: string
deliveredAt:
type: string
id:
type: integer
kindBoxReqID:
type: integer
kindBoxType:
$ref: '#/definitions/entity.KindBoxType'
receiverAgentID:
type: integer
returnAddressID:
type: integer
returnReferDate:
type: string
returnReferTimeID:
type: integer
returnedAt:
type: string
senderAgentID:
type: integer
serialNumber:
type: string
status:
$ref: '#/definitions/entity.KindBoxStatus'
type: object
adminkindboxreqparam.AssignSenderRequest: adminkindboxreqparam.AssignSenderRequest:
properties: properties:
sender_agent_id: sender_agent_id:
@ -86,6 +121,15 @@ definitions:
type: object type: object
adminkindboxreqparam.DeliverKindBoxReqResponse: adminkindboxreqparam.DeliverKindBoxReqResponse:
type: object type: object
adminkindboxreqparam.DeliveryAwaitingGetAllResponse:
properties:
all_awaiting_kind_box_req:
items:
$ref: '#/definitions/entity.KindBoxReq'
type: array
pagination:
$ref: '#/definitions/param.PaginationResponse'
type: object
adminkindboxreqparam.DeliveryAwaitingGetResponse: adminkindboxreqparam.DeliveryAwaitingGetResponse:
properties: properties:
benefactorID: benefactorID:
@ -133,9 +177,33 @@ definitions:
kind_box_req_status: kind_box_req_status:
$ref: '#/definitions/entity.KindBoxReqStatus' $ref: '#/definitions/entity.KindBoxReqStatus'
type: object type: object
adminkindboxreqparam.KindBoxReqAddRequest:
properties:
benefactor_id:
example: 1
type: integer
count_requested:
example: 2
type: integer
deliver_address_id:
example: 1
type: integer
deliver_refer_date:
example: "2025-01-02 15:04:05"
type: string
kind_box_type:
allOf:
- $ref: '#/definitions/entity.KindBoxType'
example: 1
type: object
adminkindboxreqparam.KindBoxReqAddResponse:
properties:
kindBoxReq:
$ref: '#/definitions/entity.KindBoxReq'
type: object
adminkindboxreqparam.KindBoxReqGetAllResponse: adminkindboxreqparam.KindBoxReqGetAllResponse:
properties: properties:
all_kind_box_req: all_awaiting_kind_box_req:
items: items:
$ref: '#/definitions/entity.KindBoxReq' $ref: '#/definitions/entity.KindBoxReq'
type: array type: array
@ -362,6 +430,8 @@ definitions:
type: integer type: integer
kindBoxReqID: kindBoxReqID:
type: integer type: integer
kindBoxType:
$ref: '#/definitions/entity.KindBoxType'
receiverAgentID: receiverAgentID:
type: integer type: integer
returnAddressID: returnAddressID:
@ -378,8 +448,27 @@ definitions:
type: string type: string
status: status:
$ref: '#/definitions/entity.KindBoxStatus' $ref: '#/definitions/entity.KindBoxStatus'
type: type: object
$ref: '#/definitions/entity.KindBoxType' benefactorkindboxparam.KindBoxRegisterEmptyingRequest:
properties:
return_address_id:
example: 1
type: integer
return_refer_date:
example: "2025-01-02T15:04:05Z"
type: string
return_refer_time_id:
example: 1
type: integer
type: object
benefactorkindboxreqparam.GetAllResponse:
properties:
all_kind_box_req:
items:
$ref: '#/definitions/entity.KindBoxReq'
type: array
pagination:
$ref: '#/definitions/param.PaginationResponse'
type: object type: object
benefactorkindboxreqparam.KindBoxReqAddRequest: benefactorkindboxreqparam.KindBoxReqAddRequest:
properties: properties:
@ -398,7 +487,7 @@ definitions:
deliver_refer_time_id: deliver_refer_time_id:
example: 1 example: 1
type: integer type: integer
type_id: kind_box_type:
allOf: allOf:
- $ref: '#/definitions/entity.KindBoxType' - $ref: '#/definitions/entity.KindBoxType'
example: 1 example: 1
@ -740,6 +829,33 @@ paths:
summary: Get all provinces summary: Get all provinces
tags: tags:
- Address - Address
/admin/kindboxes/{id}:
get:
consumes:
- application/json
description: This endpoint retrieves a specific kind box by admin
parameters:
- description: Kind box ID
in: path
name: id
required: true
type: integer
produces:
- application/json
responses:
"200":
description: OK
schema:
$ref: '#/definitions/adminkindboxparam.KindBoxGetResponse'
"400":
description: Bad request
schema:
type: string
security:
- AuthBearerAdmin: []
summary: Get a specific kind box by admin
tags:
- KindBox
/admin/kindboxes/assign-receiver-agent/{id}: /admin/kindboxes/assign-receiver-agent/{id}:
patch: patch:
consumes: consumes:
@ -799,6 +915,32 @@ paths:
summary: Admin get all kindboxreq summary: Admin get all kindboxreq
tags: tags:
- KindBoxReq - KindBoxReq
post:
consumes:
- application/json
parameters:
- description: New kind box request details
in: body
name: Request
required: true
schema:
$ref: '#/definitions/adminkindboxreqparam.KindBoxReqAddRequest'
produces:
- application/json
responses:
"200":
description: OK
schema:
$ref: '#/definitions/adminkindboxreqparam.KindBoxReqAddResponse'
"400":
description: Bad request
schema:
type: string
security:
- AuthBearerAdmin: []
summary: Add a new kind box request for a benefactor by admin
tags:
- KindBoxReq
/admin/kindboxreqs/accept-kind-box-req/{id}: /admin/kindboxreqs/accept-kind-box-req/{id}:
patch: patch:
consumes: consumes:
@ -863,6 +1005,95 @@ paths:
summary: Admin Assign Sender Agent to kindboxreq summary: Admin Assign Sender Agent to kindboxreq
tags: tags:
- KindBoxReq - KindBoxReq
/admin/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:
- 1
- 2
- 3
format: enum
in: query
name: filter_kind_box_type
type: integer
- 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:
- KindBoxReq
/admin/kindboxreqs/awaiting-delivery/{id}: /admin/kindboxreqs/awaiting-delivery/{id}:
get: get:
consumes: consumes:
@ -1019,7 +1250,7 @@ paths:
summary: Register an admin by super-admin summary: Register an admin by super-admin
tags: tags:
- Admin - Admin
/benefactor/kindboxes/: /benefactor/kindboxes:
get: get:
consumes: consumes:
- application/json - application/json
@ -1067,7 +1298,137 @@ paths:
summary: Get a specific kind box for a benefactor summary: Get a specific kind box for a benefactor
tags: tags:
- KindBox - KindBox
/benefactor/kindboxes/{id}/emptying-requests:
patch:
consumes:
- application/json
parameters:
- description: KindBox ID
in: path
name: id
required: true
type: integer
- description: Request body
in: body
name: Request
required: true
schema:
$ref: '#/definitions/benefactorkindboxparam.KindBoxRegisterEmptyingRequest'
produces:
- application/json
responses:
"204":
description: No content
schema:
type: string
"400":
description: Bad request
schema:
type: string
security:
- AuthBearerBenefactor: []
summary: Register a new emptying request for a kind box by benefactor
tags:
- Benefactor
/benefactor/kindboxreqs/: /benefactor/kindboxreqs/:
get:
consumes:
- application/json
description: Retrieves a list of all 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:
- 1
- 2
- 3
format: enum
in: query
name: filter_kind_box_type
type: integer
- description: Filter by KindBoxReq Status
enum:
- pending
- accepted
- assigned-sender-agent
- rejected
- delivered
in: query
name: filter_status
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/benefactorkindboxreqparam.GetAllResponse'
"400":
description: Bad request
schema:
type: string
security:
- AuthBearerBenefactor: []
summary: Get all KindBox requests
tags:
- KindBoxReq
post: post:
consumes: consumes:
- application/json - application/json

View File

@ -6,7 +6,7 @@ type KindBox struct {
ID uint ID uint
KindBoxReqID uint KindBoxReqID uint
BenefactorID uint BenefactorID uint
Type KindBoxType KindBoxType KindBoxType
Amount uint Amount uint
SerialNumber string SerialNumber string
Status KindBoxStatus Status KindBoxStatus

View File

@ -4,7 +4,7 @@ import entity "git.gocasts.ir/ebhomengo/niki/entity"
type KindBoxReqAddRequest struct { type KindBoxReqAddRequest struct {
BenefactorID uint `json:"benefactor_id" example:"1"` BenefactorID uint `json:"benefactor_id" example:"1"`
TypeID entity.KindBoxType `json:"type_id" example:"1"` KindBoxType entity.KindBoxType `json:"kind_box_type" example:"1"`
DeliverAddressID uint `json:"deliver_address_id" example:"1"` DeliverAddressID uint `json:"deliver_address_id" example:"1"`
DeliverReferDate string `json:"deliver_refer_date" example:"2025-01-02 15:04:05"` DeliverReferDate string `json:"deliver_refer_date" example:"2025-01-02 15:04:05"`
CountRequested uint `json:"count_requested" example:"2"` CountRequested uint `json:"count_requested" example:"2"`

View File

@ -3,9 +3,9 @@ package adminkindboxreqparam
import entity "git.gocasts.ir/ebhomengo/niki/entity" import entity "git.gocasts.ir/ebhomengo/niki/entity"
type KindBoxReqUpdateRequest struct { type KindBoxReqUpdateRequest struct {
BenefactorID uint BenefactorID uint
KindBoxReqID uint KindBoxReqID uint
TypeID uint uint
CountRequested uint CountRequested uint
} }

View File

@ -7,7 +7,7 @@ import (
type KindBoxReqAddRequest struct { type KindBoxReqAddRequest struct {
BenefactorID uint `json:"benefactor_id" example:"1"` BenefactorID uint `json:"benefactor_id" example:"1"`
TypeID entity.KindBoxType `json:"type_id" example:"1"` KindBoxType entity.KindBoxType `json:"kind_box_type" example:"1"`
DeliverAddressID uint `json:"deliver_address_id" example:"1"` DeliverAddressID uint `json:"deliver_address_id" example:"1"`
DeliverReferDate time.Time `json:"deliver_refer_date" example:"2025-01-02T15:04:05Z"` DeliverReferDate time.Time `json:"deliver_refer_date" example:"2025-01-02T15:04:05Z"`
DeliverReferTimeID uint `json:"deliver_refer_time_id" example:"1"` DeliverReferTimeID uint `json:"deliver_refer_time_id" example:"1"`

View File

@ -1,11 +1,17 @@
package benefactorkindboxreqparam package benefactorkindboxreqparam
import entity "git.gocasts.ir/ebhomengo/niki/entity" import (
"git.gocasts.ir/ebhomengo/niki/entity"
"git.gocasts.ir/ebhomengo/niki/param"
)
type KindBoxReqGetAllRequest struct { type GetAllRequest struct {
BenefactorID uint Pagination param.PaginationRequest
Sort param.SortRequest
Filter param.FilterRequest
} }
type KindBoxReqGetAllResponse struct { type GetAllResponse struct {
AllKindBoxReq []entity.KindBoxReq `json:"all_kind_box_req"` AllKindBoxReq []entity.KindBoxReq `json:"all_kind_box_req"`
Pagination param.PaginationResponse `json:"pagination"`
} }

View File

@ -5,7 +5,7 @@ import entity "git.gocasts.ir/ebhomengo/niki/entity"
type KindBoxReqUpdateRequest struct { type KindBoxReqUpdateRequest struct {
BenefactorID uint BenefactorID uint
KindBoxReqID uint KindBoxReqID uint
TypeID entity.KindBoxType KindBoxType entity.KindBoxType
CountRequested uint CountRequested uint
} }

View File

@ -12,7 +12,7 @@ func (d DB) AddKindBox(ctx context.Context, kindBox entity.KindBox) error {
const op = "mysqlkindbox.AddKindBox" const op = "mysqlkindbox.AddKindBox"
_, err := d.conn.Conn().ExecContext(ctx, `insert into kind_boxes(kind_box_req_id,benefactor_id,type,status,sender_agent_id) values (?,?,?,?,?)`, _, err := d.conn.Conn().ExecContext(ctx, `insert into kind_boxes(kind_box_req_id,benefactor_id,type,status,sender_agent_id) values (?,?,?,?,?)`,
kindBox.KindBoxReqID, kindBox.BenefactorID, kindBox.Type, entity.KindBoxDeliveredStatus.String(), kindBox.SenderAgentID) kindBox.KindBoxReqID, kindBox.BenefactorID, kindBox.KindBoxType, entity.KindBoxDeliveredStatus.String(), kindBox.SenderAgentID)
if err != nil { if err != nil {
return richerror.New(op).WithErr(err). return richerror.New(op).WithErr(err).
WithMessage(errmsg.ErrorMsgNotFound).WithKind(richerror.KindUnexpected) WithMessage(errmsg.ErrorMsgNotFound).WithKind(richerror.KindUnexpected)
@ -29,7 +29,7 @@ func (d DB) AddBatchKindBox(ctx context.Context, kindBoxes []entity.KindBox) err
for _, kb := range kindBoxes { for _, kb := range kindBoxes {
queryStr += "(?, ?, ?, ?, ?, ?, ?, ?)," queryStr += "(?, ?, ?, ?, ?, ?, ?, ?),"
values = append(values, kb.KindBoxReqID, kb.BenefactorID, kb.Type, kb.Status.String(), kb.DeliverReferDate, kb.DeliverAddressID, kb.SenderAgentID, kb.DeliveredAt) values = append(values, kb.KindBoxReqID, kb.BenefactorID, kb.KindBoxType, kb.Status.String(), kb.DeliverReferDate, kb.DeliverAddressID, kb.SenderAgentID, kb.DeliveredAt)
} }
// trim the last , // trim the last ,

View File

@ -52,7 +52,7 @@ func scanKindBox(scanner mysql.Scanner) (entity.KindBox, error) {
return entity.KindBox{}, err return entity.KindBox{}, err
} }
kindBox.Type = entity.MapToKindBoxType(kindBoxType) kindBox.KindBoxType = entity.MapToKindBoxType(kindBoxType)
if amount.Valid { if amount.Valid {
kindBox.Amount = uint(amount.Int64) kindBox.Amount = uint(amount.Int64)
} }

View File

@ -2,7 +2,6 @@ package mysqlkindboxreq
import ( import (
"context" "context"
"git.gocasts.ir/ebhomengo/niki/entity" "git.gocasts.ir/ebhomengo/niki/entity"
errmsg "git.gocasts.ir/ebhomengo/niki/pkg/err_msg" errmsg "git.gocasts.ir/ebhomengo/niki/pkg/err_msg"
richerror "git.gocasts.ir/ebhomengo/niki/pkg/rich_error" richerror "git.gocasts.ir/ebhomengo/niki/pkg/rich_error"
@ -11,8 +10,8 @@ import (
func (d DB) AddKindBoxReq(ctx context.Context, kindBoxReq entity.KindBoxReq) (entity.KindBoxReq, error) { func (d DB) AddKindBoxReq(ctx context.Context, kindBoxReq entity.KindBoxReq) (entity.KindBoxReq, error) {
const op = "mysqlkindboxreq.AddKindBoxReq" const op = "mysqlkindboxreq.AddKindBoxReq"
res, err := d.conn.Conn().ExecContext(ctx, `insert into kind_box_reqs(benefactor_id,kind_box_type,deliver_address_id,count_requested,deliver_refer_date,status) values (?,?,?,?,?,?)`, res, err := d.conn.Conn().ExecContext(ctx, `insert into kind_box_reqs(benefactor_id,kind_box_type,deliver_address_id,count_requested,deliver_refer_date,deliver_refer_time_id,status) values (?,?,?,?,?,?,?)`,
kindBoxReq.BenefactorID, kindBoxReq.KindBoxType.String(), kindBoxReq.DeliverAddressID, kindBoxReq.CountRequested, kindBoxReq.DeliverReferDate, kindBoxReq.Status.String()) kindBoxReq.BenefactorID, kindBoxReq.KindBoxType.String(), kindBoxReq.DeliverAddressID, kindBoxReq.CountRequested, kindBoxReq.DeliverReferDate, kindBoxReq.DeliverReferTimeID, kindBoxReq.Status.String())
if err != nil { if err != nil {
return entity.KindBoxReq{}, richerror.New(op).WithErr(err). return entity.KindBoxReq{}, richerror.New(op).WithErr(err).
WithMessage(errmsg.ErrorMsgNotFound).WithKind(richerror.KindUnexpected) WithMessage(errmsg.ErrorMsgNotFound).WithKind(richerror.KindUnexpected)

View File

@ -40,6 +40,7 @@ func scanKindBoxReq(scanner mysql.Scanner) (entity.KindBoxReq, error) {
&deletedAt, &deletedAt,
) )
if err != nil { if err != nil {
return entity.KindBoxReq{}, err return entity.KindBoxReq{}, err
} }

View File

@ -10,7 +10,7 @@ ALTER TABLE `admin_access_controls` MODIFY COLUMN `permission`
'admin-getall_agent', 'admin-getall_agent',
'kindboxreq-get_awaiting_delivery', 'kindboxreq-get_awaiting_delivery',
'kindbox-get', 'kindbox-get',
'kindbox-assign_receiver_agent' 'kindboxreq-add'
) NOT NULL; ) NOT NULL;
-- +migrate Down -- +migrate Down

View File

@ -1,15 +0,0 @@
-- +migrate Up
ALTER TABLE `admin_access_controls` MODIFY COLUMN `permission`
enum (
'admin-register',
'kindboxreq-accept',
'kindboxreq-reject',
'kindboxreq-getall',
'kindboxreq-deliver',
'kindboxreq-assign_sender_agent',
'admin-getall_agent',
'kindboxreq-get_awaiting_delivery',
'kindboxreq-add'
) NOT NULL;
-- +migrate Down

View File

@ -14,7 +14,7 @@ func (s Service) AddBatchKindBox(ctx context.Context, req param.AddKindBoxReques
kb := entity.KindBox{ kb := entity.KindBox{
KindBoxReqID: req.KindBoxReqID, KindBoxReqID: req.KindBoxReqID,
BenefactorID: req.BenefactorID, BenefactorID: req.BenefactorID,
Type: req.Type, KindBoxType: req.Type,
DeliverReferDate: req.DeliverReferDate, DeliverReferDate: req.DeliverReferDate,
DeliverAddressID: req.DeliverAddressID, DeliverAddressID: req.DeliverAddressID,
DeliveredAt: req.DeliveredAt, DeliveredAt: req.DeliveredAt,

View File

@ -17,7 +17,7 @@ func (s Service) Add(ctx context.Context, req param.KindBoxReqAddRequest) (param
} }
kindBoxReq, err := s.repo.AddKindBoxReq(ctx, entity.KindBoxReq{ kindBoxReq, err := s.repo.AddKindBoxReq(ctx, entity.KindBoxReq{
BenefactorID: req.BenefactorID, BenefactorID: req.BenefactorID,
KindBoxType: req.TypeID, KindBoxType: req.KindBoxType,
DeliverAddressID: req.DeliverAddressID, DeliverAddressID: req.DeliverAddressID,
DeliverReferDate: date, DeliverReferDate: date,
CountRequested: req.CountRequested, CountRequested: req.CountRequested,

View File

@ -12,7 +12,7 @@ func (s Service) Add(ctx context.Context, req param.KindBoxReqAddRequest) (param
kindBoxReq, err := s.repo.AddKindBoxReq(ctx, entity.KindBoxReq{ kindBoxReq, err := s.repo.AddKindBoxReq(ctx, entity.KindBoxReq{
BenefactorID: req.BenefactorID, BenefactorID: req.BenefactorID,
KindBoxType: req.TypeID, KindBoxType: req.KindBoxType,
DeliverAddressID: req.DeliverAddressID, DeliverAddressID: req.DeliverAddressID,
DeliverReferDate: req.DeliverReferDate, DeliverReferDate: req.DeliverReferDate,
DeliverReferTimeID: req.DeliverReferTimeID, DeliverReferTimeID: req.DeliverReferTimeID,

View File

@ -29,7 +29,7 @@ func TestAdd(t *testing.T) {
AddressID: 1, AddressID: 1,
ReferDate: time.Now(), ReferDate: time.Now(),
CountRequested: 1, CountRequested: 1,
TypeID: 1, KindBoxType: 1,
}, },
}, },
{ {
@ -39,7 +39,7 @@ func TestAdd(t *testing.T) {
AddressID: 1, AddressID: 1,
ReferDate: time.Now(), ReferDate: time.Now(),
CountRequested: 1, CountRequested: 1,
TypeID: 1, KindBoxType: 1,
}, },
}, },
} }

View File

@ -0,0 +1,27 @@
package benefactorkindboxreqservice
import (
"context"
paginationparam "git.gocasts.ir/ebhomengo/niki/param"
param "git.gocasts.ir/ebhomengo/niki/param/benefactor/kind_box_req"
richerror "git.gocasts.ir/ebhomengo/niki/pkg/rich_error"
)
func (s Service) GetAll(ctx context.Context, req param.GetAllRequest) (param.GetAllResponse, error) {
const op = "adminkindboxreqservice.GetAllAwaitingDelivery"
allKindBoxReq, total, err := s.repo.GetAllKindBoxReq(ctx, req.Filter, req.Pagination, req.Sort)
if err != nil {
return param.GetAllResponse{}, richerror.New(op).WithErr(err)
}
return param.GetAllResponse{
AllKindBoxReq: allKindBoxReq,
Pagination: paginationparam.PaginationResponse{
PageSize: req.Pagination.GetPageSize(),
PageNumber: req.Pagination.GetPageNumber(),
Total: total,
},
}, nil
}

View File

@ -2,6 +2,7 @@ package benefactorkindboxreqservice
import ( import (
"context" "context"
params "git.gocasts.ir/ebhomengo/niki/param"
entity "git.gocasts.ir/ebhomengo/niki/entity" entity "git.gocasts.ir/ebhomengo/niki/entity"
) )
@ -10,6 +11,7 @@ type Repository interface {
AddKindBoxReq(ctx context.Context, kindBoxReq entity.KindBoxReq) (entity.KindBoxReq, error) AddKindBoxReq(ctx context.Context, kindBoxReq entity.KindBoxReq) (entity.KindBoxReq, error)
GetKindBoxReqByID(ctx context.Context, kindBoxReqID uint) (entity.KindBoxReq, error) GetKindBoxReqByID(ctx context.Context, kindBoxReqID uint) (entity.KindBoxReq, error)
DeleteKindBoxReqByID(ctx context.Context, kindBoxReqID uint) error DeleteKindBoxReqByID(ctx context.Context, kindBoxReqID uint) error
GetAllKindBoxReq(ctx context.Context, filter params.FilterRequest, pagination params.PaginationRequest, sort params.SortRequest) ([]entity.KindBoxReq, uint, error)
} }
type Service struct { type Service struct {

View File

@ -12,7 +12,7 @@ const RepoErr = "record not found"
type DefaultKindBoxReqTest struct { type DefaultKindBoxReqTest struct {
BenefactorID uint BenefactorID uint
TypeID entity.KindBoxType KindBoxType entity.KindBoxType
AddressID uint AddressID uint
ReferDate time.Time ReferDate time.Time
CountRequested uint CountRequested uint
@ -21,7 +21,7 @@ type DefaultKindBoxReqTest struct {
func DefaultKindBoxReq() DefaultKindBoxReqTest { func DefaultKindBoxReq() DefaultKindBoxReqTest {
return DefaultKindBoxReqTest{ return DefaultKindBoxReqTest{
BenefactorID: 1, BenefactorID: 1,
TypeID: 1, KindBoxType: 1,
AddressID: 1, AddressID: 1,
ReferDate: time.Now(), ReferDate: time.Now(),
CountRequested: 1, CountRequested: 1,
@ -40,7 +40,7 @@ func NewMockRepository(hasErr bool) *MockRepository {
kindBoxReqs = append(kindBoxReqs, entity.KindBoxReq{ kindBoxReqs = append(kindBoxReqs, entity.KindBoxReq{
BenefactorID: DefaultKindBoxReq.BenefactorID, BenefactorID: DefaultKindBoxReq.BenefactorID,
AddressID: DefaultKindBoxReq.AddressID, AddressID: DefaultKindBoxReq.AddressID,
KindBoxType: DefaultKindBoxReq.TypeID, KindBoxType: DefaultKindBoxReq.KindBoxType,
ReferDate: DefaultKindBoxReq.ReferDate, ReferDate: DefaultKindBoxReq.ReferDate,
CountRequested: DefaultKindBoxReq.CountRequested, CountRequested: DefaultKindBoxReq.CountRequested,
Status: entity.KindBoxReqPendingStatus, Status: entity.KindBoxReqPendingStatus,

View File

@ -25,7 +25,7 @@ func (v Validator) ValidateAddRequest(req param.KindBoxReqAddRequest) *Validator
validation.Required, validation.Required,
validation.By(v.doesBenefactorExist)), validation.By(v.doesBenefactorExist)),
validation.Field(&req.TypeID, validation.Field(&req.KindBoxType,
validation.Required, validation.Required,
validation.By(v.doesTypeExist)), validation.By(v.doesTypeExist)),
@ -78,11 +78,11 @@ func (v Validator) doesBenefactorExist(value interface{}) error {
} }
func (v Validator) doesTypeExist(value interface{}) error { func (v Validator) doesTypeExist(value interface{}) error {
typeID, ok := value.(entity.KindBoxType) KindBoxType, ok := value.(entity.KindBoxType)
if !ok { if !ok {
return fmt.Errorf(errmsg.ErrorMsgSomethingWentWrong) return fmt.Errorf(errmsg.ErrorMsgSomethingWentWrong)
} }
if !typeID.IsValid() { if !KindBoxType.IsValid() {
return fmt.Errorf(errmsg.ErrorMsgNotFound) return fmt.Errorf(errmsg.ErrorMsgNotFound)
} }

View File

@ -20,7 +20,7 @@ func (v Validator) ValidateAddRequest(req param.KindBoxReqAddRequest) (map[strin
validation.Required, validation.Required,
validation.By(v.doesBenefactorExist)), validation.By(v.doesBenefactorExist)),
validation.Field(&req.TypeID, validation.Field(&req.KindBoxType,
validation.Required, validation.Required,
validation.By(v.doesTypeExist)), validation.By(v.doesTypeExist)),

View File

@ -99,7 +99,7 @@ func TestValidateAddRequest(t *testing.T) {
params: benefactorkindboxreqparam.KindBoxReqAddRequest{ params: benefactorkindboxreqparam.KindBoxReqAddRequest{
AddressID: 1, AddressID: 1,
BenefactorID: 1, BenefactorID: 1,
TypeID: 1, KindBoxType: 1,
CountRequested: 2, CountRequested: 2,
ReferDate: time.Now(), ReferDate: time.Now(),
}, },
@ -111,7 +111,7 @@ func TestValidateAddRequest(t *testing.T) {
params: benefactorkindboxreqparam.KindBoxReqAddRequest{ params: benefactorkindboxreqparam.KindBoxReqAddRequest{
AddressID: 1, AddressID: 1,
BenefactorID: 1, BenefactorID: 1,
TypeID: 1, KindBoxType: 1,
CountRequested: 1, CountRequested: 1,
ReferDate: time.Now(), ReferDate: time.Now(),
}, },
@ -122,29 +122,29 @@ func TestValidateAddRequest(t *testing.T) {
params: benefactorkindboxreqparam.KindBoxReqAddRequest{ params: benefactorkindboxreqparam.KindBoxReqAddRequest{
AddressID: 1, AddressID: 1,
BenefactorID: 1, BenefactorID: 1,
TypeID: 1, KindBoxType: 1,
CountRequested: 0, CountRequested: 0,
ReferDate: time.Now(), ReferDate: time.Now(),
}, },
}, },
{ {
name: "TypeID cannot be empty", name: "KindBoxType cannot be empty",
error: fmt.Errorf(fmt.Sprintf("type_id: cannot be blank\n")), error: fmt.Errorf(fmt.Sprintf("kind_box_type: cannot be blank\n")),
params: benefactorkindboxreqparam.KindBoxReqAddRequest{ params: benefactorkindboxreqparam.KindBoxReqAddRequest{
AddressID: 1, AddressID: 1,
BenefactorID: 1, BenefactorID: 1,
TypeID: 0, KindBoxType: 0,
CountRequested: 1, CountRequested: 1,
ReferDate: time.Now(), ReferDate: time.Now(),
}, },
}, },
{ {
name: "type with ID does exists", name: "type with ID does exists",
error: fmt.Errorf(fmt.Sprintf("type_id: %s\n", errmsg.ErrorMsgNotFound)), error: fmt.Errorf(fmt.Sprintf("kind_box_type: %s\n", errmsg.ErrorMsgNotFound)),
params: benefactorkindboxreqparam.KindBoxReqAddRequest{ params: benefactorkindboxreqparam.KindBoxReqAddRequest{
AddressID: 1, AddressID: 1,
BenefactorID: 1, BenefactorID: 1,
TypeID: 5, KindBoxType: 5,
CountRequested: 1, CountRequested: 1,
ReferDate: time.Now(), ReferDate: time.Now(),
}, },
@ -154,7 +154,7 @@ func TestValidateAddRequest(t *testing.T) {
error: fmt.Errorf(fmt.Sprintf("address_id: cannot be blank\n")), error: fmt.Errorf(fmt.Sprintf("address_id: cannot be blank\n")),
params: benefactorkindboxreqparam.KindBoxReqAddRequest{ params: benefactorkindboxreqparam.KindBoxReqAddRequest{
AddressID: 0, AddressID: 0,
TypeID: 1, KindBoxType: 1,
BenefactorID: 1, BenefactorID: 1,
CountRequested: 1, CountRequested: 1,
ReferDate: time.Now(), ReferDate: time.Now(),
@ -165,7 +165,7 @@ func TestValidateAddRequest(t *testing.T) {
error: fmt.Errorf(fmt.Sprintf("address_id: %s\n", errmsg.ErrorMsgNotFound)), error: fmt.Errorf(fmt.Sprintf("address_id: %s\n", errmsg.ErrorMsgNotFound)),
params: benefactorkindboxreqparam.KindBoxReqAddRequest{ params: benefactorkindboxreqparam.KindBoxReqAddRequest{
AddressID: 5000, AddressID: 5000,
TypeID: 1, KindBoxType: 1,
CountRequested: 1, CountRequested: 1,
BenefactorID: 1, BenefactorID: 1,
ReferDate: time.Now(), ReferDate: time.Now(),
@ -176,7 +176,7 @@ func TestValidateAddRequest(t *testing.T) {
error: fmt.Errorf(fmt.Sprintf("refer_date: cannot be blank\n")), error: fmt.Errorf(fmt.Sprintf("refer_date: cannot be blank\n")),
params: benefactorkindboxreqparam.KindBoxReqAddRequest{ params: benefactorkindboxreqparam.KindBoxReqAddRequest{
AddressID: 1, AddressID: 1,
TypeID: 1, KindBoxType: 1,
BenefactorID: 1, BenefactorID: 1,
CountRequested: 1, CountRequested: 1,
}, },
@ -187,7 +187,7 @@ func TestValidateAddRequest(t *testing.T) {
params: benefactorkindboxreqparam.KindBoxReqAddRequest{ params: benefactorkindboxreqparam.KindBoxReqAddRequest{
AddressID: 1, AddressID: 1,
BenefactorID: 100, BenefactorID: 100,
TypeID: 1, KindBoxType: 1,
CountRequested: 1, CountRequested: 1,
ReferDate: time.Now(), ReferDate: time.Now(),
}, },

View File

@ -9,14 +9,18 @@ import (
validation "github.com/go-ozzo/ozzo-validation/v4" validation "github.com/go-ozzo/ozzo-validation/v4"
) )
func (v Validator) ValidateGetAllRequest(req param.KindBoxReqGetAllRequest) (map[string]string, error) { func (v Validator) ValidateGetAll(req param.GetAllRequest) (map[string]string, error) {
const op = "userkindboxreqvalidator.ValidateGetAllRequest" const op = "benefactorkindboxreqvalidator.ValidateGetAllAwaitingDelivery"
validFields := []string{
"id", "kind_box_type", "status", "sender_agent_id",
"count_requested", "count_accepted",
"deliver_refer_time_id", "deliver_refer_date", "deliver_address_id",
}
if err := validation.ValidateStruct(&req, if err := validation.ValidateStruct(&req,
validation.Field(&req.BenefactorID, validation.Field(&req.Filter, validation.By(v.areFilterFieldsValid(validFields))),
validation.Required, validation.Field(&req.Sort, validation.By(v.areSortFieldsValid(validFields))),
validation.By(v.doesBenefactorExist)),
); err != nil { ); err != nil {
fieldErrors := make(map[string]string) fieldErrors := make(map[string]string)
var errV validation.Errors var errV validation.Errors

View File

@ -25,7 +25,7 @@ func (v Validator) ValidateUpdateRequest(req param.KindBoxReqUpdateRequest) (map
// validation.By(v.hasPendingStatus), // validation.By(v.hasPendingStatus),
// validation.By(v.doesKindBoxBelongToBenefactor(req.BenefactorID))), // validation.By(v.doesKindBoxBelongToBenefactor(req.BenefactorID))),
validation.Field(&req.TypeID, validation.Field(&req.KindBoxType,
validation.Required, validation.Required,
validation.By(v.doesTypeExist)), validation.By(v.doesTypeExist)),
); err != nil { ); err != nil {

View File

@ -3,6 +3,8 @@ package benefactorkindboxreqvalidator
import ( import (
"context" "context"
"fmt" "fmt"
params "git.gocasts.ir/ebhomengo/niki/param"
"slices"
"time" "time"
"git.gocasts.ir/ebhomengo/niki/entity" "git.gocasts.ir/ebhomengo/niki/entity"
@ -56,8 +58,8 @@ func (v ValidatorError) Error() string {
return err return err
} }
func New(benefactorSvc BenefactorSvc, addressSvc AddressSvc, referTimeSvc ReferTimeSvc,repo Repository) Validator { func New(benefactorSvc BenefactorSvc, addressSvc AddressSvc, referTimeSvc ReferTimeSvc, repo Repository) Validator {
return Validator{benefactorSvc: benefactorSvc, addressSvc: addressSvc, referTimeSvc: referTimeSvc,repo:repo} return Validator{benefactorSvc: benefactorSvc, addressSvc: addressSvc, referTimeSvc: referTimeSvc, repo: repo}
} }
func (v Validator) doesBenefactorExist(value interface{}) error { func (v Validator) doesBenefactorExist(value interface{}) error {
@ -74,11 +76,11 @@ func (v Validator) doesBenefactorExist(value interface{}) error {
} }
func (v Validator) doesTypeExist(value interface{}) error { func (v Validator) doesTypeExist(value interface{}) error {
typeID, ok := value.(entity.KindBoxType) kindBoxType, ok := value.(entity.KindBoxType)
if !ok { if !ok {
return fmt.Errorf(errmsg.ErrorMsgSomethingWentWrong) return fmt.Errorf(errmsg.ErrorMsgSomethingWentWrong)
} }
if !typeID.IsValid() { if !kindBoxType.IsValid() {
return fmt.Errorf(errmsg.ErrorMsgNotFound) return fmt.Errorf(errmsg.ErrorMsgNotFound)
} }
@ -166,3 +168,37 @@ func (v Validator) doesKindBoxRequestHavePendingStatus(value interface{}) error
} }
return nil 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
}
}