forked from ebhomengo/niki
Merge branch 'develop' into stage/hamed/unnecessary-check-userid
This commit is contained in:
commit
7292ce6c09
|
|
@ -1,13 +1,13 @@
|
|||
package adminbenefactorhandler
|
||||
|
||||
import (
|
||||
params "git.gocasts.ir/ebhomengo/niki/param"
|
||||
adminaddressparam "git.gocasts.ir/ebhomengo/niki/param/admin/address"
|
||||
adminkindboxparam "git.gocasts.ir/ebhomengo/niki/param/admin/kind_box"
|
||||
adminkindboxreqparam "git.gocasts.ir/ebhomengo/niki/param/admin/kind_box_req"
|
||||
"net/http"
|
||||
|
||||
params "git.gocasts.ir/ebhomengo/niki/param"
|
||||
adminaddressparam "git.gocasts.ir/ebhomengo/niki/param/admin/address"
|
||||
param "git.gocasts.ir/ebhomengo/niki/param/admin/benefactor"
|
||||
adminkindboxparam "git.gocasts.ir/ebhomengo/niki/param/admin/kind_box"
|
||||
adminkindboxreqparam "git.gocasts.ir/ebhomengo/niki/param/admin/kind_box_req"
|
||||
httpmsg "git.gocasts.ir/ebhomengo/niki/pkg/http_msg"
|
||||
"github.com/labstack/echo/v4"
|
||||
)
|
||||
|
|
@ -19,7 +19,7 @@ import (
|
|||
// @Accept json
|
||||
// @Produce json
|
||||
// @Param id path int true "Benefactor ID"
|
||||
// @Success 200 {object} param.GetBenefactorByIDResponse
|
||||
// @Success 200 {object} BenefactorAggregatedResponse
|
||||
// @Failure 400 {string} "Bad request"
|
||||
// @Failure 401 {string} "invalid or expired jwt"
|
||||
// @Failure 403 {string} "user not allowed"
|
||||
|
|
@ -58,6 +58,9 @@ func (h Handler) GetBenefactor(c echo.Context) error {
|
|||
Field: "created_at",
|
||||
Direction: params.DescSortDirection,
|
||||
},
|
||||
Filter: map[string]any{
|
||||
"benefactor_id": bnf.Data.ID,
|
||||
},
|
||||
})
|
||||
if err != nil {
|
||||
msg, code := httpmsg.Error(err)
|
||||
|
|
@ -74,6 +77,9 @@ func (h Handler) GetBenefactor(c echo.Context) error {
|
|||
Field: "created_at",
|
||||
Direction: params.DescSortDirection,
|
||||
},
|
||||
Filter: map[string]any{
|
||||
"benefactor_id": bnf.Data.ID,
|
||||
},
|
||||
})
|
||||
if err != nil {
|
||||
msg, code := httpmsg.Error(err)
|
||||
|
|
|
|||
|
|
@ -14,6 +14,7 @@ import (
|
|||
// @Tags Admins Benefactors
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Param search query string false "Search by id, phone_number, concat(first_name, last_name) benefactor"
|
||||
// @Param filter_id query int false "Filter by ID"
|
||||
// @Param filter_first_name query string false "Filter by first_name"
|
||||
// @Param filter_last_name query string false "Filter by last_name"
|
||||
|
|
|
|||
|
|
@ -13,4 +13,6 @@ func (h Handler) SetRoutes(e *echo.Echo) {
|
|||
|
||||
r.GET("", h.GetAllBenefactor, middleware.AdminAuthorization(h.authorizeSvc, entity.AdminBenefactorGetAllPermission))
|
||||
r.GET("/:id", h.GetBenefactor, middleware.AdminAuthorization(h.authorizeSvc, entity.AdminBenefactorGetPermission))
|
||||
r.PUT("/:id", h.Update, middleware.AdminAuthorization(h.authorizeSvc, entity.AdminBenefactorUpdatePermission))
|
||||
r.PUT("/:id/status", h.UpdateStatus, middleware.AdminAuthorization(h.authorizeSvc, entity.AdminBenefactorUpdateStatusPermission))
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,47 @@
|
|||
package adminbenefactorhandler
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
param "git.gocasts.ir/ebhomengo/niki/param/admin/benefactor"
|
||||
httpmsg "git.gocasts.ir/ebhomengo/niki/pkg/http_msg"
|
||||
"github.com/labstack/echo/v4"
|
||||
)
|
||||
|
||||
// Update godoc
|
||||
// @Summary Update benefactor details by admin
|
||||
// @Description This endpoint update specific benefactor.
|
||||
// @Tags Admins Benefactors
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Param id path int true "Benefactor ID"
|
||||
// @Param Request body param.BenefactorUpdateRequest true "Update Benefactor Body"
|
||||
// @Success 204
|
||||
// @Failure 400 {string} "Bad request"
|
||||
// @Failure 401 {string} "invalid or expired jwt"
|
||||
// @Failure 403 {string} "user not allowed"
|
||||
// @Failure 404 {string} "record not found"
|
||||
// @Failure 500 {string} "something went wrong"
|
||||
// @Security AuthBearerAdmin
|
||||
// @Router /admins/benefactors/{id} [put].
|
||||
func (h Handler) Update(c echo.Context) error {
|
||||
var req param.BenefactorUpdateRequest
|
||||
if bErr := c.Bind(&req); bErr != nil {
|
||||
return echo.NewHTTPError(http.StatusBadRequest)
|
||||
}
|
||||
|
||||
resp, sErr := h.benefactorSvc.Update(c.Request().Context(), req)
|
||||
if sErr != nil {
|
||||
msg, code := httpmsg.Error(sErr)
|
||||
if resp.FieldErrors != nil {
|
||||
return c.JSON(code, echo.Map{
|
||||
"message": msg,
|
||||
"errors": resp.FieldErrors,
|
||||
})
|
||||
}
|
||||
|
||||
return echo.NewHTTPError(code, msg)
|
||||
}
|
||||
|
||||
return c.JSON(http.StatusNoContent, nil)
|
||||
}
|
||||
|
|
@ -0,0 +1,46 @@
|
|||
package adminbenefactorhandler
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
param "git.gocasts.ir/ebhomengo/niki/param/admin/benefactor"
|
||||
httpmsg "git.gocasts.ir/ebhomengo/niki/pkg/http_msg"
|
||||
"github.com/labstack/echo/v4"
|
||||
)
|
||||
|
||||
// UpdateStatus godoc
|
||||
// @Summary Update benefactor status by admin
|
||||
// @Description This endpoint update status (active/inactive) benefactor.
|
||||
// @Tags Admins Benefactors
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Param id path int true "Benefactor ID"
|
||||
// @Param Request body param.BenefactorUpdateStatusRequest true "Update Benefactor Status"
|
||||
// @Success 204
|
||||
// @Failure 400 {string} "Bad request"
|
||||
// @Failure 401 {string} "invalid or expired jwt"
|
||||
// @Failure 403 {string} "user not allowed"
|
||||
// @Failure 404 {string} "record not found"
|
||||
// @Failure 500 {string} "something went wrong"
|
||||
// @Security AuthBearerAdmin
|
||||
// @Router /admins/benefactors/{id}/status [put].
|
||||
func (h Handler) UpdateStatus(c echo.Context) error {
|
||||
var req param.BenefactorUpdateStatusRequest
|
||||
if bErr := c.Bind(&req); bErr != nil {
|
||||
return echo.NewHTTPError(http.StatusBadRequest)
|
||||
}
|
||||
resp, sErr := h.benefactorSvc.UpdateStatus(c.Request().Context(), req)
|
||||
if sErr != nil {
|
||||
msg, code := httpmsg.Error(sErr)
|
||||
if resp.FieldErrors != nil {
|
||||
return c.JSON(code, echo.Map{
|
||||
"message": msg,
|
||||
"errors": resp.FieldErrors,
|
||||
})
|
||||
}
|
||||
|
||||
return echo.NewHTTPError(code, msg)
|
||||
}
|
||||
|
||||
return c.JSON(http.StatusNoContent, nil)
|
||||
}
|
||||
|
|
@ -15,6 +15,7 @@ import (
|
|||
// @Tags Admins KindBoxes
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Param search query string false "Search by id, phone_number, concat(first_name, last_name) benefactor"
|
||||
// @Param filter_id query int false "Filter by ID"
|
||||
// @Param filter_kind_box_req_id query int false "Filter by KindBox request ID"
|
||||
// @Param filter_benefactor_id query int false "Filter by benefactor ID"
|
||||
|
|
|
|||
|
|
@ -15,6 +15,7 @@ import (
|
|||
// @Tags Admins KindBoxReqs
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Param search query string false "Search by id, phone_number, concat(first_name, last_name) benefactor"
|
||||
// @Param filter_id query int false "Filter by ID"
|
||||
// @Param filter_benefactor_id query int false "Filter by benefactor ID"
|
||||
// @Param filter_sender_agent_id query int false "Filter by sender agent ID"
|
||||
|
|
|
|||
|
|
@ -10,10 +10,6 @@ func (h Handler) SetRoutes(e *echo.Echo) {
|
|||
r := e.Group("/admins/refer-times")
|
||||
|
||||
r.Use(middleware.Auth(h.authSvc))
|
||||
r.Use(
|
||||
middleware.Auth(h.authSvc),
|
||||
middleware.AdminAuthorization(h.adminAuthorizeSvc, entity.AdminKindBoxReqAddPermission),
|
||||
)
|
||||
|
||||
r.GET("", h.GetAll)
|
||||
r.GET("", h.GetAll, middleware.AdminAuthorization(h.adminAuthorizeSvc, entity.AdminReferTimeGetAllPermission))
|
||||
}
|
||||
|
|
|
|||
|
|
@ -33,7 +33,7 @@ services:
|
|||
MARIADB_PASSWORD: ${NIKI_STAGE_MARIADB_UR_PASSWORD}
|
||||
MARIADB_DATABASE: niki_db
|
||||
MARIADB_ROOT_PASSWORD: ${NIKI_STAGE_MARIADB_RT_PASSWORD}
|
||||
ALLOW_EMPTY_PASSWORD: no
|
||||
ALLOW_EMPTY_PASSWORD: "no"
|
||||
|
||||
niki-redis:
|
||||
image: bitnami/redis:6.2
|
||||
|
|
|
|||
248
docs/docs.go
248
docs/docs.go
|
|
@ -66,6 +66,12 @@ const docTemplate = `{
|
|||
],
|
||||
"summary": "Get all benefactors by admin",
|
||||
"parameters": [
|
||||
{
|
||||
"type": "string",
|
||||
"description": "Search by id, phone_number, concat(first_name, last_name) benefactor",
|
||||
"name": "search",
|
||||
"in": "query"
|
||||
},
|
||||
{
|
||||
"type": "integer",
|
||||
"description": "Filter by ID",
|
||||
|
|
@ -215,7 +221,7 @@ const docTemplate = `{
|
|||
"200": {
|
||||
"description": "OK",
|
||||
"schema": {
|
||||
"$ref": "#/definitions/adminbenefactoreparam.GetBenefactorByIDResponse"
|
||||
"$ref": "#/definitions/adminbenefactorhandler.BenefactorAggregatedResponse"
|
||||
}
|
||||
},
|
||||
"400": {
|
||||
|
|
@ -249,6 +255,150 @@ const docTemplate = `{
|
|||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"put": {
|
||||
"security": [
|
||||
{
|
||||
"AuthBearerAdmin": []
|
||||
}
|
||||
],
|
||||
"description": "This endpoint update specific benefactor.",
|
||||
"consumes": [
|
||||
"application/json"
|
||||
],
|
||||
"produces": [
|
||||
"application/json"
|
||||
],
|
||||
"tags": [
|
||||
"Admins Benefactors"
|
||||
],
|
||||
"summary": "Update benefactor details by admin",
|
||||
"parameters": [
|
||||
{
|
||||
"type": "integer",
|
||||
"description": "Benefactor ID",
|
||||
"name": "id",
|
||||
"in": "path",
|
||||
"required": true
|
||||
},
|
||||
{
|
||||
"description": "Update Benefactor Body",
|
||||
"name": "Request",
|
||||
"in": "body",
|
||||
"required": true,
|
||||
"schema": {
|
||||
"$ref": "#/definitions/adminbenefactoreparam.BenefactorUpdateRequest"
|
||||
}
|
||||
}
|
||||
],
|
||||
"responses": {
|
||||
"204": {
|
||||
"description": "No Content"
|
||||
},
|
||||
"400": {
|
||||
"description": "Bad request",
|
||||
"schema": {
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"401": {
|
||||
"description": "invalid or expired jwt",
|
||||
"schema": {
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"403": {
|
||||
"description": "user not allowed",
|
||||
"schema": {
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"404": {
|
||||
"description": "record not found",
|
||||
"schema": {
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"500": {
|
||||
"description": "something went wrong",
|
||||
"schema": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"/admins/benefactors/{id}/status": {
|
||||
"put": {
|
||||
"security": [
|
||||
{
|
||||
"AuthBearerAdmin": []
|
||||
}
|
||||
],
|
||||
"description": "This endpoint update status (active/inactive) benefactor.",
|
||||
"consumes": [
|
||||
"application/json"
|
||||
],
|
||||
"produces": [
|
||||
"application/json"
|
||||
],
|
||||
"tags": [
|
||||
"Admins Benefactors"
|
||||
],
|
||||
"summary": "Update benefactor status by admin",
|
||||
"parameters": [
|
||||
{
|
||||
"type": "integer",
|
||||
"description": "Benefactor ID",
|
||||
"name": "id",
|
||||
"in": "path",
|
||||
"required": true
|
||||
},
|
||||
{
|
||||
"description": "Update Benefactor Status",
|
||||
"name": "Request",
|
||||
"in": "body",
|
||||
"required": true,
|
||||
"schema": {
|
||||
"$ref": "#/definitions/adminbenefactoreparam.BenefactorUpdateStatusRequest"
|
||||
}
|
||||
}
|
||||
],
|
||||
"responses": {
|
||||
"204": {
|
||||
"description": "No Content"
|
||||
},
|
||||
"400": {
|
||||
"description": "Bad request",
|
||||
"schema": {
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"401": {
|
||||
"description": "invalid or expired jwt",
|
||||
"schema": {
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"403": {
|
||||
"description": "user not allowed",
|
||||
"schema": {
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"404": {
|
||||
"description": "record not found",
|
||||
"schema": {
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"500": {
|
||||
"description": "something went wrong",
|
||||
"schema": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"/admins/kindboxes": {
|
||||
|
|
@ -270,6 +420,12 @@ const docTemplate = `{
|
|||
],
|
||||
"summary": "Get all KindBoxes by admin",
|
||||
"parameters": [
|
||||
{
|
||||
"type": "string",
|
||||
"description": "Search by id, phone_number, concat(first_name, last_name) benefactor",
|
||||
"name": "search",
|
||||
"in": "query"
|
||||
},
|
||||
{
|
||||
"type": "integer",
|
||||
"description": "Filter by ID",
|
||||
|
|
@ -706,6 +862,12 @@ const docTemplate = `{
|
|||
],
|
||||
"summary": "Admin get all kindboxreq",
|
||||
"parameters": [
|
||||
{
|
||||
"type": "string",
|
||||
"description": "Search by id, phone_number, concat(first_name, last_name) benefactor",
|
||||
"name": "search",
|
||||
"in": "query"
|
||||
},
|
||||
{
|
||||
"type": "integer",
|
||||
"description": "Filter by ID",
|
||||
|
|
@ -3046,6 +3208,38 @@ const docTemplate = `{
|
|||
}
|
||||
}
|
||||
},
|
||||
"adminaddressparam.Data": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"address": {
|
||||
"type": "string"
|
||||
},
|
||||
"benefactor_id": {
|
||||
"type": "integer"
|
||||
},
|
||||
"city_id": {
|
||||
"type": "integer"
|
||||
},
|
||||
"id": {
|
||||
"type": "integer"
|
||||
},
|
||||
"lat": {
|
||||
"type": "number"
|
||||
},
|
||||
"lon": {
|
||||
"type": "number"
|
||||
},
|
||||
"name": {
|
||||
"type": "string"
|
||||
},
|
||||
"postal_code": {
|
||||
"type": "string"
|
||||
},
|
||||
"province_id": {
|
||||
"type": "integer"
|
||||
}
|
||||
}
|
||||
},
|
||||
"adminagentparam.Data": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
|
|
@ -3098,6 +3292,22 @@ const docTemplate = `{
|
|||
}
|
||||
}
|
||||
},
|
||||
"adminbenefactoreparam.BenefactorUpdateRequest": {
|
||||
"type": "object"
|
||||
},
|
||||
"adminbenefactoreparam.BenefactorUpdateStatusRequest": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"status": {
|
||||
"allOf": [
|
||||
{
|
||||
"$ref": "#/definitions/entity.BenefactorStatus"
|
||||
}
|
||||
],
|
||||
"example": "inactive"
|
||||
}
|
||||
}
|
||||
},
|
||||
"adminbenefactoreparam.Data": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
|
|
@ -3130,11 +3340,37 @@ const docTemplate = `{
|
|||
}
|
||||
}
|
||||
},
|
||||
"adminbenefactoreparam.GetBenefactorByIDResponse": {
|
||||
"adminbenefactorhandler.BenefactorAggregatedResponse": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"data": {
|
||||
"$ref": "#/definitions/adminbenefactorhandler.Data"
|
||||
}
|
||||
}
|
||||
},
|
||||
"adminbenefactorhandler.Data": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"addresses": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"$ref": "#/definitions/adminaddressparam.Data"
|
||||
}
|
||||
},
|
||||
"benefactor": {
|
||||
"$ref": "#/definitions/adminbenefactoreparam.Data"
|
||||
},
|
||||
"kind_box_reqs": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"$ref": "#/definitions/adminkindboxreqparam.Data"
|
||||
}
|
||||
},
|
||||
"kind_boxes": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"$ref": "#/definitions/adminkindboxparam.Data"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
|
|
@ -4450,6 +4686,14 @@ const docTemplate = `{
|
|||
}
|
||||
}
|
||||
},
|
||||
"param.Date": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"time.Time": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
},
|
||||
"param.PaginationResponse": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
|
|
|
|||
|
|
@ -55,6 +55,12 @@
|
|||
],
|
||||
"summary": "Get all benefactors by admin",
|
||||
"parameters": [
|
||||
{
|
||||
"type": "string",
|
||||
"description": "Search by id, phone_number, concat(first_name, last_name) benefactor",
|
||||
"name": "search",
|
||||
"in": "query"
|
||||
},
|
||||
{
|
||||
"type": "integer",
|
||||
"description": "Filter by ID",
|
||||
|
|
@ -204,7 +210,7 @@
|
|||
"200": {
|
||||
"description": "OK",
|
||||
"schema": {
|
||||
"$ref": "#/definitions/adminbenefactoreparam.GetBenefactorByIDResponse"
|
||||
"$ref": "#/definitions/adminbenefactorhandler.BenefactorAggregatedResponse"
|
||||
}
|
||||
},
|
||||
"400": {
|
||||
|
|
@ -238,6 +244,150 @@
|
|||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"put": {
|
||||
"security": [
|
||||
{
|
||||
"AuthBearerAdmin": []
|
||||
}
|
||||
],
|
||||
"description": "This endpoint update specific benefactor.",
|
||||
"consumes": [
|
||||
"application/json"
|
||||
],
|
||||
"produces": [
|
||||
"application/json"
|
||||
],
|
||||
"tags": [
|
||||
"Admins Benefactors"
|
||||
],
|
||||
"summary": "Update benefactor details by admin",
|
||||
"parameters": [
|
||||
{
|
||||
"type": "integer",
|
||||
"description": "Benefactor ID",
|
||||
"name": "id",
|
||||
"in": "path",
|
||||
"required": true
|
||||
},
|
||||
{
|
||||
"description": "Update Benefactor Body",
|
||||
"name": "Request",
|
||||
"in": "body",
|
||||
"required": true,
|
||||
"schema": {
|
||||
"$ref": "#/definitions/adminbenefactoreparam.BenefactorUpdateRequest"
|
||||
}
|
||||
}
|
||||
],
|
||||
"responses": {
|
||||
"204": {
|
||||
"description": "No Content"
|
||||
},
|
||||
"400": {
|
||||
"description": "Bad request",
|
||||
"schema": {
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"401": {
|
||||
"description": "invalid or expired jwt",
|
||||
"schema": {
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"403": {
|
||||
"description": "user not allowed",
|
||||
"schema": {
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"404": {
|
||||
"description": "record not found",
|
||||
"schema": {
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"500": {
|
||||
"description": "something went wrong",
|
||||
"schema": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"/admins/benefactors/{id}/status": {
|
||||
"put": {
|
||||
"security": [
|
||||
{
|
||||
"AuthBearerAdmin": []
|
||||
}
|
||||
],
|
||||
"description": "This endpoint update status (active/inactive) benefactor.",
|
||||
"consumes": [
|
||||
"application/json"
|
||||
],
|
||||
"produces": [
|
||||
"application/json"
|
||||
],
|
||||
"tags": [
|
||||
"Admins Benefactors"
|
||||
],
|
||||
"summary": "Update benefactor status by admin",
|
||||
"parameters": [
|
||||
{
|
||||
"type": "integer",
|
||||
"description": "Benefactor ID",
|
||||
"name": "id",
|
||||
"in": "path",
|
||||
"required": true
|
||||
},
|
||||
{
|
||||
"description": "Update Benefactor Status",
|
||||
"name": "Request",
|
||||
"in": "body",
|
||||
"required": true,
|
||||
"schema": {
|
||||
"$ref": "#/definitions/adminbenefactoreparam.BenefactorUpdateStatusRequest"
|
||||
}
|
||||
}
|
||||
],
|
||||
"responses": {
|
||||
"204": {
|
||||
"description": "No Content"
|
||||
},
|
||||
"400": {
|
||||
"description": "Bad request",
|
||||
"schema": {
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"401": {
|
||||
"description": "invalid or expired jwt",
|
||||
"schema": {
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"403": {
|
||||
"description": "user not allowed",
|
||||
"schema": {
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"404": {
|
||||
"description": "record not found",
|
||||
"schema": {
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"500": {
|
||||
"description": "something went wrong",
|
||||
"schema": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"/admins/kindboxes": {
|
||||
|
|
@ -259,6 +409,12 @@
|
|||
],
|
||||
"summary": "Get all KindBoxes by admin",
|
||||
"parameters": [
|
||||
{
|
||||
"type": "string",
|
||||
"description": "Search by id, phone_number, concat(first_name, last_name) benefactor",
|
||||
"name": "search",
|
||||
"in": "query"
|
||||
},
|
||||
{
|
||||
"type": "integer",
|
||||
"description": "Filter by ID",
|
||||
|
|
@ -695,6 +851,12 @@
|
|||
],
|
||||
"summary": "Admin get all kindboxreq",
|
||||
"parameters": [
|
||||
{
|
||||
"type": "string",
|
||||
"description": "Search by id, phone_number, concat(first_name, last_name) benefactor",
|
||||
"name": "search",
|
||||
"in": "query"
|
||||
},
|
||||
{
|
||||
"type": "integer",
|
||||
"description": "Filter by ID",
|
||||
|
|
@ -3035,6 +3197,38 @@
|
|||
}
|
||||
}
|
||||
},
|
||||
"adminaddressparam.Data": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"address": {
|
||||
"type": "string"
|
||||
},
|
||||
"benefactor_id": {
|
||||
"type": "integer"
|
||||
},
|
||||
"city_id": {
|
||||
"type": "integer"
|
||||
},
|
||||
"id": {
|
||||
"type": "integer"
|
||||
},
|
||||
"lat": {
|
||||
"type": "number"
|
||||
},
|
||||
"lon": {
|
||||
"type": "number"
|
||||
},
|
||||
"name": {
|
||||
"type": "string"
|
||||
},
|
||||
"postal_code": {
|
||||
"type": "string"
|
||||
},
|
||||
"province_id": {
|
||||
"type": "integer"
|
||||
}
|
||||
}
|
||||
},
|
||||
"adminagentparam.Data": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
|
|
@ -3087,6 +3281,22 @@
|
|||
}
|
||||
}
|
||||
},
|
||||
"adminbenefactoreparam.BenefactorUpdateRequest": {
|
||||
"type": "object"
|
||||
},
|
||||
"adminbenefactoreparam.BenefactorUpdateStatusRequest": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"status": {
|
||||
"allOf": [
|
||||
{
|
||||
"$ref": "#/definitions/entity.BenefactorStatus"
|
||||
}
|
||||
],
|
||||
"example": "inactive"
|
||||
}
|
||||
}
|
||||
},
|
||||
"adminbenefactoreparam.Data": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
|
|
@ -3119,11 +3329,37 @@
|
|||
}
|
||||
}
|
||||
},
|
||||
"adminbenefactoreparam.GetBenefactorByIDResponse": {
|
||||
"adminbenefactorhandler.BenefactorAggregatedResponse": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"data": {
|
||||
"$ref": "#/definitions/adminbenefactorhandler.Data"
|
||||
}
|
||||
}
|
||||
},
|
||||
"adminbenefactorhandler.Data": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"addresses": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"$ref": "#/definitions/adminaddressparam.Data"
|
||||
}
|
||||
},
|
||||
"benefactor": {
|
||||
"$ref": "#/definitions/adminbenefactoreparam.Data"
|
||||
},
|
||||
"kind_box_reqs": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"$ref": "#/definitions/adminkindboxreqparam.Data"
|
||||
}
|
||||
},
|
||||
"kind_boxes": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"$ref": "#/definitions/adminkindboxparam.Data"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
|
|
@ -4439,6 +4675,14 @@
|
|||
}
|
||||
}
|
||||
},
|
||||
"param.Date": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"time.Time": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
},
|
||||
"param.PaginationResponse": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
|
|
|
|||
|
|
@ -101,6 +101,27 @@ definitions:
|
|||
example: "1234567890"
|
||||
type: string
|
||||
type: object
|
||||
adminaddressparam.Data:
|
||||
properties:
|
||||
address:
|
||||
type: string
|
||||
benefactor_id:
|
||||
type: integer
|
||||
city_id:
|
||||
type: integer
|
||||
id:
|
||||
type: integer
|
||||
lat:
|
||||
type: number
|
||||
lon:
|
||||
type: number
|
||||
name:
|
||||
type: string
|
||||
postal_code:
|
||||
type: string
|
||||
province_id:
|
||||
type: integer
|
||||
type: object
|
||||
adminagentparam.Data:
|
||||
properties:
|
||||
first_name:
|
||||
|
|
@ -136,6 +157,15 @@ definitions:
|
|||
pagination:
|
||||
$ref: '#/definitions/param.PaginationResponse'
|
||||
type: object
|
||||
adminbenefactoreparam.BenefactorUpdateRequest:
|
||||
type: object
|
||||
adminbenefactoreparam.BenefactorUpdateStatusRequest:
|
||||
properties:
|
||||
status:
|
||||
allOf:
|
||||
- $ref: '#/definitions/entity.BenefactorStatus'
|
||||
example: inactive
|
||||
type: object
|
||||
adminbenefactoreparam.Data:
|
||||
properties:
|
||||
birth_date:
|
||||
|
|
@ -157,10 +187,27 @@ definitions:
|
|||
status:
|
||||
$ref: '#/definitions/entity.BenefactorStatus'
|
||||
type: object
|
||||
adminbenefactoreparam.GetBenefactorByIDResponse:
|
||||
adminbenefactorhandler.BenefactorAggregatedResponse:
|
||||
properties:
|
||||
data:
|
||||
$ref: '#/definitions/adminbenefactorhandler.Data'
|
||||
type: object
|
||||
adminbenefactorhandler.Data:
|
||||
properties:
|
||||
addresses:
|
||||
items:
|
||||
$ref: '#/definitions/adminaddressparam.Data'
|
||||
type: array
|
||||
benefactor:
|
||||
$ref: '#/definitions/adminbenefactoreparam.Data'
|
||||
kind_box_reqs:
|
||||
items:
|
||||
$ref: '#/definitions/adminkindboxreqparam.Data'
|
||||
type: array
|
||||
kind_boxes:
|
||||
items:
|
||||
$ref: '#/definitions/adminkindboxparam.Data'
|
||||
type: array
|
||||
type: object
|
||||
adminkindboxparam.AssignReceiverRequest:
|
||||
properties:
|
||||
|
|
@ -1031,6 +1078,11 @@ definitions:
|
|||
message:
|
||||
type: string
|
||||
type: object
|
||||
param.Date:
|
||||
properties:
|
||||
time.Time:
|
||||
type: string
|
||||
type: object
|
||||
param.PaginationResponse:
|
||||
properties:
|
||||
page_number:
|
||||
|
|
@ -1071,6 +1123,10 @@ paths:
|
|||
consumes:
|
||||
- application/json
|
||||
parameters:
|
||||
- description: Search by id, phone_number, concat(first_name, last_name) benefactor
|
||||
in: query
|
||||
name: search
|
||||
type: string
|
||||
- description: Filter by ID
|
||||
in: query
|
||||
name: filter_id
|
||||
|
|
@ -1174,7 +1230,7 @@ paths:
|
|||
"200":
|
||||
description: OK
|
||||
schema:
|
||||
$ref: '#/definitions/adminbenefactoreparam.GetBenefactorByIDResponse'
|
||||
$ref: '#/definitions/adminbenefactorhandler.BenefactorAggregatedResponse'
|
||||
"400":
|
||||
description: Bad request
|
||||
schema:
|
||||
|
|
@ -1200,6 +1256,99 @@ paths:
|
|||
summary: Get benefactor details by id
|
||||
tags:
|
||||
- Admins Benefactors
|
||||
put:
|
||||
consumes:
|
||||
- application/json
|
||||
description: This endpoint update specific benefactor.
|
||||
parameters:
|
||||
- description: Benefactor ID
|
||||
in: path
|
||||
name: id
|
||||
required: true
|
||||
type: integer
|
||||
- description: Update Benefactor Body
|
||||
in: body
|
||||
name: Request
|
||||
required: true
|
||||
schema:
|
||||
$ref: '#/definitions/adminbenefactoreparam.BenefactorUpdateRequest'
|
||||
produces:
|
||||
- application/json
|
||||
responses:
|
||||
"204":
|
||||
description: No Content
|
||||
"400":
|
||||
description: Bad request
|
||||
schema:
|
||||
type: string
|
||||
"401":
|
||||
description: invalid or expired jwt
|
||||
schema:
|
||||
type: string
|
||||
"403":
|
||||
description: user not allowed
|
||||
schema:
|
||||
type: string
|
||||
"404":
|
||||
description: record not found
|
||||
schema:
|
||||
type: string
|
||||
"500":
|
||||
description: something went wrong
|
||||
schema:
|
||||
type: string
|
||||
security:
|
||||
- AuthBearerAdmin: []
|
||||
summary: Update benefactor details by admin
|
||||
tags:
|
||||
- Admins Benefactors
|
||||
/admins/benefactors/{id}/status:
|
||||
put:
|
||||
consumes:
|
||||
- application/json
|
||||
description: This endpoint update status (active/inactive) benefactor.
|
||||
parameters:
|
||||
- description: Benefactor ID
|
||||
in: path
|
||||
name: id
|
||||
required: true
|
||||
type: integer
|
||||
- description: Update Benefactor Status
|
||||
in: body
|
||||
name: Request
|
||||
required: true
|
||||
schema:
|
||||
$ref: '#/definitions/adminbenefactoreparam.BenefactorUpdateStatusRequest'
|
||||
produces:
|
||||
- application/json
|
||||
responses:
|
||||
"204":
|
||||
description: No Content
|
||||
"400":
|
||||
description: Bad request
|
||||
schema:
|
||||
type: string
|
||||
"401":
|
||||
description: invalid or expired jwt
|
||||
schema:
|
||||
type: string
|
||||
"403":
|
||||
description: user not allowed
|
||||
schema:
|
||||
type: string
|
||||
"404":
|
||||
description: record not found
|
||||
schema:
|
||||
type: string
|
||||
"500":
|
||||
description: something went wrong
|
||||
schema:
|
||||
type: string
|
||||
security:
|
||||
- AuthBearerAdmin: []
|
||||
summary: Update benefactor status by admin
|
||||
tags:
|
||||
- Admins Benefactors
|
||||
/admins/kindboxes:
|
||||
get:
|
||||
consumes:
|
||||
|
|
@ -1207,6 +1356,10 @@ paths:
|
|||
description: Retrieves a list of all KindBoxes with filtering, sorting, and
|
||||
pagination options
|
||||
parameters:
|
||||
- description: Search by id, phone_number, concat(first_name, last_name) benefactor
|
||||
in: query
|
||||
name: search
|
||||
type: string
|
||||
- description: Filter by ID
|
||||
in: query
|
||||
name: filter_id
|
||||
|
|
@ -1498,6 +1651,10 @@ paths:
|
|||
description: Retrieves a list of all KindBox requests with filtering, sorting,
|
||||
and pagination options
|
||||
parameters:
|
||||
- description: Search by id, phone_number, concat(first_name, last_name) benefactor
|
||||
in: query
|
||||
name: search
|
||||
type: string
|
||||
- description: Filter by ID
|
||||
in: query
|
||||
name: filter_id
|
||||
|
|
|
|||
|
|
@ -23,4 +23,7 @@ const (
|
|||
AdminKindBoxEnumeratePermission = AdminPermission("kindbox-enumerate")
|
||||
AdminKindBoxUpdatePermission = AdminPermission("kindbox-update")
|
||||
AdminBenefactorGetPermission = AdminPermission("benefactor-get")
|
||||
AdminBenefactorUpdatePermission = AdminPermission("benefactor-update")
|
||||
AdminBenefactorUpdateStatusPermission = AdminPermission("benefactor-update-status")
|
||||
AdminReferTimeGetAllPermission = AdminPermission("refertime-getall")
|
||||
)
|
||||
|
|
|
|||
|
|
@ -1,8 +1,9 @@
|
|||
package adminbenefactoreparam
|
||||
|
||||
import (
|
||||
"git.gocasts.ir/ebhomengo/niki/entity"
|
||||
"time"
|
||||
|
||||
"git.gocasts.ir/ebhomengo/niki/entity"
|
||||
)
|
||||
|
||||
type Data struct {
|
||||
|
|
@ -13,6 +14,6 @@ type Data struct {
|
|||
Description string `json:"description"`
|
||||
Email string `json:"email"`
|
||||
Gender entity.Gender `json:"gender"`
|
||||
BirthDate time.Time `json:"birth_date"`
|
||||
BirthDate *time.Time `json:"birth_date"`
|
||||
Status entity.BenefactorStatus `json:"status"`
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@ type BenefactorGetAllRequest struct {
|
|||
Pagination param.PaginationRequest
|
||||
Sort param.SortRequest
|
||||
Filter param.FilterRequest
|
||||
Search param.SearchRequest
|
||||
}
|
||||
type BenefactorGetAllResponse struct {
|
||||
Data []Data `json:"data"`
|
||||
|
|
|
|||
|
|
@ -0,0 +1,16 @@
|
|||
package adminbenefactoreparam
|
||||
|
||||
import (
|
||||
"git.gocasts.ir/ebhomengo/niki/param"
|
||||
)
|
||||
|
||||
type BenefactorUpdateRequest struct {
|
||||
ID uint `json:"-" param:"id" example:"1"`
|
||||
FirstName string `json:"first_name" example:"name"`
|
||||
LastName string `json:"last_name" example:"family"`
|
||||
BirthDate param.Date `json:"birth_date" example:"2000-01-01"`
|
||||
}
|
||||
|
||||
type BenefactorUpdateResponse struct {
|
||||
FieldErrors map[string]string `json:"field_errors,omitempty"`
|
||||
}
|
||||
|
|
@ -0,0 +1,12 @@
|
|||
package adminbenefactoreparam
|
||||
|
||||
import "git.gocasts.ir/ebhomengo/niki/entity"
|
||||
|
||||
type BenefactorUpdateStatusRequest struct {
|
||||
ID uint `json:"-" param:"id" example:"1"`
|
||||
Status entity.BenefactorStatus `json:"status" example:"inactive"`
|
||||
}
|
||||
|
||||
type BenefactorUpdateStatusResponse struct {
|
||||
FieldErrors map[string]string `json:"field_errors,omitempty"`
|
||||
}
|
||||
|
|
@ -20,8 +20,8 @@ type Data struct {
|
|||
SenderAgentID uint `json:"sender_agent_id"`
|
||||
DeliveredAt time.Time `json:"delivered_at"`
|
||||
ReturnReferTimeID uint `json:"return_refer_time_id"`
|
||||
ReturnReferDate time.Time `json:"return_refer_date"`
|
||||
ReturnReferDate *time.Time `json:"return_refer_date"`
|
||||
ReturnAddressID uint `json:"return_address_id"`
|
||||
ReceiverAgentID uint `json:"receiver_agent_id"`
|
||||
ReturnedAt time.Time `json:"returned_at"`
|
||||
ReturnedAt *time.Time `json:"returned_at"`
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@ type KindBoxGetAllRequest struct {
|
|||
Pagination param.PaginationRequest
|
||||
Sort param.SortRequest
|
||||
Filter param.FilterRequest
|
||||
Search param.SearchRequest
|
||||
}
|
||||
|
||||
type KindBoxGetAllResponse struct {
|
||||
|
|
|
|||
|
|
@ -18,5 +18,5 @@ type Data struct {
|
|||
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"`
|
||||
DeliveredAt *time.Time `json:"delivered_at"`
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@ type KindBoxReqGetAllRequest struct {
|
|||
Pagination param.PaginationRequest
|
||||
Sort param.SortRequest
|
||||
Filter param.FilterRequest
|
||||
Search param.SearchRequest
|
||||
}
|
||||
|
||||
type KindBoxReqGetAllResponse struct {
|
||||
|
|
|
|||
|
|
@ -20,8 +20,8 @@ type Data struct {
|
|||
SenderAgentID uint `json:"sender_agent_id"`
|
||||
DeliveredAt time.Time `json:"delivered_at"`
|
||||
ReturnReferTimeID uint `json:"return_refer_time_id"`
|
||||
ReturnReferDate time.Time `json:"return_refer_date"`
|
||||
ReturnReferDate *time.Time `json:"return_refer_date"`
|
||||
ReturnAddressID uint `json:"return_address_id"`
|
||||
ReceiverAgentID uint `json:"receiver_agent_id"`
|
||||
ReturnedAt time.Time `json:"returned_at"`
|
||||
ReturnedAt *time.Time `json:"returned_at"`
|
||||
}
|
||||
|
|
|
|||
|
|
@ -18,5 +18,5 @@ type Data struct {
|
|||
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"`
|
||||
DeliveredAt *time.Time `json:"delivered_at"`
|
||||
}
|
||||
|
|
|
|||
|
|
@ -20,8 +20,8 @@ type Data struct {
|
|||
SenderAgentID uint `json:"sender_agent_id"`
|
||||
DeliveredAt time.Time `json:"delivered_at"`
|
||||
ReturnReferTimeID uint `json:"return_refer_time_id"`
|
||||
ReturnReferDate time.Time `json:"return_refer_date"`
|
||||
ReturnReferDate *time.Time `json:"return_refer_date"`
|
||||
ReturnAddressID uint `json:"return_address_id"`
|
||||
ReceiverAgentID uint `json:"receiver_agent_id"`
|
||||
ReturnedAt time.Time `json:"returned_at"`
|
||||
ReturnedAt *time.Time `json:"returned_at"`
|
||||
}
|
||||
|
|
|
|||
|
|
@ -18,5 +18,5 @@ type Data struct {
|
|||
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"`
|
||||
DeliveredAt *time.Time `json:"delivered_at"`
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,29 @@
|
|||
package param
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
type Date struct {
|
||||
time.Time
|
||||
}
|
||||
|
||||
func (t Date) MarshalJSON() ([]byte, error) {
|
||||
date := t.Time.Format("2006-01-02")
|
||||
fmt.Println(date)
|
||||
date = fmt.Sprintf(`"%s"`, date)
|
||||
return []byte(date), nil
|
||||
}
|
||||
|
||||
func (t *Date) UnmarshalJSON(b []byte) (err error) {
|
||||
s := strings.Trim(string(b), "\"")
|
||||
|
||||
date, err := time.Parse("2006-01-02", s)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
t.Time = date
|
||||
return
|
||||
}
|
||||
|
|
@ -0,0 +1,34 @@
|
|||
package param
|
||||
|
||||
import (
|
||||
"regexp"
|
||||
"strings"
|
||||
)
|
||||
|
||||
const (
|
||||
id = "benefactors.id"
|
||||
phoneNumber = "benefactors.phone_number"
|
||||
fullName = "concat(benefactors.first_name, benefactors.last_name)"
|
||||
)
|
||||
|
||||
var searchItems = []string{id, phoneNumber, fullName}
|
||||
|
||||
type SearchRequest struct {
|
||||
Query string `query:"search" example:"09123456789"`
|
||||
}
|
||||
|
||||
type QuerySearch map[string]any
|
||||
|
||||
func (s *SearchRequest) GetSearch() *QuerySearch {
|
||||
searchParams := QuerySearch{}
|
||||
|
||||
if s.Query != "" {
|
||||
s.Query = strings.TrimSpace(s.Query)
|
||||
re := regexp.MustCompile(`[\p{P}\p{S}]+`)
|
||||
s.Query = re.ReplaceAllString(s.Query, "")
|
||||
for _, val := range searchItems {
|
||||
searchParams[val] = s.Query
|
||||
}
|
||||
}
|
||||
return &searchParams
|
||||
}
|
||||
|
|
@ -39,4 +39,5 @@ const (
|
|||
ErrorMsgInvalidSerialNumberRange = "invalid serial number range"
|
||||
ErrorMsgInvalidOrExpiredJwt = "invalid or expired jwt"
|
||||
ErrorMsgInvalidRefreshToken = "invalid refresh token"
|
||||
ErrorMsgInvalidBenefactorStatus = "invalid benefactor status"
|
||||
)
|
||||
|
|
|
|||
|
|
@ -0,0 +1,35 @@
|
|||
package mysqlquerybuilder
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
)
|
||||
|
||||
func BuildDeletedAtQuery(query, table string) string {
|
||||
deletedAtClause := fmt.Sprintf(" %s.deleted_at IS NULL ", table)
|
||||
|
||||
if !strings.Contains(query, "WHERE") {
|
||||
return appendStringBefore(query, "WHERE", deletedAtClause)
|
||||
}
|
||||
|
||||
return appendStringAfter(query, "AND", deletedAtClause)
|
||||
}
|
||||
|
||||
func appendStringBefore(s, operator, appendage string) string {
|
||||
limitIndex := strings.Index(strings.ToUpper(s), "LIMIT")
|
||||
if limitIndex == -1 {
|
||||
return s + operator + appendage
|
||||
}
|
||||
return s[:limitIndex] + operator + appendage + s[limitIndex:]
|
||||
}
|
||||
|
||||
func appendStringAfter(s, operator, appendage string) string {
|
||||
index := strings.Index(strings.ToUpper(s), "WHERE")
|
||||
|
||||
spaceAfterTarget := strings.Index(s[index:], " ")
|
||||
if spaceAfterTarget == -1 {
|
||||
spaceAfterTarget = len(s) - index
|
||||
}
|
||||
|
||||
return s[:index+spaceAfterTarget] + appendage + operator + s[index+spaceAfterTarget:]
|
||||
}
|
||||
|
|
@ -12,16 +12,16 @@ func isValidDateOrDateTime(value string) bool {
|
|||
return datePattern.MatchString(value)
|
||||
}
|
||||
|
||||
func BuildFilterQuery(baseQuery string, filter map[string]interface{}) (string, []any) {
|
||||
func BuildFilterQuery(baseQuery, table string, filter map[string]interface{}) (string, []any) {
|
||||
var conditions []string
|
||||
var args []any
|
||||
|
||||
for key, value := range filter {
|
||||
if strVal, ok := value.(string); ok && isValidDateOrDateTime(strVal) {
|
||||
conditions = append(conditions, fmt.Sprintf("DATE(%s) = ?", key))
|
||||
conditions = append(conditions, fmt.Sprintf("DATE(%s.%s) = ?", table, key))
|
||||
args = append(args, strVal)
|
||||
} else {
|
||||
conditions = append(conditions, fmt.Sprintf("%s = ?", key))
|
||||
conditions = append(conditions, fmt.Sprintf("%s.%s = ?", table, key))
|
||||
args = append(args, value)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,8 +6,8 @@ import (
|
|||
"git.gocasts.ir/ebhomengo/niki/param"
|
||||
)
|
||||
|
||||
func BuildGetAllQuery(baseQuery string, filter param.FilterRequest, pagination param.PaginationRequest, sort param.SortRequest) (query string, args []any) {
|
||||
filterQuery, fArgs := BuildFilterQuery(baseQuery, filter)
|
||||
func BuildGetAllQuery(baseQuery, table string, filter param.FilterRequest, pagination param.PaginationRequest, sort param.SortRequest) (query string, args []any) {
|
||||
filterQuery, fArgs := BuildFilterQuery(baseQuery, table, filter)
|
||||
paginationQuery, pArgs := BuildPaginationQuery(pagination)
|
||||
sortQuery := BuildSortQuery(sort)
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,38 @@
|
|||
package mysqlquerybuilder
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
)
|
||||
|
||||
// TODO: implementation more complete search service.
|
||||
|
||||
func BuildGetSearchQuery(baseQuery string, filter map[string]interface{}, exist bool) (string, []any) {
|
||||
var conditions []string
|
||||
var args []any
|
||||
for key, value := range filter {
|
||||
if key == "id" {
|
||||
conditions = append(conditions, fmt.Sprintf("%s = ?", key))
|
||||
} else {
|
||||
conditions = append(conditions, fmt.Sprintf("%s LIKE ?", key))
|
||||
}
|
||||
args = append(args, value)
|
||||
}
|
||||
|
||||
query := baseQuery
|
||||
if len(conditions) > 0 {
|
||||
subQuery := strings.Join(conditions, " OR ")
|
||||
if exist {
|
||||
query += fmt.Sprintf(" INNER JOIN benefactors ON benefactor_id = benefactors.id WHERE (%s) ", subQuery)
|
||||
} else {
|
||||
if strings.Contains(strings.ToUpper(baseQuery), "WHERE") {
|
||||
query += " AND "
|
||||
} else {
|
||||
query += " WHERE "
|
||||
}
|
||||
query += subQuery
|
||||
}
|
||||
}
|
||||
|
||||
return query, args
|
||||
}
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
package response_builder
|
||||
|
||||
import "time"
|
||||
|
||||
func GetNullDate(time time.Time) *time.Time {
|
||||
nullDate := &time
|
||||
if time.IsZero() {
|
||||
nullDate = nil
|
||||
}
|
||||
return nullDate
|
||||
}
|
||||
|
|
@ -10,11 +10,16 @@ import (
|
|||
richerror "git.gocasts.ir/ebhomengo/niki/pkg/rich_error"
|
||||
)
|
||||
|
||||
func (d *DB) GetAllBenefactor(ctx context.Context, filter params.FilterRequest, pagination params.PaginationRequest, sort params.SortRequest) ([]entity.Benefactor, uint, error) {
|
||||
func (d *DB) GetAllBenefactor(ctx context.Context, filter params.FilterRequest, pagination params.PaginationRequest, sort params.SortRequest, searchParams *params.QuerySearch) ([]entity.Benefactor, uint, error) {
|
||||
const op = "mysqlbenefactor.GetAllBenefactor"
|
||||
table := "benefactors"
|
||||
|
||||
baseQuery := `SELECT * FROM benefactors`
|
||||
query, args := builder.BuildGetAllQuery(baseQuery, filter, pagination, sort)
|
||||
|
||||
searchQuery, sArgs := builder.BuildGetSearchQuery(baseQuery, *searchParams, false)
|
||||
query, fArgs := builder.BuildGetAllQuery(searchQuery, table, filter, pagination, sort)
|
||||
args := append(sArgs, fArgs...)
|
||||
|
||||
rows, qErr := d.conn.Conn().QueryContext(ctx, query, args...)
|
||||
if qErr != nil {
|
||||
return nil, 0, richerror.New(op).WithErr(qErr).WithMessage(errmsg.ErrorMsgSomethingWentWrong).WithKind(richerror.KindUnexpected)
|
||||
|
|
@ -38,7 +43,7 @@ func (d *DB) GetAllBenefactor(ctx context.Context, filter params.FilterRequest,
|
|||
}
|
||||
var total uint
|
||||
baseQuery = `SELECT COUNT(*) FROM benefactors`
|
||||
query, args = builder.BuildGetAllQuery(baseQuery, filter, params.PaginationRequest{}, params.SortRequest{})
|
||||
query, args = builder.BuildGetAllQuery(baseQuery, table, filter, params.PaginationRequest{}, params.SortRequest{})
|
||||
qErr = d.conn.Conn().QueryRowContext(ctx, query, args...).Scan(&total)
|
||||
if qErr != nil {
|
||||
return nil, 0, richerror.New(op).WithErr(qErr).WithMessage(errmsg.ErrorMsgSomethingWentWrong).WithKind(richerror.KindUnexpected)
|
||||
|
|
|
|||
|
|
@ -0,0 +1,33 @@
|
|||
package mysqlbenefactor
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"git.gocasts.ir/ebhomengo/niki/entity"
|
||||
errmsg "git.gocasts.ir/ebhomengo/niki/pkg/err_msg"
|
||||
richerror "git.gocasts.ir/ebhomengo/niki/pkg/rich_error"
|
||||
"git.gocasts.ir/ebhomengo/niki/repository/mysql"
|
||||
)
|
||||
|
||||
func (d *DB) UpdateBenefactor(ctx context.Context, benefactor entity.Benefactor) error {
|
||||
const op = "mysqlbenefactor.UpdateBenefactor"
|
||||
|
||||
query := `UPDATE benefactors
|
||||
SET first_name = ?, last_name = ?, birth_date = ?
|
||||
WHERE id = ?`
|
||||
//nolint
|
||||
stmt, err := d.conn.PrepareStatement(ctx, mysql.StatementKeyBenefactorUpdate, query)
|
||||
if err != nil {
|
||||
return richerror.New(op).WithErr(err).
|
||||
WithMessage(errmsg.ErrorMsgCantPrepareStatement).WithKind(richerror.KindUnexpected)
|
||||
}
|
||||
_, uErr := stmt.ExecContext(ctx, benefactor.FirstName,
|
||||
benefactor.LastName, benefactor.BirthDate, benefactor.ID)
|
||||
|
||||
if uErr != nil {
|
||||
return richerror.New(op).WithErr(uErr).WithMessage(errmsg.ErrorMsgCantUpdateRecord).
|
||||
WithKind(richerror.KindUnexpected)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
|
@ -0,0 +1,30 @@
|
|||
package mysqlbenefactor
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"git.gocasts.ir/ebhomengo/niki/entity"
|
||||
errmsg "git.gocasts.ir/ebhomengo/niki/pkg/err_msg"
|
||||
richerror "git.gocasts.ir/ebhomengo/niki/pkg/rich_error"
|
||||
"git.gocasts.ir/ebhomengo/niki/repository/mysql"
|
||||
)
|
||||
|
||||
func (d *DB) UpdateStatusBenefactor(ctx context.Context, benefactor entity.Benefactor, status entity.BenefactorStatus) error {
|
||||
const op = "mysqlbenefactor.UpdateStatusBenefactor"
|
||||
|
||||
query := `UPDATE benefactors SET status = ? WHERE id = ?`
|
||||
//nolint
|
||||
stmt, err := d.conn.PrepareStatement(ctx, mysql.StatementKeyBenefactorUpdateStatus, query)
|
||||
if err != nil {
|
||||
return richerror.New(op).WithErr(err).
|
||||
WithMessage(errmsg.ErrorMsgCantPrepareStatement).WithKind(richerror.KindUnexpected)
|
||||
}
|
||||
_, uErr := stmt.ExecContext(ctx, status, benefactor.ID)
|
||||
|
||||
if uErr != nil {
|
||||
return richerror.New(op).WithErr(uErr).WithMessage(errmsg.ErrorMsgCantUpdateRecord).
|
||||
WithKind(richerror.KindUnexpected)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
|
@ -10,11 +10,17 @@ import (
|
|||
richerror "git.gocasts.ir/ebhomengo/niki/pkg/rich_error"
|
||||
)
|
||||
|
||||
func (d *DB) GetAllKindBox(ctx context.Context, filter params.FilterRequest, pagination params.PaginationRequest, sort params.SortRequest) ([]entity.KindBox, uint, error) {
|
||||
func (d *DB) GetAllKindBox(ctx context.Context, filter params.FilterRequest, pagination params.PaginationRequest, sort params.SortRequest, searchParams *params.QuerySearch) ([]entity.KindBox, uint, error) {
|
||||
const op = "mysqlkindbox.GetAllKindBox"
|
||||
table := "kind_boxes"
|
||||
|
||||
baseQuery := `SELECT kind_boxes.* FROM kind_boxes`
|
||||
|
||||
searchQuery, sArgs := builder.BuildGetSearchQuery(baseQuery, *searchParams, true)
|
||||
filterQuery, fArgs := builder.BuildGetAllQuery(searchQuery, table, filter, pagination, sort)
|
||||
query := builder.BuildDeletedAtQuery(filterQuery, table)
|
||||
args := append(sArgs, fArgs...)
|
||||
|
||||
baseQuery := `SELECT * FROM kind_boxes WHERE deleted_at IS NULL`
|
||||
query, args := builder.BuildGetAllQuery(baseQuery, filter, pagination, sort)
|
||||
rows, qErr := d.conn.Conn().QueryContext(ctx, query, args...)
|
||||
if qErr != nil {
|
||||
return nil, 0, richerror.New(op).WithErr(qErr).WithMessage(errmsg.ErrorMsgSomethingWentWrong).WithKind(richerror.KindUnexpected)
|
||||
|
|
@ -37,7 +43,7 @@ func (d *DB) GetAllKindBox(ctx context.Context, filter params.FilterRequest, pag
|
|||
|
||||
var total uint
|
||||
baseQuery = `SELECT COUNT(*) FROM kind_boxes WHERE deleted_at IS NULL`
|
||||
query, args = builder.BuildGetAllQuery(baseQuery, filter, params.PaginationRequest{}, params.SortRequest{})
|
||||
query, args = builder.BuildGetAllQuery(baseQuery, table, filter, params.PaginationRequest{}, params.SortRequest{})
|
||||
qErr = d.conn.Conn().QueryRowContext(ctx, query, args...).Scan(&total)
|
||||
if qErr != nil {
|
||||
return nil, 0, richerror.New(op).WithErr(qErr).WithMessage(errmsg.ErrorMsgSomethingWentWrong).WithKind(richerror.KindUnexpected)
|
||||
|
|
|
|||
|
|
@ -10,11 +10,17 @@ import (
|
|||
richerror "git.gocasts.ir/ebhomengo/niki/pkg/rich_error"
|
||||
)
|
||||
|
||||
func (d *DB) GetAllKindBoxReq(ctx context.Context, filter param.FilterRequest, pagination param.PaginationRequest, sort param.SortRequest) ([]entity.KindBoxReq, uint, error) {
|
||||
func (d *DB) GetAllKindBoxReq(ctx context.Context, filter param.FilterRequest, pagination param.PaginationRequest, sort param.SortRequest, searchParams *param.QuerySearch) ([]entity.KindBoxReq, uint, error) {
|
||||
const op = "mysqlkindboxreq.GetAllKindBoxReq"
|
||||
table := "kind_box_reqs"
|
||||
|
||||
baseQuery := `SELECT kind_box_reqs.* FROM kind_box_reqs`
|
||||
|
||||
searchQuery, sArgs := builder.BuildGetSearchQuery(baseQuery, *searchParams, true)
|
||||
filterQuery, fArgs := builder.BuildGetAllQuery(searchQuery, table, filter, pagination, sort)
|
||||
query := builder.BuildDeletedAtQuery(filterQuery, table)
|
||||
args := append(sArgs, fArgs...)
|
||||
|
||||
baseQuery := `SELECT * FROM kind_box_reqs WHERE deleted_at IS NULL`
|
||||
query, args := builder.BuildGetAllQuery(baseQuery, filter, pagination, sort)
|
||||
rows, qErr := d.conn.Conn().QueryContext(ctx, query, args...)
|
||||
if qErr != nil {
|
||||
return nil, 0, richerror.New(op).WithErr(qErr).WithMessage(errmsg.ErrorMsgSomethingWentWrong).WithKind(richerror.KindUnexpected)
|
||||
|
|
@ -37,7 +43,7 @@ func (d *DB) GetAllKindBoxReq(ctx context.Context, filter param.FilterRequest, p
|
|||
|
||||
var total uint
|
||||
baseQuery = `SELECT COUNT(*) FROM kind_box_reqs WHERE deleted_at IS NULL`
|
||||
query, args = builder.BuildGetAllQuery(baseQuery, filter, param.PaginationRequest{}, param.SortRequest{})
|
||||
query, args = builder.BuildGetAllQuery(baseQuery, table, filter, param.PaginationRequest{}, param.SortRequest{})
|
||||
qErr = d.conn.Conn().QueryRowContext(ctx, query, args...).Scan(&total)
|
||||
if qErr != nil {
|
||||
return nil, 0, richerror.New(op).WithErr(qErr).WithMessage(errmsg.ErrorMsgSomethingWentWrong).WithKind(richerror.KindUnexpected)
|
||||
|
|
|
|||
|
|
@ -0,0 +1,33 @@
|
|||
-- +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',
|
||||
'kindbox-get',
|
||||
'kindboxreq-add',
|
||||
'kindbox-assign_receiver_agent',
|
||||
'kindbox-getall',
|
||||
'kindboxreq-update',
|
||||
'kindboxreq-get',
|
||||
'kindbox-get_awaiting_return',
|
||||
'kindbox-return',
|
||||
'kindbox-enumerate',
|
||||
'kindbox-update',
|
||||
'benefactor-getall',
|
||||
'benefactor-get',
|
||||
'refertime-getall'
|
||||
) NOT NULL;
|
||||
|
||||
INSERT INTO `admin_access_controls` (`actor_id`, `actor_type`, `permission`)
|
||||
VALUES (1, 'role', 'refertime-getall'),
|
||||
(2, 'role', 'refertime-getall');
|
||||
|
||||
-- +migrate Down
|
||||
DELETE
|
||||
FROM `admin_access_controls`;
|
||||
|
|
@ -0,0 +1,36 @@
|
|||
-- +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',
|
||||
'kindbox-get',
|
||||
'kindboxreq-add',
|
||||
'kindbox-assign_receiver_agent',
|
||||
'kindbox-getall',
|
||||
'kindboxreq-update',
|
||||
'kindboxreq-get',
|
||||
'kindbox-get_awaiting_return',
|
||||
'kindbox-return',
|
||||
'kindbox-enumerate',
|
||||
'kindbox-update',
|
||||
'benefactor-getall',
|
||||
'benefactor-get',
|
||||
'benefactor-update',
|
||||
'benefactor-update-status'
|
||||
) NOT NULL;
|
||||
|
||||
INSERT INTO `admin_access_controls` (`actor_id`, `actor_type`, `permission`)
|
||||
VALUES (1, 'role', 'benefactor-update'),
|
||||
VALUES (2, 'role', 'benefactor-update'),
|
||||
VALUES (1, 'role', 'benefactor-update-status'),
|
||||
VALUES (2, 'role', 'benefactor-update-status');
|
||||
|
||||
-- +migrate Down
|
||||
DELETE
|
||||
FROM `admin_access_controls`;
|
||||
|
|
@ -46,4 +46,6 @@ const (
|
|||
StatementKeyKindBoxUpdate
|
||||
StatementKeyReferTimeGetByID
|
||||
StatementKeyReferTimeGetAll
|
||||
StatementKeyBenefactorUpdate
|
||||
StatementKeyBenefactorUpdateStatus
|
||||
)
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@ package adminaddressservice
|
|||
|
||||
import (
|
||||
"context"
|
||||
|
||||
param "git.gocasts.ir/ebhomengo/niki/param/admin/address"
|
||||
richerror "git.gocasts.ir/ebhomengo/niki/pkg/rich_error"
|
||||
)
|
||||
|
|
|
|||
|
|
@ -2,7 +2,9 @@ package adminbenefactorservice
|
|||
|
||||
import (
|
||||
"context"
|
||||
|
||||
param "git.gocasts.ir/ebhomengo/niki/param/admin/benefactor"
|
||||
response "git.gocasts.ir/ebhomengo/niki/pkg/response_builder"
|
||||
richerror "git.gocasts.ir/ebhomengo/niki/pkg/rich_error"
|
||||
)
|
||||
|
||||
|
|
@ -23,7 +25,7 @@ func (s Service) GetByID(ctx context.Context, req param.GetBenefactorByIDRequest
|
|||
Description: bnf.Description,
|
||||
Email: bnf.Email,
|
||||
Gender: bnf.Gender,
|
||||
BirthDate: bnf.BirthDate,
|
||||
BirthDate: response.GetNullDate(bnf.BirthDate),
|
||||
Status: bnf.Status,
|
||||
},
|
||||
}, nil
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@ import (
|
|||
|
||||
paginationparam "git.gocasts.ir/ebhomengo/niki/param"
|
||||
param "git.gocasts.ir/ebhomengo/niki/param/admin/benefactor"
|
||||
response "git.gocasts.ir/ebhomengo/niki/pkg/response_builder"
|
||||
richerror "git.gocasts.ir/ebhomengo/niki/pkg/rich_error"
|
||||
)
|
||||
|
||||
|
|
@ -17,7 +18,7 @@ func (s Service) GetAllBenefactor(ctx context.Context, req param.BenefactorGetAl
|
|||
req.Pagination.GetPageSize()
|
||||
req.Pagination.GetPageNumber()
|
||||
|
||||
benefactors, total, err := s.repo.GetAllBenefactor(ctx, req.Filter, req.Pagination, req.Sort)
|
||||
benefactors, total, err := s.repo.GetAllBenefactor(ctx, req.Filter, req.Pagination, req.Sort, req.Search.GetSearch())
|
||||
if err != nil {
|
||||
return param.BenefactorGetAllResponse{}, richerror.New(op).WithErr(err).WithKind(richerror.KindUnexpected)
|
||||
}
|
||||
|
|
@ -32,7 +33,7 @@ func (s Service) GetAllBenefactor(ctx context.Context, req param.BenefactorGetAl
|
|||
Description: benefactor.Description,
|
||||
Email: benefactor.Email,
|
||||
Gender: benefactor.Gender,
|
||||
BirthDate: benefactor.BirthDate,
|
||||
BirthDate: response.GetNullDate(benefactor.BirthDate),
|
||||
Status: benefactor.Status,
|
||||
})
|
||||
}
|
||||
|
|
|
|||
|
|
@ -12,7 +12,9 @@ import (
|
|||
type Repository interface {
|
||||
IsExistBenefactorByID(ctx context.Context, id uint) (bool, error)
|
||||
GetByID(ctx context.Context, id uint) (entity.Benefactor, error)
|
||||
GetAllBenefactor(ctx context.Context, filter param.FilterRequest, pagination param.PaginationRequest, sort param.SortRequest) ([]entity.Benefactor, uint, error)
|
||||
UpdateBenefactor(ctx context.Context, benefactor entity.Benefactor) error
|
||||
UpdateStatusBenefactor(ctx context.Context, benefactor entity.Benefactor, status entity.BenefactorStatus) error
|
||||
GetAllBenefactor(ctx context.Context, filter param.FilterRequest, pagination param.PaginationRequest, sort param.SortRequest, searchParams *param.QuerySearch) ([]entity.Benefactor, uint, error)
|
||||
}
|
||||
type AddressSvc interface {
|
||||
GetAddressByID(ctx context.Context, request adminaddressparam.AddressGetRequest) (adminaddressparam.AddressGetResponse, error)
|
||||
|
|
|
|||
|
|
@ -0,0 +1,31 @@
|
|||
package adminbenefactorservice
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
param "git.gocasts.ir/ebhomengo/niki/param/admin/benefactor"
|
||||
richerror "git.gocasts.ir/ebhomengo/niki/pkg/rich_error"
|
||||
)
|
||||
|
||||
func (s Service) Update(ctx context.Context, req param.BenefactorUpdateRequest) (param.BenefactorUpdateResponse, error) {
|
||||
const op = "adminbenefactorservice.Update"
|
||||
|
||||
if fieldErrors, vErr := s.vld.ValidateUpdateRequest(ctx, req); vErr != nil {
|
||||
return param.BenefactorUpdateResponse{FieldErrors: fieldErrors}, richerror.New(op).WithErr(vErr)
|
||||
}
|
||||
|
||||
benefactor, err := s.repo.GetByID(ctx, req.ID)
|
||||
if err != nil {
|
||||
return param.BenefactorUpdateResponse{}, richerror.New(op).WithErr(err)
|
||||
}
|
||||
|
||||
benefactor.FirstName = req.FirstName
|
||||
benefactor.LastName = req.LastName
|
||||
benefactor.BirthDate = req.BirthDate.Time
|
||||
|
||||
if uErr := s.repo.UpdateBenefactor(ctx, benefactor); uErr != nil {
|
||||
return param.BenefactorUpdateResponse{}, richerror.New(op).WithErr(uErr)
|
||||
}
|
||||
|
||||
return param.BenefactorUpdateResponse{}, nil
|
||||
}
|
||||
|
|
@ -0,0 +1,27 @@
|
|||
package adminbenefactorservice
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
param "git.gocasts.ir/ebhomengo/niki/param/admin/benefactor"
|
||||
richerror "git.gocasts.ir/ebhomengo/niki/pkg/rich_error"
|
||||
)
|
||||
|
||||
func (s Service) UpdateStatus(ctx context.Context, req param.BenefactorUpdateStatusRequest) (param.BenefactorUpdateStatusResponse, error) {
|
||||
const op = "adminbenefactorservice.UpdateStatus"
|
||||
|
||||
if fieldErrors, vErr := s.vld.ValidateUpdateStatusRequest(ctx, req); vErr != nil {
|
||||
return param.BenefactorUpdateStatusResponse{FieldErrors: fieldErrors}, richerror.New(op).WithErr(vErr)
|
||||
}
|
||||
|
||||
benefactor, err := s.repo.GetByID(ctx, req.ID)
|
||||
if err != nil {
|
||||
return param.BenefactorUpdateStatusResponse{}, richerror.New(op).WithErr(err)
|
||||
}
|
||||
|
||||
if uErr := s.repo.UpdateStatusBenefactor(ctx, benefactor, req.Status); uErr != nil {
|
||||
return param.BenefactorUpdateStatusResponse{}, richerror.New(op).WithErr(uErr)
|
||||
}
|
||||
|
||||
return param.BenefactorUpdateStatusResponse{}, nil
|
||||
}
|
||||
|
|
@ -4,6 +4,7 @@ import (
|
|||
"context"
|
||||
|
||||
param "git.gocasts.ir/ebhomengo/niki/param/admin/kind_box"
|
||||
response "git.gocasts.ir/ebhomengo/niki/pkg/response_builder"
|
||||
richerror "git.gocasts.ir/ebhomengo/niki/pkg/rich_error"
|
||||
)
|
||||
|
||||
|
|
@ -31,9 +32,9 @@ func (s Service) Get(ctx context.Context, req param.KindBoxGetRequest) (param.Ki
|
|||
SenderAgentID: kindBox.SenderAgentID,
|
||||
DeliveredAt: kindBox.DeliveredAt,
|
||||
ReturnReferTimeID: kindBox.ReturnReferTimeID,
|
||||
ReturnReferDate: kindBox.ReturnReferDate,
|
||||
ReturnReferDate: response.GetNullDate(kindBox.ReturnReferDate),
|
||||
ReturnAddressID: kindBox.ReturnAddressID,
|
||||
ReceiverAgentID: kindBox.ReceiverAgentID,
|
||||
ReturnedAt: kindBox.ReturnedAt,
|
||||
ReturnedAt: response.GetNullDate(kindBox.ReturnedAt),
|
||||
}}, nil
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@ import (
|
|||
|
||||
paginationparam "git.gocasts.ir/ebhomengo/niki/param"
|
||||
param "git.gocasts.ir/ebhomengo/niki/param/admin/kind_box"
|
||||
response "git.gocasts.ir/ebhomengo/niki/pkg/response_builder"
|
||||
richerror "git.gocasts.ir/ebhomengo/niki/pkg/rich_error"
|
||||
)
|
||||
|
||||
|
|
@ -18,7 +19,7 @@ func (s Service) GetAll(ctx context.Context, req param.KindBoxGetAllRequest) (pa
|
|||
req.Pagination.GetPageSize()
|
||||
req.Pagination.GetPageNumber()
|
||||
|
||||
allKindBox, total, err := s.repo.GetAllKindBox(ctx, req.Filter, req.Pagination, req.Sort)
|
||||
allKindBox, total, err := s.repo.GetAllKindBox(ctx, req.Filter, req.Pagination, req.Sort, req.Search.GetSearch())
|
||||
if err != nil {
|
||||
return param.KindBoxGetAllResponse{}, richerror.New(op).WithErr(err)
|
||||
}
|
||||
|
|
@ -39,10 +40,10 @@ func (s Service) GetAll(ctx context.Context, req param.KindBoxGetAllRequest) (pa
|
|||
SenderAgentID: kindBox.SenderAgentID,
|
||||
DeliveredAt: kindBox.DeliveredAt,
|
||||
ReturnReferTimeID: kindBox.ReturnReferTimeID,
|
||||
ReturnReferDate: kindBox.ReturnReferDate,
|
||||
ReturnReferDate: response.GetNullDate(kindBox.ReturnReferDate),
|
||||
ReturnAddressID: kindBox.ReturnAddressID,
|
||||
ReceiverAgentID: kindBox.ReceiverAgentID,
|
||||
ReturnedAt: kindBox.ReturnedAt,
|
||||
ReturnedAt: response.GetNullDate(kindBox.ReturnedAt),
|
||||
})
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@ import (
|
|||
type Repository interface {
|
||||
GetKindBox(ctx context.Context, kindBoxID uint) (entity.KindBox, error)
|
||||
AssignReceiverAgent(ctx context.Context, kindBox entity.KindBox) error
|
||||
GetAllKindBox(ctx context.Context, filter params.FilterRequest, pagination params.PaginationRequest, sort params.SortRequest) ([]entity.KindBox, uint, error)
|
||||
GetAllKindBox(ctx context.Context, filter params.FilterRequest, pagination params.PaginationRequest, sort params.SortRequest, searchParams *params.QuerySearch) ([]entity.KindBox, uint, error)
|
||||
EnumerateKindBox(ctx context.Context, kindBoxID uint, amount uint) error
|
||||
UpdateKindBox(ctx context.Context, KindBox entity.KindBox) error
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@ import (
|
|||
"context"
|
||||
|
||||
param "git.gocasts.ir/ebhomengo/niki/param/admin/kind_box_req"
|
||||
response "git.gocasts.ir/ebhomengo/niki/pkg/response_builder"
|
||||
richerror "git.gocasts.ir/ebhomengo/niki/pkg/rich_error"
|
||||
)
|
||||
|
||||
|
|
@ -39,6 +40,6 @@ func (s Service) Accept(ctx context.Context, req param.KindBoxReqAcceptRequest)
|
|||
DeliverReferDate: kindBoxReq.DeliverReferDate,
|
||||
DeliverAddressID: kindBoxReq.DeliverAddressID,
|
||||
SenderAgentID: kindBoxReq.SenderAgentID,
|
||||
DeliveredAt: kindBoxReq.DeliveredAt,
|
||||
DeliveredAt: response.GetNullDate(kindBoxReq.DeliveredAt),
|
||||
}}, nil
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@ import (
|
|||
|
||||
"git.gocasts.ir/ebhomengo/niki/entity"
|
||||
param "git.gocasts.ir/ebhomengo/niki/param/admin/kind_box_req"
|
||||
response "git.gocasts.ir/ebhomengo/niki/pkg/response_builder"
|
||||
richerror "git.gocasts.ir/ebhomengo/niki/pkg/rich_error"
|
||||
)
|
||||
|
||||
|
|
@ -38,6 +39,6 @@ func (s Service) Add(ctx context.Context, req param.KindBoxReqAddRequest) (param
|
|||
DeliverReferDate: kindBoxReq.DeliverReferDate,
|
||||
DeliverAddressID: kindBoxReq.DeliverAddressID,
|
||||
SenderAgentID: kindBoxReq.SenderAgentID,
|
||||
DeliveredAt: kindBoxReq.DeliveredAt,
|
||||
DeliveredAt: response.GetNullDate(kindBoxReq.DeliveredAt),
|
||||
}}, nil
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@ import (
|
|||
"context"
|
||||
|
||||
param "git.gocasts.ir/ebhomengo/niki/param/admin/kind_box_req"
|
||||
response "git.gocasts.ir/ebhomengo/niki/pkg/response_builder"
|
||||
richerror "git.gocasts.ir/ebhomengo/niki/pkg/rich_error"
|
||||
)
|
||||
|
||||
|
|
@ -30,7 +31,7 @@ func (s Service) Get(ctx context.Context, req param.GetKindBoxReqRequest) (param
|
|||
DeliverReferDate: kindBoxReq.DeliverReferDate,
|
||||
DeliverAddressID: kindBoxReq.DeliverAddressID,
|
||||
SenderAgentID: kindBoxReq.SenderAgentID,
|
||||
DeliveredAt: kindBoxReq.DeliveredAt,
|
||||
DeliveredAt: response.GetNullDate(kindBoxReq.DeliveredAt),
|
||||
},
|
||||
}, nil
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@ import (
|
|||
|
||||
paginationparam "git.gocasts.ir/ebhomengo/niki/param"
|
||||
param "git.gocasts.ir/ebhomengo/niki/param/admin/kind_box_req"
|
||||
response "git.gocasts.ir/ebhomengo/niki/pkg/response_builder"
|
||||
richerror "git.gocasts.ir/ebhomengo/niki/pkg/rich_error"
|
||||
)
|
||||
|
||||
|
|
@ -18,7 +19,7 @@ func (s Service) GetAll(ctx context.Context, req param.KindBoxReqGetAllRequest)
|
|||
req.Pagination.GetPageSize()
|
||||
req.Pagination.GetPageNumber()
|
||||
|
||||
allKindBoxReq, total, err := s.repo.GetAllKindBoxReq(ctx, req.Filter, req.Pagination, req.Sort)
|
||||
allKindBoxReq, total, err := s.repo.GetAllKindBoxReq(ctx, req.Filter, req.Pagination, req.Sort, req.Search.GetSearch())
|
||||
if err != nil {
|
||||
return param.KindBoxReqGetAllResponse{}, richerror.New(op).WithErr(err).WithKind(richerror.KindUnexpected)
|
||||
}
|
||||
|
|
@ -36,7 +37,7 @@ func (s Service) GetAll(ctx context.Context, req param.KindBoxReqGetAllRequest)
|
|||
DeliverReferDate: kindBoxReq.DeliverReferDate,
|
||||
DeliverAddressID: kindBoxReq.DeliverAddressID,
|
||||
SenderAgentID: kindBoxReq.SenderAgentID,
|
||||
DeliveredAt: kindBoxReq.DeliveredAt,
|
||||
DeliveredAt: response.GetNullDate(kindBoxReq.DeliveredAt),
|
||||
})
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@ import (
|
|||
"context"
|
||||
|
||||
param "git.gocasts.ir/ebhomengo/niki/param/admin/kind_box_req"
|
||||
response "git.gocasts.ir/ebhomengo/niki/pkg/response_builder"
|
||||
richerror "git.gocasts.ir/ebhomengo/niki/pkg/rich_error"
|
||||
)
|
||||
|
||||
|
|
@ -35,7 +36,7 @@ func (s Service) Reject(ctx context.Context, req param.KindBoxReqRejectRequest)
|
|||
DeliverReferDate: kindBoxReq.DeliverReferDate,
|
||||
DeliverAddressID: kindBoxReq.DeliverAddressID,
|
||||
SenderAgentID: kindBoxReq.SenderAgentID,
|
||||
DeliveredAt: kindBoxReq.DeliveredAt,
|
||||
DeliveredAt: response.GetNullDate(kindBoxReq.DeliveredAt),
|
||||
},
|
||||
}, nil
|
||||
}
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@ type Repository interface {
|
|||
RejectKindBoxReq(ctx context.Context, kindBoxReqID uint, description string) error
|
||||
AssignSenderAgentToKindBoxReq(ctx context.Context, kindBoxReqID uint, senderAgentID uint) error
|
||||
DeliverKindBoxReq(ctx context.Context, kindBoxReqID uint) error
|
||||
GetAllKindBoxReq(ctx context.Context, filter params.FilterRequest, pagination params.PaginationRequest, sort params.SortRequest) ([]entity.KindBoxReq, uint, error)
|
||||
GetAllKindBoxReq(ctx context.Context, filter params.FilterRequest, pagination params.PaginationRequest, sort params.SortRequest, searchParams *params.QuerySearch) ([]entity.KindBoxReq, uint, error)
|
||||
GetAwaitingDeliveryByAgent(ctx context.Context, kindBoxReqID uint, agentID uint) (entity.KindBoxReq, error)
|
||||
AddKindBoxReq(ctx context.Context, kindBoxReq entity.KindBoxReq) (entity.KindBoxReq, error)
|
||||
UpdateKindBoxReq(ctx context.Context, kindBoxReq entity.KindBoxReq) error
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@ import (
|
|||
|
||||
paginationparam "git.gocasts.ir/ebhomengo/niki/param"
|
||||
param "git.gocasts.ir/ebhomengo/niki/param/agent/kind_box"
|
||||
response "git.gocasts.ir/ebhomengo/niki/pkg/response_builder"
|
||||
richerror "git.gocasts.ir/ebhomengo/niki/pkg/rich_error"
|
||||
)
|
||||
|
||||
|
|
@ -20,7 +21,7 @@ func (s Service) GetAll(ctx context.Context, req param.GetAllRequest) (param.Get
|
|||
req.Filter["receiver_agent_id"] = req.ReceiverAgentId
|
||||
req.Filter["status"] = req.Status
|
||||
|
||||
allKindBoxes, total, err := s.repo.GetAllKindBox(ctx, req.Filter, req.Pagination, req.Sort)
|
||||
allKindBoxes, total, err := s.repo.GetAllKindBox(ctx, req.Filter, req.Pagination, req.Sort, nil)
|
||||
if err != nil {
|
||||
return param.GetAllResponse{}, richerror.New(op).WithErr(err)
|
||||
}
|
||||
|
|
@ -41,10 +42,10 @@ func (s Service) GetAll(ctx context.Context, req param.GetAllRequest) (param.Get
|
|||
SenderAgentID: kindBox.SenderAgentID,
|
||||
DeliveredAt: kindBox.DeliveredAt,
|
||||
ReturnReferTimeID: kindBox.ReturnReferTimeID,
|
||||
ReturnReferDate: kindBox.ReturnReferDate,
|
||||
ReturnReferDate: response.GetNullDate(kindBox.ReturnReferDate),
|
||||
ReturnAddressID: kindBox.ReturnAddressID,
|
||||
ReceiverAgentID: kindBox.ReceiverAgentID,
|
||||
ReturnedAt: kindBox.ReturnedAt,
|
||||
ReturnedAt: response.GetNullDate(kindBox.ReturnedAt),
|
||||
})
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@ import (
|
|||
"context"
|
||||
|
||||
param "git.gocasts.ir/ebhomengo/niki/param/agent/kind_box"
|
||||
response "git.gocasts.ir/ebhomengo/niki/pkg/response_builder"
|
||||
richerror "git.gocasts.ir/ebhomengo/niki/pkg/rich_error"
|
||||
)
|
||||
|
||||
|
|
@ -32,10 +33,10 @@ func (s Service) Get(ctx context.Context, req param.GetKindBoxRequest) (param.Ge
|
|||
SenderAgentID: kindBox.SenderAgentID,
|
||||
DeliveredAt: kindBox.DeliveredAt,
|
||||
ReturnReferTimeID: kindBox.ReturnReferTimeID,
|
||||
ReturnReferDate: kindBox.ReturnReferDate,
|
||||
ReturnReferDate: response.GetNullDate(kindBox.ReturnReferDate),
|
||||
ReturnAddressID: kindBox.ReturnAddressID,
|
||||
ReceiverAgentID: kindBox.ReceiverAgentID,
|
||||
ReturnedAt: kindBox.ReturnedAt,
|
||||
ReturnedAt: response.GetNullDate(kindBox.ReturnedAt),
|
||||
},
|
||||
}, nil
|
||||
}
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@ import (
|
|||
|
||||
type Repository interface {
|
||||
GetAwaitingReturnByAgent(ctx context.Context, kindBoxID uint, agentID uint) (entity.KindBox, error)
|
||||
GetAllKindBox(ctx context.Context, filter params.FilterRequest, pagination params.PaginationRequest, sort params.SortRequest) ([]entity.KindBox, uint, error)
|
||||
GetAllKindBox(ctx context.Context, filter params.FilterRequest, pagination params.PaginationRequest, sort params.SortRequest, searchParams *params.QuerySearch) ([]entity.KindBox, uint, error)
|
||||
ReturnKindBox(ctx context.Context, kindBoxID uint, serialNumber string) error
|
||||
AddBatchKindBox(ctx context.Context, kindBoxes []entity.KindBox) error
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@ import (
|
|||
|
||||
paginationparam "git.gocasts.ir/ebhomengo/niki/param"
|
||||
param "git.gocasts.ir/ebhomengo/niki/param/agent/kind_box_req"
|
||||
response "git.gocasts.ir/ebhomengo/niki/pkg/response_builder"
|
||||
richerror "git.gocasts.ir/ebhomengo/niki/pkg/rich_error"
|
||||
)
|
||||
|
||||
|
|
@ -20,7 +21,7 @@ func (s Service) GetAllAwaitingDelivery(ctx context.Context, req param.DeliveryA
|
|||
req.Filter["sender_agent_id"] = req.SenderAgentId
|
||||
req.Filter["status"] = req.Status
|
||||
|
||||
allAwaitingKindBoxReq, total, err := s.repo.GetAllKindBoxReq(ctx, req.Filter, req.Pagination, req.Sort)
|
||||
allAwaitingKindBoxReq, total, err := s.repo.GetAllKindBoxReq(ctx, req.Filter, req.Pagination, req.Sort, nil)
|
||||
if err != nil {
|
||||
return param.DeliveryAwaitingGetAllResponse{}, richerror.New(op).WithErr(err)
|
||||
}
|
||||
|
|
@ -38,7 +39,7 @@ func (s Service) GetAllAwaitingDelivery(ctx context.Context, req param.DeliveryA
|
|||
DeliverReferDate: kindBoxReq.DeliverReferDate,
|
||||
DeliverAddressID: kindBoxReq.DeliverAddressID,
|
||||
SenderAgentID: kindBoxReq.SenderAgentID,
|
||||
DeliveredAt: kindBoxReq.DeliveredAt,
|
||||
DeliveredAt: response.GetNullDate(kindBoxReq.DeliveredAt),
|
||||
})
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@ import (
|
|||
"context"
|
||||
|
||||
param "git.gocasts.ir/ebhomengo/niki/param/agent/kind_box_req"
|
||||
response "git.gocasts.ir/ebhomengo/niki/pkg/response_builder"
|
||||
richerror "git.gocasts.ir/ebhomengo/niki/pkg/rich_error"
|
||||
)
|
||||
|
||||
|
|
@ -30,7 +31,7 @@ func (s Service) GetAwaitingDelivery(ctx context.Context, req param.DeliveryAwai
|
|||
DeliverReferDate: kindBoxReq.DeliverReferDate,
|
||||
DeliverAddressID: kindBoxReq.DeliverAddressID,
|
||||
SenderAgentID: kindBoxReq.SenderAgentID,
|
||||
DeliveredAt: kindBoxReq.DeliveredAt,
|
||||
DeliveredAt: response.GetNullDate(kindBoxReq.DeliveredAt),
|
||||
},
|
||||
}, nil
|
||||
}
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@ import (
|
|||
)
|
||||
|
||||
type Repository interface {
|
||||
GetAllKindBoxReq(ctx context.Context, filter params.FilterRequest, pagination params.PaginationRequest, sort params.SortRequest) ([]entity.KindBoxReq, uint, error)
|
||||
GetAllKindBoxReq(ctx context.Context, filter params.FilterRequest, pagination params.PaginationRequest, sort params.SortRequest, searchParams *params.QuerySearch) ([]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)
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@ import (
|
|||
"context"
|
||||
|
||||
param "git.gocasts.ir/ebhomengo/niki/param/benefactor/kind_box"
|
||||
response "git.gocasts.ir/ebhomengo/niki/pkg/response_builder"
|
||||
richerror "git.gocasts.ir/ebhomengo/niki/pkg/rich_error"
|
||||
)
|
||||
|
||||
|
|
@ -31,9 +32,9 @@ func (s Service) Get(ctx context.Context, req param.KindBoxGetRequest) (param.Ki
|
|||
SenderAgentID: kindBox.SenderAgentID,
|
||||
DeliveredAt: kindBox.DeliveredAt,
|
||||
ReturnReferTimeID: kindBox.ReturnReferTimeID,
|
||||
ReturnReferDate: kindBox.ReturnReferDate,
|
||||
ReturnReferDate: response.GetNullDate(kindBox.ReturnReferDate),
|
||||
ReturnAddressID: kindBox.ReturnAddressID,
|
||||
ReceiverAgentID: kindBox.ReceiverAgentID,
|
||||
ReturnedAt: kindBox.ReturnedAt,
|
||||
ReturnedAt: response.GetNullDate(kindBox.ReturnedAt),
|
||||
}}, nil
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@ import (
|
|||
|
||||
params "git.gocasts.ir/ebhomengo/niki/param"
|
||||
param "git.gocasts.ir/ebhomengo/niki/param/benefactor/kind_box"
|
||||
response "git.gocasts.ir/ebhomengo/niki/pkg/response_builder"
|
||||
richerror "git.gocasts.ir/ebhomengo/niki/pkg/rich_error"
|
||||
)
|
||||
|
||||
|
|
@ -18,7 +19,7 @@ func (s Service) GetAll(ctx context.Context, req param.KindBoxGetAllRequest) (pa
|
|||
req.Pagination.GetPageSize()
|
||||
req.Pagination.GetPageNumber()
|
||||
|
||||
allKindBox, total, err := s.repo.GetAllKindBox(ctx, req.Filter, req.Pagination, req.Sort)
|
||||
allKindBox, total, err := s.repo.GetAllKindBox(ctx, req.Filter, req.Pagination, req.Sort, nil)
|
||||
if err != nil {
|
||||
return param.KindBoxGetAllResponse{}, richerror.New(op).WithErr(err)
|
||||
}
|
||||
|
|
@ -39,10 +40,10 @@ func (s Service) GetAll(ctx context.Context, req param.KindBoxGetAllRequest) (pa
|
|||
SenderAgentID: kindBox.SenderAgentID,
|
||||
DeliveredAt: kindBox.DeliveredAt,
|
||||
ReturnReferTimeID: kindBox.ReturnReferTimeID,
|
||||
ReturnReferDate: kindBox.ReturnReferDate,
|
||||
ReturnReferDate: response.GetNullDate(kindBox.ReturnReferDate),
|
||||
ReturnAddressID: kindBox.ReturnAddressID,
|
||||
ReceiverAgentID: kindBox.ReceiverAgentID,
|
||||
ReturnedAt: kindBox.ReturnedAt,
|
||||
ReturnedAt: response.GetNullDate(kindBox.ReturnedAt),
|
||||
})
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@ import (
|
|||
)
|
||||
|
||||
type Repository interface {
|
||||
GetAllKindBox(ctx context.Context, filter params.FilterRequest, pagination params.PaginationRequest, sort params.SortRequest) ([]entity.KindBox, uint, error)
|
||||
GetAllKindBox(ctx context.Context, filter params.FilterRequest, pagination params.PaginationRequest, sort params.SortRequest, searchParams *params.QuerySearch) ([]entity.KindBox, uint, error)
|
||||
GetKindBox(ctx context.Context, kindBoxID uint) (entity.KindBox, error)
|
||||
RegisterEmptyingRequestForKindBox(ctx context.Context, kindBox entity.KindBox) error
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@ import (
|
|||
|
||||
"git.gocasts.ir/ebhomengo/niki/entity"
|
||||
param "git.gocasts.ir/ebhomengo/niki/param/benefactor/kind_box_req"
|
||||
response "git.gocasts.ir/ebhomengo/niki/pkg/response_builder"
|
||||
richerror "git.gocasts.ir/ebhomengo/niki/pkg/rich_error"
|
||||
)
|
||||
|
||||
|
|
@ -38,6 +39,6 @@ func (s Service) Add(ctx context.Context, req param.KindBoxReqAddRequest) (param
|
|||
DeliverReferDate: kindBoxReq.DeliverReferDate,
|
||||
DeliverAddressID: kindBoxReq.DeliverAddressID,
|
||||
SenderAgentID: kindBoxReq.SenderAgentID,
|
||||
DeliveredAt: kindBoxReq.DeliveredAt,
|
||||
DeliveredAt: response.GetNullDate(kindBoxReq.DeliveredAt),
|
||||
}}, nil
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@ import (
|
|||
"context"
|
||||
|
||||
param "git.gocasts.ir/ebhomengo/niki/param/benefactor/kind_box_req"
|
||||
response "git.gocasts.ir/ebhomengo/niki/pkg/response_builder"
|
||||
richerror "git.gocasts.ir/ebhomengo/niki/pkg/rich_error"
|
||||
)
|
||||
|
||||
|
|
@ -30,6 +31,6 @@ func (s Service) Get(ctx context.Context, req param.KindBoxReqGetRequest) (param
|
|||
DeliverReferDate: kindBoxReq.DeliverReferDate,
|
||||
DeliverAddressID: kindBoxReq.DeliverAddressID,
|
||||
SenderAgentID: kindBoxReq.SenderAgentID,
|
||||
DeliveredAt: kindBoxReq.DeliveredAt,
|
||||
DeliveredAt: response.GetNullDate(kindBoxReq.DeliveredAt),
|
||||
}}, nil
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@ import (
|
|||
|
||||
params "git.gocasts.ir/ebhomengo/niki/param"
|
||||
param "git.gocasts.ir/ebhomengo/niki/param/benefactor/kind_box_req"
|
||||
response "git.gocasts.ir/ebhomengo/niki/pkg/response_builder"
|
||||
richerror "git.gocasts.ir/ebhomengo/niki/pkg/rich_error"
|
||||
)
|
||||
|
||||
|
|
@ -18,7 +19,7 @@ func (s Service) GetAll(ctx context.Context, req param.GetAllRequest) (param.Get
|
|||
req.Pagination.GetPageSize()
|
||||
req.Pagination.GetPageNumber()
|
||||
|
||||
allKindBoxReq, total, err := s.repo.GetAllKindBoxReq(ctx, req.Filter, req.Pagination, req.Sort)
|
||||
allKindBoxReq, total, err := s.repo.GetAllKindBoxReq(ctx, req.Filter, req.Pagination, req.Sort, nil)
|
||||
if err != nil {
|
||||
return param.GetAllResponse{}, richerror.New(op).WithErr(err)
|
||||
}
|
||||
|
|
@ -37,7 +38,7 @@ func (s Service) GetAll(ctx context.Context, req param.GetAllRequest) (param.Get
|
|||
DeliverReferDate: kindBoxReq.DeliverReferDate,
|
||||
DeliverAddressID: kindBoxReq.DeliverAddressID,
|
||||
SenderAgentID: kindBoxReq.SenderAgentID,
|
||||
DeliveredAt: kindBoxReq.DeliveredAt,
|
||||
DeliveredAt: response.GetNullDate(kindBoxReq.DeliveredAt),
|
||||
})
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@ type Repository interface {
|
|||
AddKindBoxReq(ctx context.Context, kindBoxReq entity.KindBoxReq) (entity.KindBoxReq, error)
|
||||
GetKindBoxReqByID(ctx context.Context, kindBoxReqID uint) (entity.KindBoxReq, 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)
|
||||
GetAllKindBoxReq(ctx context.Context, filter params.FilterRequest, pagination params.PaginationRequest, sort params.SortRequest, searchParams *params.QuerySearch) ([]entity.KindBoxReq, uint, error)
|
||||
UpdateKindBoxReq(ctx context.Context, kindBoxReq entity.KindBoxReq) error
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -81,7 +81,7 @@ func New(cfg config.Config, db *mysql.DB, rds *redis.Adapter, smsAdapter smscont
|
|||
AdminReferTimeVld = adminrefertimevalidator.New()
|
||||
AdminReferTimeSvc = adminrefertimeservice.New(referTimeRepo, AdminReferTimeVld)
|
||||
AdminAddressSvc = adminaddressservice.New(addressRepo)
|
||||
AdminBenefactorVld = adminbenefactorvalidator.New()
|
||||
AdminBenefactorVld = adminbenefactorvalidator.New(benefactorRepo)
|
||||
AdminBenefactorSvc = adminbenefactorservice.New(benefactorRepo, AdminAddressSvc, AdminBenefactorVld)
|
||||
AdminAgentSvc = adminagentservice.New(agentRepo)
|
||||
|
||||
|
|
|
|||
|
|
@ -17,6 +17,7 @@ func (v Validator) ValidateGetAll(req param.BenefactorGetAllRequest) (map[string
|
|||
if err := validation.ValidateStruct(&req,
|
||||
validation.Field(&req.Filter, validation.By(v.AreFilterFieldsValid(validFields))),
|
||||
validation.Field(&req.Sort, validation.By(v.AreSortFieldsValid(validFields))),
|
||||
validation.Field(&req.Search, validation.By(v.AreSearchValid())),
|
||||
); err != nil {
|
||||
|
||||
fieldErrors := make(map[string]string)
|
||||
|
|
|
|||
|
|
@ -0,0 +1,46 @@
|
|||
package adminbenefactorvalidator
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
|
||||
param "git.gocasts.ir/ebhomengo/niki/param/admin/benefactor"
|
||||
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"
|
||||
)
|
||||
|
||||
func (v Validator) ValidateUpdateRequest(ctx context.Context, req param.BenefactorUpdateRequest) (map[string]string, error) {
|
||||
const op = "adminbenefactorvalidator.ValidateUpdateRequest"
|
||||
|
||||
if err := validation.ValidateStruct(&req,
|
||||
validation.Field(&req.ID,
|
||||
validation.Required,
|
||||
validation.By(v.doesBenefactorExist(ctx))),
|
||||
validation.Field(&req.FirstName,
|
||||
validation.Length(minLengthFirstName, maxLengthFirstName)),
|
||||
validation.Field(&req.LastName,
|
||||
validation.Length(minLengthLastName, maxLengthLastName)),
|
||||
validation.Field(&req.BirthDate,
|
||||
validation.Required,
|
||||
validation.By(v.isDateValid),
|
||||
),
|
||||
); err != nil {
|
||||
fieldErrors := make(map[string]string)
|
||||
|
||||
vErr := validation.Errors{}
|
||||
if errors.As(err, &vErr) {
|
||||
for key, value := range vErr {
|
||||
if value != nil {
|
||||
fieldErrors[key] = value.Error()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return fieldErrors, richerror.New(op).WithMessage(errmsg.ErrorMsgInvalidInput).
|
||||
WithKind(richerror.KindInvalid).
|
||||
WithMeta(map[string]interface{}{"req": req}).WithErr(err)
|
||||
}
|
||||
|
||||
return nil, nil
|
||||
}
|
||||
|
|
@ -0,0 +1,40 @@
|
|||
package adminbenefactorvalidator
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
|
||||
param "git.gocasts.ir/ebhomengo/niki/param/admin/benefactor"
|
||||
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"
|
||||
)
|
||||
|
||||
func (v Validator) ValidateUpdateStatusRequest(ctx context.Context, req param.BenefactorUpdateStatusRequest) (map[string]string, error) {
|
||||
const op = "adminbenefactorvalidator.ValidateUpdateStatusRequest"
|
||||
|
||||
if err := validation.ValidateStruct(&req,
|
||||
validation.Field(&req.ID,
|
||||
validation.Required,
|
||||
validation.By(v.doesBenefactorExist(ctx))),
|
||||
validation.Field(&req.Status,
|
||||
validation.By(v.doesBenefactorStatusExist)),
|
||||
); err != nil {
|
||||
fieldErrors := make(map[string]string)
|
||||
|
||||
vErr := validation.Errors{}
|
||||
if errors.As(err, &vErr) {
|
||||
for key, value := range vErr {
|
||||
if value != nil {
|
||||
fieldErrors[key] = value.Error()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return fieldErrors, richerror.New(op).WithMessage(errmsg.ErrorMsgInvalidInput).
|
||||
WithKind(richerror.KindInvalid).
|
||||
WithMeta(map[string]interface{}{"req": req}).WithErr(err)
|
||||
}
|
||||
|
||||
return nil, nil
|
||||
}
|
||||
|
|
@ -1,18 +1,36 @@
|
|||
package adminbenefactorvalidator
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"slices"
|
||||
"time"
|
||||
|
||||
"git.gocasts.ir/ebhomengo/niki/entity"
|
||||
params "git.gocasts.ir/ebhomengo/niki/param"
|
||||
errmsg "git.gocasts.ir/ebhomengo/niki/pkg/err_msg"
|
||||
validation "github.com/go-ozzo/ozzo-validation/v4"
|
||||
)
|
||||
|
||||
type Validator struct{}
|
||||
const (
|
||||
minLengthFirstName = 3
|
||||
maxLengthFirstName = 40
|
||||
minLengthLastName = 3
|
||||
maxLengthLastName = 40
|
||||
MaxLengthQuerySearch = 32
|
||||
)
|
||||
|
||||
func New() Validator {
|
||||
return Validator{}
|
||||
type Repository interface {
|
||||
IsExistBenefactorByID(ctx context.Context, id uint) (bool, error)
|
||||
}
|
||||
|
||||
type Validator struct {
|
||||
repo Repository
|
||||
}
|
||||
|
||||
func New(repo Repository) Validator {
|
||||
return Validator{repo: repo}
|
||||
}
|
||||
|
||||
func (v Validator) AreSortFieldsValid(validSortFields []string) validation.RuleFunc {
|
||||
|
|
@ -50,3 +68,62 @@ func (v Validator) AreFilterFieldsValid(validFilters []string) validation.RuleFu
|
|||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
func (v Validator) doesBenefactorExist(ctx context.Context) validation.RuleFunc {
|
||||
return func(value interface{}) error {
|
||||
benefactor, ok := value.(uint)
|
||||
if !ok {
|
||||
return fmt.Errorf(errmsg.ErrorMsgSomethingWentWrong)
|
||||
}
|
||||
if isExist, err := v.repo.IsExistBenefactorByID(ctx, benefactor); !isExist || err != nil {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if !isExist {
|
||||
return errors.New("benefactor is not exist")
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
func (v Validator) AreSearchValid() validation.RuleFunc {
|
||||
return func(value interface{}) error {
|
||||
search, ok := value.(params.SearchRequest)
|
||||
if !ok {
|
||||
return fmt.Errorf(errmsg.ErrorMsgSomethingWentWrong)
|
||||
}
|
||||
if len(search.Query) > MaxLengthQuerySearch {
|
||||
return fmt.Errorf(errmsg.ErrorMsgInvalidInput)
|
||||
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
func (v Validator) isDateValid(value interface{}) error {
|
||||
date, ok := value.(params.Date)
|
||||
if !ok {
|
||||
return fmt.Errorf(errmsg.ErrorMsgSomethingWentWrong)
|
||||
}
|
||||
|
||||
if date.After(time.Now()) {
|
||||
return fmt.Errorf(errmsg.ErrorMsgInvalidInput)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (v Validator) doesBenefactorStatusExist(value interface{}) error {
|
||||
BenefactorStatus, ok := value.(entity.BenefactorStatus)
|
||||
if !ok {
|
||||
return fmt.Errorf(errmsg.ErrorMsgSomethingWentWrong)
|
||||
}
|
||||
if !BenefactorStatus.IsValid() {
|
||||
return fmt.Errorf(errmsg.ErrorMsgInvalidBenefactorStatus)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
|
|
|||
|
|
@ -21,6 +21,7 @@ func (v Validator) ValidateGetAll(req param.KindBoxGetAllRequest) (map[string]st
|
|||
if err := validation.ValidateStruct(&req,
|
||||
validation.Field(&req.Filter, validation.By(v.AreFilterFieldsValid(validFields))),
|
||||
validation.Field(&req.Sort, validation.By(v.AreSortFieldsValid(validFields))),
|
||||
validation.Field(&req.Search, validation.By(v.AreSearchValid())),
|
||||
); err != nil {
|
||||
|
||||
fieldErrors := make(map[string]string)
|
||||
|
|
|
|||
|
|
@ -18,6 +18,10 @@ import (
|
|||
validation "github.com/go-ozzo/ozzo-validation/v4"
|
||||
)
|
||||
|
||||
const (
|
||||
MaxLengthQuerySearch = 32
|
||||
)
|
||||
|
||||
//go:generate mockery --name Repository
|
||||
type Repository interface {
|
||||
KindBoxExist(ctx context.Context, kindBoxID uint) (bool, error)
|
||||
|
|
@ -279,3 +283,17 @@ func (v Validator) AreFilterFieldsValid(validFilters []string) validation.RuleFu
|
|||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
func (v Validator) AreSearchValid() validation.RuleFunc {
|
||||
return func(value interface{}) error {
|
||||
search, ok := value.(params.SearchRequest)
|
||||
if !ok {
|
||||
return fmt.Errorf(errmsg.ErrorMsgSomethingWentWrong)
|
||||
}
|
||||
if len(search.Query) > MaxLengthQuerySearch {
|
||||
return fmt.Errorf(errmsg.ErrorMsgInvalidInput)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -20,6 +20,7 @@ func (v Validator) ValidateGetAll(req param.KindBoxReqGetAllRequest) (map[string
|
|||
if err := validation.ValidateStruct(&req,
|
||||
validation.Field(&req.Filter, validation.By(v.AreFilterFieldsValid(validFields))),
|
||||
validation.Field(&req.Sort, validation.By(v.AreSortFieldsValid(validFields))),
|
||||
validation.Field(&req.Search, validation.By(v.AreSearchValid())),
|
||||
); err != nil {
|
||||
fieldErrors := make(map[string]string)
|
||||
|
||||
|
|
|
|||
|
|
@ -20,6 +20,7 @@ import (
|
|||
const (
|
||||
MinKindBoxReq = 1
|
||||
MaxKindBoxReq = 100
|
||||
MaxLengthQuerySearch = 32
|
||||
)
|
||||
|
||||
type Repository interface {
|
||||
|
|
@ -340,3 +341,17 @@ func (v Validator) AreFilterFieldsValid(validFilters []string) validation.RuleFu
|
|||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
func (v Validator) AreSearchValid() validation.RuleFunc {
|
||||
return func(value interface{}) error {
|
||||
search, ok := value.(params.SearchRequest)
|
||||
if !ok {
|
||||
return fmt.Errorf(errmsg.ErrorMsgSomethingWentWrong)
|
||||
}
|
||||
if len(search.Query) > MaxLengthQuerySearch {
|
||||
return fmt.Errorf(errmsg.ErrorMsgInvalidInput)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue