forked from ebhomengo/niki
feat(niki): get all benefactors by admin
This commit is contained in:
parent
046b292f9f
commit
300b69b449
|
|
@ -1,9 +1,9 @@
|
|||
package adminhandler
|
||||
|
||||
import (
|
||||
adminserviceparam "git.gocasts.ir/ebhomengo/niki/param/admin/admin"
|
||||
"net/http"
|
||||
|
||||
adminserviceparam "git.gocasts.ir/ebhomengo/niki/param/admin/admin"
|
||||
httpmsg "git.gocasts.ir/ebhomengo/niki/pkg/http_msg"
|
||||
"github.com/labstack/echo/v4"
|
||||
)
|
||||
|
|
|
|||
|
|
@ -1,26 +1,55 @@
|
|||
package adminbenefactorhandler
|
||||
|
||||
import (
|
||||
adminbenefactorparam "git.gocasts.ir/ebhomengo/niki/param/admin/benefactor"
|
||||
httpmsg "git.gocasts.ir/ebhomengo/niki/pkg/http_msg"
|
||||
"github.com/labstack/echo/v4"
|
||||
"net/http"
|
||||
|
||||
param "git.gocasts.ir/ebhomengo/niki/param/admin/benefactor"
|
||||
httpmsg "git.gocasts.ir/ebhomengo/niki/pkg/http_msg"
|
||||
queryparam "git.gocasts.ir/ebhomengo/niki/pkg/query_param"
|
||||
"github.com/labstack/echo/v4"
|
||||
)
|
||||
|
||||
// GetAllBenefactor godoc
|
||||
// @Summary Get all benefactor by admin
|
||||
// @Summary Get all benefactors by admin
|
||||
// @Tags Admins Benefactors
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Success 200 {object} adminbenefactorparam.GetAllBenefactorResponse
|
||||
// @Failure 400 {string} "Bad request"
|
||||
// @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"
|
||||
// @Param filter_phone_number query string false "Filter by phone_number"
|
||||
// @Param filter_email query string false "Filter by email"
|
||||
// @Param filter_status query string false "Filter by status" Enums(active,inactive)
|
||||
// @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,first_name,last_name,phone_number,email,status,created_at)
|
||||
// @Param sort_direction query string false "Sort order" Enums(asc,desc)
|
||||
// @Success 200 {object} param.BenefactorGetAllResponse
|
||||
// @Failure 400 {string} "Bad Request"
|
||||
// @Failure 401 {string} "invalid or expired jwt"
|
||||
// @Failure 403 {string} "user not allowed"
|
||||
// @Failure 422 {object} httpmsg.ErrorResponse
|
||||
// @Failure 500 {string} "something went wrong"
|
||||
// @Security AuthBearerAdmin
|
||||
// @Router /admins/benefactors [get].
|
||||
func (h Handler) GetAllBenefactor(c echo.Context) error {
|
||||
var resp adminbenefactorparam.GetAllBenefactorResponse
|
||||
resp, sErr := h.benefactorSvc.GetAllBenefactor(c.Request().Context())
|
||||
var req param.BenefactorGetAllRequest
|
||||
|
||||
if bErr := c.Bind(&req); bErr != nil {
|
||||
return echo.NewHTTPError(http.StatusBadRequest)
|
||||
}
|
||||
|
||||
req.Filter = queryparam.GetFilterParams(c)
|
||||
|
||||
resp, sErr := h.benefactorSvc.GetAllBenefactor(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)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,7 +7,9 @@ import (
|
|||
)
|
||||
|
||||
func (h Handler) SetRoutes(e *echo.Echo) {
|
||||
r := e.Group("/admins")
|
||||
r := e.Group("/admins/benefactors")
|
||||
|
||||
r.GET("/benefactors", h.GetAllBenefactor, middleware.Auth(h.authSvc), middleware.AdminAuthorization(h.authorizeSvc, entity.AdminBenefactorGetAllPermission))
|
||||
r.Use(middleware.Auth(h.authSvc))
|
||||
|
||||
r.GET("", h.GetAllBenefactor, middleware.AdminAuthorization(h.authorizeSvc, entity.AdminBenefactorGetAllPermission))
|
||||
}
|
||||
|
|
|
|||
|
|
@ -24,7 +24,6 @@ import (
|
|||
// @Security AuthBearerAdmin
|
||||
// @Router /admins/kindboxes/update/{id} [put].
|
||||
func (h Handler) Update(c echo.Context) error {
|
||||
|
||||
var req param.KindBoxUpdateRequest
|
||||
|
||||
if bErr := c.Bind(&req); bErr != nil {
|
||||
|
|
|
|||
|
|
@ -2,10 +2,10 @@ package agentkindboxreqhandler
|
|||
|
||||
import (
|
||||
"context"
|
||||
params "git.gocasts.ir/ebhomengo/niki/param"
|
||||
param "git.gocasts.ir/ebhomengo/niki/param/agent/kind_box_req"
|
||||
"net/http"
|
||||
|
||||
params "git.gocasts.ir/ebhomengo/niki/param"
|
||||
param "git.gocasts.ir/ebhomengo/niki/param/agent/kind_box_req"
|
||||
errmsg "git.gocasts.ir/ebhomengo/niki/pkg/err_msg"
|
||||
httpmsg "git.gocasts.ir/ebhomengo/niki/pkg/http_msg"
|
||||
querier "git.gocasts.ir/ebhomengo/niki/pkg/query_transaction/sql"
|
||||
|
|
|
|||
|
|
@ -1,10 +1,10 @@
|
|||
package agentkindboxreqhandler
|
||||
|
||||
import (
|
||||
param "git.gocasts.ir/ebhomengo/niki/param/agent/kind_box_req"
|
||||
"net/http"
|
||||
|
||||
"git.gocasts.ir/ebhomengo/niki/entity"
|
||||
param "git.gocasts.ir/ebhomengo/niki/param/agent/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"
|
||||
|
|
|
|||
|
|
@ -1,9 +1,9 @@
|
|||
package agentkindboxreqhandler
|
||||
|
||||
import (
|
||||
param "git.gocasts.ir/ebhomengo/niki/param/agent/kind_box_req"
|
||||
"net/http"
|
||||
|
||||
param "git.gocasts.ir/ebhomengo/niki/param/agent/kind_box_req"
|
||||
"git.gocasts.ir/ebhomengo/niki/pkg/claim"
|
||||
httpmsg "git.gocasts.ir/ebhomengo/niki/pkg/http_msg"
|
||||
"github.com/labstack/echo/v4"
|
||||
|
|
|
|||
|
|
@ -1,10 +1,10 @@
|
|||
package benefactorhandler
|
||||
|
||||
import (
|
||||
benefactorparam "git.gocasts.ir/ebhomengo/niki/param/benefactor/benefactor"
|
||||
httpmsg "git.gocasts.ir/ebhomengo/niki/pkg/http_msg"
|
||||
"net/http"
|
||||
|
||||
benefactorparam "git.gocasts.ir/ebhomengo/niki/param/benefactor/benefactor"
|
||||
httpmsg "git.gocasts.ir/ebhomengo/niki/pkg/http_msg"
|
||||
"github.com/labstack/echo/v4"
|
||||
)
|
||||
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@ import (
|
|||
"git.gocasts.ir/ebhomengo/niki/config"
|
||||
adminhandler "git.gocasts.ir/ebhomengo/niki/delivery/http_server/admin/admin"
|
||||
adminagenthandler "git.gocasts.ir/ebhomengo/niki/delivery/http_server/admin/agent"
|
||||
adminbenefactorhandler "git.gocasts.ir/ebhomengo/niki/delivery/http_server/admin/benefactor"
|
||||
adminKindBoxHandler "git.gocasts.ir/ebhomengo/niki/delivery/http_server/admin/kind_box"
|
||||
adminkindboxreqhandler "git.gocasts.ir/ebhomengo/niki/delivery/http_server/admin/kind_box_req"
|
||||
adminrefertimehandler "git.gocasts.ir/ebhomengo/niki/delivery/http_server/admin/refer_time"
|
||||
|
|
@ -30,6 +31,7 @@ type Server struct {
|
|||
adminKindBoxReqHandler adminkindboxreqhandler.Handler
|
||||
adminKindBoxHandler adminKindBoxHandler.Handler
|
||||
adminAgentHandler adminagenthandler.Handler
|
||||
adminBenefactorHandler adminbenefactorhandler.Handler
|
||||
adminReferTimeHandler adminrefertimehandler.Handler
|
||||
agentKindBoxHandler agentkindboxhandler.Handler
|
||||
agentKindBoxReqHandler agentkindboxreqhandler.Handler
|
||||
|
|
@ -51,6 +53,7 @@ func New(
|
|||
adminKindBoxReqHandler: adminkindboxreqhandler.New(svc.AdminAuthSvc, svc.AdminKindBoxReqSvc, svc.AdminAuthorizeSvc, svc.NotificationSvc),
|
||||
adminKindBoxHandler: adminKindBoxHandler.New(svc.AdminAuthSvc, svc.AdminKindBoxSvc, svc.AdminAuthorizeSvc, svc.NotificationSvc),
|
||||
adminAgentHandler: adminagenthandler.New(svc.AdminAuthSvc, svc.AdminAgentSvc, svc.AdminAuthorizeSvc),
|
||||
adminBenefactorHandler: adminbenefactorhandler.New(svc.AdminAuthSvc, svc.AdminBenefactorSvc, svc.AdminAuthorizeSvc),
|
||||
adminReferTimeHandler: adminrefertimehandler.New(svc.AdminAuthSvc, svc.AdminReferTimeSvc, svc.AdminAuthorizeSvc),
|
||||
agentKindBoxHandler: agentkindboxhandler.New(svc.AdminAuthSvc, svc.AgentKindBoxSvc, svc.AdminAuthorizeSvc, svc.NotificationSvc),
|
||||
agentKindBoxReqHandler: agentkindboxreqhandler.New(svc.AdminAuthSvc, svc.AgentKindBoxReqSvc, svc.AdminAuthorizeSvc, svc.NotificationSvc),
|
||||
|
|
@ -93,6 +96,7 @@ func (s Server) RegisterRoutes() {
|
|||
s.adminKindBoxReqHandler.SetRoutes(s.Router)
|
||||
s.adminKindBoxHandler.SetRoutes(s.Router)
|
||||
s.adminReferTimeHandler.SetRoutes(s.Router)
|
||||
s.adminBenefactorHandler.SetRoutes(s.Router)
|
||||
s.agentKindBoxHandler.SetRoutes(s.Router)
|
||||
s.agentKindBoxReqHandler.SetRoutes(s.Router)
|
||||
}
|
||||
|
|
|
|||
199
docs/docs.go
199
docs/docs.go
|
|
@ -48,6 +48,142 @@ const docTemplate = `{
|
|||
}
|
||||
}
|
||||
},
|
||||
"/admins/benefactors": {
|
||||
"get": {
|
||||
"security": [
|
||||
{
|
||||
"AuthBearerAdmin": []
|
||||
}
|
||||
],
|
||||
"consumes": [
|
||||
"application/json"
|
||||
],
|
||||
"produces": [
|
||||
"application/json"
|
||||
],
|
||||
"tags": [
|
||||
"Admins Benefactors"
|
||||
],
|
||||
"summary": "Get all benefactors by admin",
|
||||
"parameters": [
|
||||
{
|
||||
"type": "integer",
|
||||
"description": "Filter by ID",
|
||||
"name": "filter_id",
|
||||
"in": "query"
|
||||
},
|
||||
{
|
||||
"type": "string",
|
||||
"description": "Filter by first_name",
|
||||
"name": "filter_first_name",
|
||||
"in": "query"
|
||||
},
|
||||
{
|
||||
"type": "string",
|
||||
"description": "Filter by last_name",
|
||||
"name": "filter_last_name",
|
||||
"in": "query"
|
||||
},
|
||||
{
|
||||
"type": "string",
|
||||
"description": "Filter by phone_number",
|
||||
"name": "filter_phone_number",
|
||||
"in": "query"
|
||||
},
|
||||
{
|
||||
"type": "string",
|
||||
"description": "Filter by email",
|
||||
"name": "filter_email",
|
||||
"in": "query"
|
||||
},
|
||||
{
|
||||
"enum": [
|
||||
"active",
|
||||
"inactive"
|
||||
],
|
||||
"type": "string",
|
||||
"description": "Filter by status",
|
||||
"name": "filter_status",
|
||||
"in": "query"
|
||||
},
|
||||
{
|
||||
"type": "integer",
|
||||
"description": "Page number",
|
||||
"name": "page_number",
|
||||
"in": "query"
|
||||
},
|
||||
{
|
||||
"type": "integer",
|
||||
"description": "Page size",
|
||||
"name": "page_size",
|
||||
"in": "query"
|
||||
},
|
||||
{
|
||||
"enum": [
|
||||
"id",
|
||||
"first_name",
|
||||
"last_name",
|
||||
"phone_number",
|
||||
"email",
|
||||
"status",
|
||||
"created_at"
|
||||
],
|
||||
"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/adminbenefactoreparam.BenefactorGetAllResponse"
|
||||
}
|
||||
},
|
||||
"400": {
|
||||
"description": "Bad Request",
|
||||
"schema": {
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"401": {
|
||||
"description": "invalid or expired jwt",
|
||||
"schema": {
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"403": {
|
||||
"description": "user not allowed",
|
||||
"schema": {
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"422": {
|
||||
"description": "Unprocessable Entity",
|
||||
"schema": {
|
||||
"$ref": "#/definitions/httpmsg.ErrorResponse"
|
||||
}
|
||||
},
|
||||
"500": {
|
||||
"description": "something went wrong",
|
||||
"schema": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"/admins/kindboxes": {
|
||||
"get": {
|
||||
"security": [
|
||||
|
|
@ -2862,6 +2998,58 @@ const docTemplate = `{
|
|||
}
|
||||
}
|
||||
},
|
||||
"adminbenefactoreparam.BenefactorGetAllResponse": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"data": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"$ref": "#/definitions/adminbenefactoreparam.Data"
|
||||
}
|
||||
},
|
||||
"field_errors": {
|
||||
"type": "object",
|
||||
"additionalProperties": {
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"pagination": {
|
||||
"$ref": "#/definitions/param.PaginationResponse"
|
||||
}
|
||||
}
|
||||
},
|
||||
"adminbenefactoreparam.Data": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"birth_date": {
|
||||
"type": "string"
|
||||
},
|
||||
"description": {
|
||||
"type": "string"
|
||||
},
|
||||
"email": {
|
||||
"type": "string"
|
||||
},
|
||||
"first_name": {
|
||||
"type": "string"
|
||||
},
|
||||
"gender": {
|
||||
"$ref": "#/definitions/entity.Gender"
|
||||
},
|
||||
"id": {
|
||||
"type": "integer"
|
||||
},
|
||||
"last_name": {
|
||||
"type": "string"
|
||||
},
|
||||
"phone_number": {
|
||||
"type": "string"
|
||||
},
|
||||
"status": {
|
||||
"$ref": "#/definitions/entity.BenefactorStatus"
|
||||
}
|
||||
}
|
||||
},
|
||||
"adminkindboxparam.AssignReceiverRequest": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
|
|
@ -4026,6 +4214,17 @@ const docTemplate = `{
|
|||
"AdminInactiveStatus"
|
||||
]
|
||||
},
|
||||
"entity.BenefactorStatus": {
|
||||
"type": "string",
|
||||
"enum": [
|
||||
"active",
|
||||
"inactive"
|
||||
],
|
||||
"x-enum-varnames": [
|
||||
"BenefactorActiveStatus",
|
||||
"BenefactorInactiveStatus"
|
||||
]
|
||||
},
|
||||
"entity.City": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
|
|
|
|||
|
|
@ -37,6 +37,142 @@
|
|||
}
|
||||
}
|
||||
},
|
||||
"/admins/benefactors": {
|
||||
"get": {
|
||||
"security": [
|
||||
{
|
||||
"AuthBearerAdmin": []
|
||||
}
|
||||
],
|
||||
"consumes": [
|
||||
"application/json"
|
||||
],
|
||||
"produces": [
|
||||
"application/json"
|
||||
],
|
||||
"tags": [
|
||||
"Admins Benefactors"
|
||||
],
|
||||
"summary": "Get all benefactors by admin",
|
||||
"parameters": [
|
||||
{
|
||||
"type": "integer",
|
||||
"description": "Filter by ID",
|
||||
"name": "filter_id",
|
||||
"in": "query"
|
||||
},
|
||||
{
|
||||
"type": "string",
|
||||
"description": "Filter by first_name",
|
||||
"name": "filter_first_name",
|
||||
"in": "query"
|
||||
},
|
||||
{
|
||||
"type": "string",
|
||||
"description": "Filter by last_name",
|
||||
"name": "filter_last_name",
|
||||
"in": "query"
|
||||
},
|
||||
{
|
||||
"type": "string",
|
||||
"description": "Filter by phone_number",
|
||||
"name": "filter_phone_number",
|
||||
"in": "query"
|
||||
},
|
||||
{
|
||||
"type": "string",
|
||||
"description": "Filter by email",
|
||||
"name": "filter_email",
|
||||
"in": "query"
|
||||
},
|
||||
{
|
||||
"enum": [
|
||||
"active",
|
||||
"inactive"
|
||||
],
|
||||
"type": "string",
|
||||
"description": "Filter by status",
|
||||
"name": "filter_status",
|
||||
"in": "query"
|
||||
},
|
||||
{
|
||||
"type": "integer",
|
||||
"description": "Page number",
|
||||
"name": "page_number",
|
||||
"in": "query"
|
||||
},
|
||||
{
|
||||
"type": "integer",
|
||||
"description": "Page size",
|
||||
"name": "page_size",
|
||||
"in": "query"
|
||||
},
|
||||
{
|
||||
"enum": [
|
||||
"id",
|
||||
"first_name",
|
||||
"last_name",
|
||||
"phone_number",
|
||||
"email",
|
||||
"status",
|
||||
"created_at"
|
||||
],
|
||||
"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/adminbenefactoreparam.BenefactorGetAllResponse"
|
||||
}
|
||||
},
|
||||
"400": {
|
||||
"description": "Bad Request",
|
||||
"schema": {
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"401": {
|
||||
"description": "invalid or expired jwt",
|
||||
"schema": {
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"403": {
|
||||
"description": "user not allowed",
|
||||
"schema": {
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"422": {
|
||||
"description": "Unprocessable Entity",
|
||||
"schema": {
|
||||
"$ref": "#/definitions/httpmsg.ErrorResponse"
|
||||
}
|
||||
},
|
||||
"500": {
|
||||
"description": "something went wrong",
|
||||
"schema": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"/admins/kindboxes": {
|
||||
"get": {
|
||||
"security": [
|
||||
|
|
@ -2851,6 +2987,58 @@
|
|||
}
|
||||
}
|
||||
},
|
||||
"adminbenefactoreparam.BenefactorGetAllResponse": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"data": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"$ref": "#/definitions/adminbenefactoreparam.Data"
|
||||
}
|
||||
},
|
||||
"field_errors": {
|
||||
"type": "object",
|
||||
"additionalProperties": {
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"pagination": {
|
||||
"$ref": "#/definitions/param.PaginationResponse"
|
||||
}
|
||||
}
|
||||
},
|
||||
"adminbenefactoreparam.Data": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"birth_date": {
|
||||
"type": "string"
|
||||
},
|
||||
"description": {
|
||||
"type": "string"
|
||||
},
|
||||
"email": {
|
||||
"type": "string"
|
||||
},
|
||||
"first_name": {
|
||||
"type": "string"
|
||||
},
|
||||
"gender": {
|
||||
"$ref": "#/definitions/entity.Gender"
|
||||
},
|
||||
"id": {
|
||||
"type": "integer"
|
||||
},
|
||||
"last_name": {
|
||||
"type": "string"
|
||||
},
|
||||
"phone_number": {
|
||||
"type": "string"
|
||||
},
|
||||
"status": {
|
||||
"$ref": "#/definitions/entity.BenefactorStatus"
|
||||
}
|
||||
}
|
||||
},
|
||||
"adminkindboxparam.AssignReceiverRequest": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
|
|
@ -4015,6 +4203,17 @@
|
|||
"AdminInactiveStatus"
|
||||
]
|
||||
},
|
||||
"entity.BenefactorStatus": {
|
||||
"type": "string",
|
||||
"enum": [
|
||||
"active",
|
||||
"inactive"
|
||||
],
|
||||
"x-enum-varnames": [
|
||||
"BenefactorActiveStatus",
|
||||
"BenefactorInactiveStatus"
|
||||
]
|
||||
},
|
||||
"entity.City": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
|
|
|
|||
|
|
@ -123,6 +123,40 @@ definitions:
|
|||
$ref: '#/definitions/adminagentparam.Data'
|
||||
type: array
|
||||
type: object
|
||||
adminbenefactoreparam.BenefactorGetAllResponse:
|
||||
properties:
|
||||
data:
|
||||
items:
|
||||
$ref: '#/definitions/adminbenefactoreparam.Data'
|
||||
type: array
|
||||
field_errors:
|
||||
additionalProperties:
|
||||
type: string
|
||||
type: object
|
||||
pagination:
|
||||
$ref: '#/definitions/param.PaginationResponse'
|
||||
type: object
|
||||
adminbenefactoreparam.Data:
|
||||
properties:
|
||||
birth_date:
|
||||
type: string
|
||||
description:
|
||||
type: string
|
||||
email:
|
||||
type: string
|
||||
first_name:
|
||||
type: string
|
||||
gender:
|
||||
$ref: '#/definitions/entity.Gender'
|
||||
id:
|
||||
type: integer
|
||||
last_name:
|
||||
type: string
|
||||
phone_number:
|
||||
type: string
|
||||
status:
|
||||
$ref: '#/definitions/entity.BenefactorStatus'
|
||||
type: object
|
||||
adminkindboxparam.AssignReceiverRequest:
|
||||
properties:
|
||||
receiver_agent_id:
|
||||
|
|
@ -886,6 +920,14 @@ definitions:
|
|||
x-enum-varnames:
|
||||
- AdminActiveStatus
|
||||
- AdminInactiveStatus
|
||||
entity.BenefactorStatus:
|
||||
enum:
|
||||
- active
|
||||
- inactive
|
||||
type: string
|
||||
x-enum-varnames:
|
||||
- BenefactorActiveStatus
|
||||
- BenefactorInactiveStatus
|
||||
entity.City:
|
||||
properties:
|
||||
id:
|
||||
|
|
@ -1015,6 +1057,97 @@ paths:
|
|||
summary: Get all agents by admin
|
||||
tags:
|
||||
- Admins
|
||||
/admins/benefactors:
|
||||
get:
|
||||
consumes:
|
||||
- application/json
|
||||
parameters:
|
||||
- description: Filter by ID
|
||||
in: query
|
||||
name: filter_id
|
||||
type: integer
|
||||
- description: Filter by first_name
|
||||
in: query
|
||||
name: filter_first_name
|
||||
type: string
|
||||
- description: Filter by last_name
|
||||
in: query
|
||||
name: filter_last_name
|
||||
type: string
|
||||
- description: Filter by phone_number
|
||||
in: query
|
||||
name: filter_phone_number
|
||||
type: string
|
||||
- description: Filter by email
|
||||
in: query
|
||||
name: filter_email
|
||||
type: string
|
||||
- description: Filter by status
|
||||
enum:
|
||||
- active
|
||||
- inactive
|
||||
in: query
|
||||
name: filter_status
|
||||
type: string
|
||||
- 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
|
||||
- first_name
|
||||
- last_name
|
||||
- phone_number
|
||||
- email
|
||||
- status
|
||||
- created_at
|
||||
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/adminbenefactoreparam.BenefactorGetAllResponse'
|
||||
"400":
|
||||
description: Bad Request
|
||||
schema:
|
||||
type: string
|
||||
"401":
|
||||
description: invalid or expired jwt
|
||||
schema:
|
||||
type: string
|
||||
"403":
|
||||
description: user not allowed
|
||||
schema:
|
||||
type: string
|
||||
"422":
|
||||
description: Unprocessable Entity
|
||||
schema:
|
||||
$ref: '#/definitions/httpmsg.ErrorResponse'
|
||||
"500":
|
||||
description: something went wrong
|
||||
schema:
|
||||
type: string
|
||||
security:
|
||||
- AuthBearerAdmin: []
|
||||
summary: Get all benefactors by admin
|
||||
tags:
|
||||
- Admins Benefactors
|
||||
/admins/kindboxes:
|
||||
get:
|
||||
consumes:
|
||||
|
|
|
|||
|
|
@ -1,8 +1,9 @@
|
|||
package adminbenefactoreparam
|
||||
|
||||
import (
|
||||
"git.gocasts.ir/ebhomengo/niki/entity"
|
||||
"time"
|
||||
|
||||
"git.gocasts.ir/ebhomengo/niki/entity"
|
||||
)
|
||||
|
||||
type Data struct {
|
||||
|
|
@ -14,6 +15,5 @@ type Data struct {
|
|||
Email string `json:"email"`
|
||||
Gender entity.Gender `json:"gender"`
|
||||
BirthDate time.Time `json:"birth_date"`
|
||||
Roll entity.UserRole `json:"roll"`
|
||||
Status entity.BenefactorStatus `json:"status"`
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,12 +4,12 @@ import (
|
|||
"git.gocasts.ir/ebhomengo/niki/param"
|
||||
)
|
||||
|
||||
type GetAllBenefactorRequest struct {
|
||||
type BenefactorGetAllRequest struct {
|
||||
Pagination param.PaginationRequest
|
||||
Sort param.SortRequest
|
||||
Filter param.FilterRequest
|
||||
}
|
||||
type GetAllBenefactorResponse struct {
|
||||
type BenefactorGetAllResponse struct {
|
||||
Data []Data `json:"data"`
|
||||
Pagination param.PaginationResponse `json:"pagination"`
|
||||
FieldErrors map[string]string `json:"field_errors,omitempty"`
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ import (
|
|||
"time"
|
||||
)
|
||||
|
||||
//when kindbox creates, which fields are
|
||||
// when kindbox creates, which fields are
|
||||
type KindBoxUpdateRequest struct {
|
||||
KindBoxID uint `json:"-" param:"id" example:"1"` // ID is passed in the URL path
|
||||
BenefactorID uint `json:"benefactor_id" example:"1"`
|
||||
|
|
|
|||
|
|
@ -1,8 +1,9 @@
|
|||
package adminkindboxreqparam
|
||||
|
||||
import (
|
||||
entity "git.gocasts.ir/ebhomengo/niki/entity"
|
||||
"time"
|
||||
|
||||
entity "git.gocasts.ir/ebhomengo/niki/entity"
|
||||
)
|
||||
|
||||
type KindBoxReqAddRequest struct {
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@ package mysqlquerybuilder
|
|||
import (
|
||||
"fmt"
|
||||
"regexp"
|
||||
"strings"
|
||||
)
|
||||
|
||||
var datePattern = regexp.MustCompile(`^\d{4}-\d{2}-\d{2}(T\d{2}:\d{2}:\d{2}Z)?$`)
|
||||
|
|
@ -11,16 +12,30 @@ func isValidDateOrDateTime(value string) bool {
|
|||
return datePattern.MatchString(value)
|
||||
}
|
||||
|
||||
func BuildFilterQuery(filter map[string]interface{}) (filterQuery string, args []any) {
|
||||
func BuildFilterQuery(baseQuery 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) {
|
||||
filterQuery += fmt.Sprintf("AND DATE(%s) = ? ", key)
|
||||
conditions = append(conditions, fmt.Sprintf("DATE(%s) = ?", key))
|
||||
args = append(args, strVal)
|
||||
} else {
|
||||
filterQuery += fmt.Sprintf("AND %s = ? ", key)
|
||||
conditions = append(conditions, fmt.Sprintf("%s = ?", key))
|
||||
args = append(args, value)
|
||||
}
|
||||
}
|
||||
|
||||
return filterQuery, args
|
||||
query := baseQuery
|
||||
|
||||
if len(conditions) > 0 {
|
||||
if strings.Contains(strings.ToUpper(baseQuery), "WHERE") {
|
||||
query += " AND "
|
||||
} else {
|
||||
query += " WHERE "
|
||||
}
|
||||
query += strings.Join(conditions, " AND ")
|
||||
}
|
||||
|
||||
return query, args
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,17 +7,15 @@ import (
|
|||
)
|
||||
|
||||
func BuildGetAllQuery(baseQuery string, filter param.FilterRequest, pagination param.PaginationRequest, sort param.SortRequest) (query string, args []any) {
|
||||
filterQuery, fArgs := BuildFilterQuery(filter)
|
||||
filterQuery, fArgs := BuildFilterQuery(baseQuery, filter)
|
||||
paginationQuery, pArgs := BuildPaginationQuery(pagination)
|
||||
sortQuery := BuildSortQuery(sort)
|
||||
|
||||
args = append(args, fArgs...)
|
||||
args = append(args, pArgs...)
|
||||
|
||||
query = baseQuery
|
||||
if filterQuery != "" {
|
||||
query = fmt.Sprintf("%s %s", query, filterQuery)
|
||||
}
|
||||
query = filterQuery
|
||||
|
||||
if sortQuery != "" {
|
||||
query = fmt.Sprintf("%s %s", query, sortQuery)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@ package mysqlbenefactor
|
|||
import (
|
||||
"context"
|
||||
"errors"
|
||||
|
||||
"git.gocasts.ir/ebhomengo/niki/entity"
|
||||
richerror "git.gocasts.ir/ebhomengo/niki/pkg/rich_error"
|
||||
)
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@ import (
|
|||
"context"
|
||||
"database/sql"
|
||||
"errors"
|
||||
|
||||
"git.gocasts.ir/ebhomengo/niki/entity"
|
||||
errmsg "git.gocasts.ir/ebhomengo/niki/pkg/err_msg"
|
||||
richerror "git.gocasts.ir/ebhomengo/niki/pkg/rich_error"
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@ package mysqlbenefactor
|
|||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"git.gocasts.ir/ebhomengo/niki/entity"
|
||||
params "git.gocasts.ir/ebhomengo/niki/param"
|
||||
errmsg "git.gocasts.ir/ebhomengo/niki/pkg/err_msg"
|
||||
|
|
@ -37,7 +38,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, pagination, sort)
|
||||
query, args = builder.BuildGetAllQuery(baseQuery, 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)
|
||||
|
|
|
|||
|
|
@ -2,9 +2,10 @@ package mysqlbenefactor
|
|||
|
||||
import (
|
||||
"database/sql"
|
||||
"time"
|
||||
|
||||
"git.gocasts.ir/ebhomengo/niki/entity"
|
||||
"git.gocasts.ir/ebhomengo/niki/repository/mysql"
|
||||
"time"
|
||||
)
|
||||
|
||||
func scanBenefactor(scanner mysql.Scanner) (entity.Benefactor, error) {
|
||||
|
|
|
|||
|
|
@ -5,7 +5,6 @@ import (
|
|||
"database/sql"
|
||||
"time"
|
||||
|
||||
|
||||
"git.gocasts.ir/ebhomengo/niki/entity"
|
||||
errmsg "git.gocasts.ir/ebhomengo/niki/pkg/err_msg"
|
||||
richerror "git.gocasts.ir/ebhomengo/niki/pkg/rich_error"
|
||||
|
|
@ -54,7 +53,7 @@ func (d *DB) UpdateKindBox(ctx context.Context, kindBox entity.KindBox) error {
|
|||
returnedAt = sql.NullTime{Time: time.Time{}, Valid: false}
|
||||
}
|
||||
|
||||
query:= `UPDATE kind_boxes SET
|
||||
query := `UPDATE kind_boxes SET
|
||||
benefactor_id = ?, type = ?, amount = ?, serial_number = ?, status = ?, deliver_refer_time_id = ?, deliver_refer_date = ?, deliver_address_id = ?,
|
||||
sender_agent_id = ?, delivered_at = ?, return_refer_time_id = ?, return_refer_date = ?, return_address_id = ?, receiver_agent_id = ?, returned_at = ?
|
||||
WHERE
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@ package mysqlkindboxreq
|
|||
|
||||
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"
|
||||
|
|
|
|||
|
|
@ -0,0 +1,25 @@
|
|||
-- +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'
|
||||
) NOT NULL;
|
||||
|
||||
-- +migrate Down
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
-- +migrate Up
|
||||
INSERT INTO `admin_access_controls` (`actor_id`, `actor_type`,`permission`)
|
||||
VALUES
|
||||
(1 , 'role', 'benefactor-getall'),
|
||||
(2 , 'role', 'benefactor-getall');
|
||||
|
||||
-- +migrate Down
|
||||
DELETE FROM `admin_access_controls`;
|
||||
|
|
@ -2,6 +2,7 @@ package adminservice
|
|||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"git.gocasts.ir/ebhomengo/niki/entity"
|
||||
adminserviceparam "git.gocasts.ir/ebhomengo/niki/param/admin/admin"
|
||||
errmsg "git.gocasts.ir/ebhomengo/niki/pkg/err_msg"
|
||||
|
|
|
|||
|
|
@ -3,10 +3,10 @@ package adminservice
|
|||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"git.gocasts.ir/ebhomengo/niki/service/auth"
|
||||
|
||||
"git.gocasts.ir/ebhomengo/niki/config"
|
||||
"git.gocasts.ir/ebhomengo/niki/entity"
|
||||
"git.gocasts.ir/ebhomengo/niki/service/auth"
|
||||
validator "git.gocasts.ir/ebhomengo/niki/validator/admin/admin"
|
||||
"golang.org/x/crypto/bcrypt"
|
||||
)
|
||||
|
|
|
|||
|
|
@ -2,23 +2,29 @@ package adminbenefactorservice
|
|||
|
||||
import (
|
||||
"context"
|
||||
|
||||
paginationparam "git.gocasts.ir/ebhomengo/niki/param"
|
||||
param "git.gocasts.ir/ebhomengo/niki/param/admin/benefactor"
|
||||
richerror "git.gocasts.ir/ebhomengo/niki/pkg/rich_error"
|
||||
)
|
||||
|
||||
func (s Service) GetAllBenefactor(ctx context.Context, req param.GetAllBenefactorRequest) (param.GetAllBenefactorResponse, error) {
|
||||
func (s Service) GetAllBenefactor(ctx context.Context, req param.BenefactorGetAllRequest) (param.BenefactorGetAllResponse, error) {
|
||||
const op = "adminbenefactorservice.GetAllBenefactor"
|
||||
|
||||
benefactorInfo := make([]param.Data, 0)
|
||||
if fieldErrors, vErr := s.vld.ValidateGetAll(req); vErr != nil {
|
||||
return param.BenefactorGetAllResponse{FieldErrors: fieldErrors}, richerror.New(op).WithErr(vErr)
|
||||
}
|
||||
req.Pagination.GetPageSize()
|
||||
req.Pagination.GetPageNumber()
|
||||
|
||||
benefactors, total, err := s.benefactorSvc.GetAllBenefactors(ctx, req.Filter, req.Pagination, req.Sort)
|
||||
benefactors, total, err := s.repo.GetAllBenefactor(ctx, req.Filter, req.Pagination, req.Sort)
|
||||
if err != nil {
|
||||
return param.GetAllBenefactorResponse{}, richerror.New(op).WithErr(err).WithKind(richerror.KindUnexpected)
|
||||
return param.BenefactorGetAllResponse{}, richerror.New(op).WithErr(err).WithKind(richerror.KindUnexpected)
|
||||
}
|
||||
|
||||
resp := make([]param.Data, 0)
|
||||
for _, benefactor := range benefactors {
|
||||
benefactorInfo = append(benefactorInfo, param.Data{
|
||||
resp = append(resp, param.Data{
|
||||
ID: benefactor.ID,
|
||||
FirstName: benefactor.FirstName,
|
||||
LastName: benefactor.LastName,
|
||||
|
|
@ -27,14 +33,16 @@ func (s Service) GetAllBenefactor(ctx context.Context, req param.GetAllBenefacto
|
|||
Email: benefactor.Email,
|
||||
Gender: benefactor.Gender,
|
||||
BirthDate: benefactor.BirthDate,
|
||||
Roll: benefactor.Role,
|
||||
Status: benefactor.Status,
|
||||
})
|
||||
}
|
||||
|
||||
return param.GetAllBenefactorResponse{Data: benefactorInfo, Pagination: paginationparam.PaginationResponse{
|
||||
return param.BenefactorGetAllResponse{
|
||||
Data: resp,
|
||||
Pagination: paginationparam.PaginationResponse{
|
||||
PageSize: req.Pagination.PageSize,
|
||||
PageNumber: req.Pagination.PageNumber,
|
||||
Total: total,
|
||||
}}, nil
|
||||
},
|
||||
}, nil
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,18 +2,17 @@ package adminbenefactorservice
|
|||
|
||||
import (
|
||||
"context"
|
||||
"git.gocasts.ir/ebhomengo/niki/param"
|
||||
|
||||
"git.gocasts.ir/ebhomengo/niki/entity"
|
||||
"git.gocasts.ir/ebhomengo/niki/param"
|
||||
adminaddressparam "git.gocasts.ir/ebhomengo/niki/param/admin/address"
|
||||
validator "git.gocasts.ir/ebhomengo/niki/validator/admin/benefactor"
|
||||
)
|
||||
|
||||
type BenefactorSvc interface {
|
||||
GetAllBenefactors(ctx context.Context, filter param.FilterRequest, pagination param.PaginationRequest, sort param.SortRequest) ([]entity.Benefactor, uint, error)
|
||||
}
|
||||
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)
|
||||
}
|
||||
type AddressSvc interface {
|
||||
GetAddressByID(ctx context.Context, request adminaddressparam.AddressGetRequest) (adminaddressparam.AddressGetResponse, error)
|
||||
|
|
@ -22,9 +21,9 @@ type AddressSvc interface {
|
|||
type Service struct {
|
||||
repo Repository
|
||||
addressSvc AddressSvc
|
||||
benefactorSvc BenefactorSvc
|
||||
vld validator.Validator
|
||||
}
|
||||
|
||||
func New(repo Repository, addressSvc AddressSvc, benefactorSvc BenefactorSvc) Service {
|
||||
return Service{repo: repo, addressSvc: addressSvc, benefactorSvc: benefactorSvc}
|
||||
func New(repo Repository, addressSvc AddressSvc, vld validator.Validator) Service {
|
||||
return Service{repo: repo, addressSvc: addressSvc, vld: vld}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@ package adminkindboxreqservice
|
|||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"git.gocasts.ir/ebhomengo/niki/entity"
|
||||
param "git.gocasts.ir/ebhomengo/niki/param/admin/kind_box_req"
|
||||
richerror "git.gocasts.ir/ebhomengo/niki/pkg/rich_error"
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@ package agentkindboxservice
|
|||
|
||||
import (
|
||||
"context"
|
||||
|
||||
entity "git.gocasts.ir/ebhomengo/niki/entity"
|
||||
param "git.gocasts.ir/ebhomengo/niki/param/agent/kind_box"
|
||||
richerror "git.gocasts.ir/ebhomengo/niki/pkg/rich_error"
|
||||
|
|
|
|||
|
|
@ -2,10 +2,10 @@ package agentkindboxreqservice
|
|||
|
||||
import (
|
||||
"context"
|
||||
kindboxParam "git.gocasts.ir/ebhomengo/niki/param/agent/kind_box"
|
||||
param "git.gocasts.ir/ebhomengo/niki/param/agent/kind_box_req"
|
||||
"time"
|
||||
|
||||
kindboxParam "git.gocasts.ir/ebhomengo/niki/param/agent/kind_box"
|
||||
param "git.gocasts.ir/ebhomengo/niki/param/agent/kind_box_req"
|
||||
richerror "git.gocasts.ir/ebhomengo/niki/pkg/rich_error"
|
||||
)
|
||||
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@ package agentkindboxreqservice
|
|||
|
||||
import (
|
||||
"context"
|
||||
|
||||
param "git.gocasts.ir/ebhomengo/niki/param/agent/kind_box_req"
|
||||
richerror "git.gocasts.ir/ebhomengo/niki/pkg/rich_error"
|
||||
)
|
||||
|
|
|
|||
|
|
@ -2,10 +2,10 @@ package agentkindboxreqservice
|
|||
|
||||
import (
|
||||
"context"
|
||||
param "git.gocasts.ir/ebhomengo/niki/param/agent/kind_box"
|
||||
|
||||
"git.gocasts.ir/ebhomengo/niki/entity"
|
||||
params "git.gocasts.ir/ebhomengo/niki/param"
|
||||
param "git.gocasts.ir/ebhomengo/niki/param/agent/kind_box"
|
||||
validator "git.gocasts.ir/ebhomengo/niki/validator/agent/kind_box_req"
|
||||
)
|
||||
|
||||
|
|
|
|||
|
|
@ -1,9 +1,10 @@
|
|||
package auth
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"git.gocasts.ir/ebhomengo/niki/entity"
|
||||
"github.com/golang-jwt/jwt/v4"
|
||||
"time"
|
||||
)
|
||||
|
||||
func (s Service) CreateAccessToken(user entity.Authenticable) (string, error) {
|
||||
|
|
|
|||
|
|
@ -2,9 +2,10 @@ package auth
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
errmsg "git.gocasts.ir/ebhomengo/niki/pkg/err_msg"
|
||||
"github.com/golang-jwt/jwt/v4"
|
||||
"strings"
|
||||
)
|
||||
|
||||
func (s Service) ParseBearerToken(bearerToken string) (*Claims, error) {
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@ package benefactorservice
|
|||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"git.gocasts.ir/ebhomengo/niki/entity"
|
||||
benefactorparam "git.gocasts.ir/ebhomengo/niki/param/benefactor/benefactor"
|
||||
errmsg "git.gocasts.ir/ebhomengo/niki/pkg/err_msg"
|
||||
|
|
|
|||
|
|
@ -2,11 +2,11 @@ package benefactorservice
|
|||
|
||||
import (
|
||||
"context"
|
||||
"git.gocasts.ir/ebhomengo/niki/service/auth"
|
||||
"time"
|
||||
|
||||
smscontract "git.gocasts.ir/ebhomengo/niki/contract/sms"
|
||||
"git.gocasts.ir/ebhomengo/niki/entity"
|
||||
"git.gocasts.ir/ebhomengo/niki/service/auth"
|
||||
benefactorvalidator "git.gocasts.ir/ebhomengo/niki/validator/benefactor/benefactor"
|
||||
)
|
||||
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@ package notification
|
|||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"git.gocasts.ir/ebhomengo/niki/param"
|
||||
bnfparam "git.gocasts.ir/ebhomengo/niki/param/admin/benefactor"
|
||||
kbp "git.gocasts.ir/ebhomengo/niki/param/admin/kind_box"
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@ package notification
|
|||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"git.gocasts.ir/ebhomengo/niki/param"
|
||||
bnfparam "git.gocasts.ir/ebhomengo/niki/param/admin/benefactor"
|
||||
kbparam "git.gocasts.ir/ebhomengo/niki/param/admin/kind_box_req"
|
||||
|
|
|
|||
|
|
@ -31,6 +31,7 @@ import (
|
|||
benefactorrefertimeservice "git.gocasts.ir/ebhomengo/niki/service/benefactor/refer_time"
|
||||
"git.gocasts.ir/ebhomengo/niki/service/notification"
|
||||
adminvalidator "git.gocasts.ir/ebhomengo/niki/validator/admin/admin"
|
||||
adminbenefactorvalidator "git.gocasts.ir/ebhomengo/niki/validator/admin/benefactor"
|
||||
adminkindboxvalidator "git.gocasts.ir/ebhomengo/niki/validator/admin/kind_box"
|
||||
adminkindboxreqvalidator "git.gocasts.ir/ebhomengo/niki/validator/admin/kind_box_req"
|
||||
agentkindboxvalidator "git.gocasts.ir/ebhomengo/niki/validator/agent/kind_box"
|
||||
|
|
@ -48,6 +49,7 @@ type Service struct {
|
|||
AdminAuthorizeSvc adminauthorizationservice.Service
|
||||
AdminSvc adminservice.Service
|
||||
AdminAgentSvc adminagentservice.Service
|
||||
AdminBenefactorSvc adminbenefactorservice.Service
|
||||
AgentKindBoxSvc agentkindboxservice.Service
|
||||
AgentKindBoxReqSvc agentkindboxreqservice.Service
|
||||
BenefactorAuthSvc auth.Service
|
||||
|
|
@ -76,7 +78,8 @@ func New(cfg config.Config, db *mysql.DB, rds *redis.Adapter, smsAdapter smscont
|
|||
AdminAuthorizeSvc = adminauthorizationservice.New(adminRepo)
|
||||
AdminReferTimeSvc = adminrefertimeservice.New(referTimeRepo)
|
||||
AdminAddressSvc = adminaddressservice.New(addressRepo)
|
||||
AdminBenefactorSvc = adminbenefactorservice.New(benefactorRepo, AdminAddressSvc)
|
||||
AdminBenefactorVld = adminbenefactorvalidator.New()
|
||||
AdminBenefactorSvc = adminbenefactorservice.New(benefactorRepo, AdminAddressSvc, AdminBenefactorVld)
|
||||
AdminAgentSvc = adminagentservice.New(agentRepo)
|
||||
|
||||
AdminVld = adminvalidator.New(adminRepo)
|
||||
|
|
@ -116,6 +119,7 @@ func New(cfg config.Config, db *mysql.DB, rds *redis.Adapter, smsAdapter smscont
|
|||
AdminAuthorizeSvc: AdminAuthorizeSvc,
|
||||
AdminSvc: AdminSvc,
|
||||
AdminAgentSvc: AdminAgentSvc,
|
||||
AdminBenefactorSvc: AdminBenefactorSvc,
|
||||
AgentKindBoxSvc: AgentKindBoxSvc,
|
||||
AgentKindBoxReqSvc: AgentKindBoxReqSvc,
|
||||
BenefactorAuthSvc: BenefactorAuthSvc,
|
||||
|
|
|
|||
|
|
@ -3,9 +3,9 @@ package adminvalidator
|
|||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"git.gocasts.ir/ebhomengo/niki/entity"
|
||||
"testing"
|
||||
|
||||
"git.gocasts.ir/ebhomengo/niki/entity"
|
||||
adminserviceparam "git.gocasts.ir/ebhomengo/niki/param/admin/admin"
|
||||
errmsg "git.gocasts.ir/ebhomengo/niki/pkg/err_msg"
|
||||
"github.com/stretchr/testify/assert"
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@ package adminvalidator
|
|||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"git.gocasts.ir/ebhomengo/niki/entity"
|
||||
errmsg "git.gocasts.ir/ebhomengo/niki/pkg/err_msg"
|
||||
validation "github.com/go-ozzo/ozzo-validation/v4"
|
||||
|
|
|
|||
|
|
@ -1 +1,41 @@
|
|||
package benefactor
|
||||
package adminbenefactorvalidator
|
||||
|
||||
import (
|
||||
"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) ValidateGetAll(req param.BenefactorGetAllRequest) (map[string]string, error) {
|
||||
const op = "adminbenefactorvalidator.ValidateGetAll"
|
||||
|
||||
validFields := []string{"id", "first_name", "last_name", "phone_number", "email", "status", "created_at"}
|
||||
|
||||
if err := validation.ValidateStruct(&req,
|
||||
validation.Field(&req.Filter, validation.By(v.AreFilterFieldsValid(validFields))),
|
||||
validation.Field(&req.Sort, validation.By(v.AreSortFieldsValid(validFields))),
|
||||
); err != nil {
|
||||
|
||||
fieldErrors := make(map[string]string)
|
||||
|
||||
var errV validation.Errors
|
||||
if errors.As(err, &errV) {
|
||||
for key, value := range errV {
|
||||
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 map[string]string{}, nil
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1 +1,52 @@
|
|||
package benefactor
|
||||
package adminbenefactorvalidator
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"slices"
|
||||
|
||||
params "git.gocasts.ir/ebhomengo/niki/param"
|
||||
errmsg "git.gocasts.ir/ebhomengo/niki/pkg/err_msg"
|
||||
validation "github.com/go-ozzo/ozzo-validation/v4"
|
||||
)
|
||||
|
||||
type Validator struct{}
|
||||
|
||||
func New() Validator {
|
||||
return Validator{}
|
||||
}
|
||||
|
||||
func (v Validator) AreSortFieldsValid(validSortFields []string) validation.RuleFunc {
|
||||
return func(value interface{}) error {
|
||||
sort, ok := value.(params.SortRequest)
|
||||
if !ok {
|
||||
return fmt.Errorf(errmsg.ErrorMsgSomethingWentWrong)
|
||||
}
|
||||
if sort.Field == "" && sort.Direction != "" {
|
||||
return fmt.Errorf(errmsg.ErrorMsgSortFieldIsRequired)
|
||||
}
|
||||
if sort.Direction != "" && sort.Direction != params.AscSortDirection && sort.Direction != params.DescSortDirection {
|
||||
return fmt.Errorf(errmsg.ErrorMsgSortDirectionShouldBeAscOrDesc)
|
||||
}
|
||||
if sort.Field != "" && !slices.Contains(validSortFields, sort.Field) {
|
||||
return fmt.Errorf(errmsg.ErrorMsgSortFieldIsNotValid)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
func (v Validator) AreFilterFieldsValid(validFilters []string) validation.RuleFunc {
|
||||
return func(value interface{}) error {
|
||||
filters, ok := value.(params.FilterRequest)
|
||||
if !ok {
|
||||
return fmt.Errorf(errmsg.ErrorMsgSomethingWentWrong)
|
||||
}
|
||||
for filter := range filters {
|
||||
if !slices.Contains(validFilters, filter) {
|
||||
return fmt.Errorf(errmsg.ErrorMsgFiltersAreNotValid)
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -19,7 +19,6 @@ func (v Validator) ValidateEnumerate(ctx context.Context, req param.EnumerateKin
|
|||
validation.By(v.CheckKindBoxStatusForEnumeration(ctx))),
|
||||
|
||||
validation.Field(&req.Amount, validation.Required),
|
||||
|
||||
); err != nil {
|
||||
fieldErrors := make(map[string]string)
|
||||
|
||||
|
|
|
|||
|
|
@ -22,7 +22,6 @@ func (v Validator) ValidateUpdateRequest(ctx context.Context, req param.KindBoxU
|
|||
validation.By(v.doesBenefactorExist(ctx)),
|
||||
validation.By(v.doesBenefactorHaveKindBox(ctx, req.KindBoxID, req.BenefactorID))),
|
||||
)
|
||||
|
||||
if err != nil {
|
||||
fieldErrors := make(map[string]string)
|
||||
v.processValidationErrors(err, fieldErrors)
|
||||
|
|
|
|||
|
|
@ -5,19 +5,16 @@ import (
|
|||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"git.gocasts.ir/ebhomengo/niki/entity"
|
||||
adminupdateparam "git.gocasts.ir/ebhomengo/niki/param/admin/kind_box"
|
||||
benefactorserviceparam "git.gocasts.ir/ebhomengo/niki/param/admin/benefactor"
|
||||
agentserviceparam "git.gocasts.ir/ebhomengo/niki/param/admin/agent"
|
||||
addressserviceparam "git.gocasts.ir/ebhomengo/niki/param/admin/address"
|
||||
agentserviceparam "git.gocasts.ir/ebhomengo/niki/param/admin/agent"
|
||||
benefactorserviceparam "git.gocasts.ir/ebhomengo/niki/param/admin/benefactor"
|
||||
adminupdateparam "git.gocasts.ir/ebhomengo/niki/param/admin/kind_box"
|
||||
refertimeserviceparam "git.gocasts.ir/ebhomengo/niki/param/admin/refer_time"
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
|
||||
|
||||
func TestValidator_ValidateUpdateRequest(t *testing.T) {
|
||||
|
||||
now := time.Now()
|
||||
twoDaysLater := now.Add(48 * time.Hour)
|
||||
threeDaysLater := now.Add(52 * time.Hour)
|
||||
|
|
@ -31,7 +28,6 @@ func TestValidator_ValidateUpdateRequest(t *testing.T) {
|
|||
validator := New(mockRepository, mockAgentSvc, mockBenefactorSvc, mockReferTimeSvc, mockAddressSvc)
|
||||
ctx := context.Background()
|
||||
|
||||
|
||||
t.Run("KindBox Delivered And Benefactor Does Not Exist", func(t *testing.T) {
|
||||
req := adminupdateparam.KindBoxUpdateRequest{
|
||||
KindBoxID: 1,
|
||||
|
|
@ -46,13 +42,11 @@ func TestValidator_ValidateUpdateRequest(t *testing.T) {
|
|||
mockRepository.EXPECT().GetKindBox(ctx, req.KindBoxID).
|
||||
Return(entity.KindBox{Status: entity.KindBoxDeliveredStatus}, nil).Once()
|
||||
|
||||
|
||||
fieldErrors, err := validator.ValidateUpdateRequest(ctx, req)
|
||||
|
||||
assert.Error(t, err)
|
||||
assert.NotNil(t, fieldErrors)
|
||||
assert.Contains(t, fieldErrors, "benefactor_id")
|
||||
|
||||
})
|
||||
|
||||
t.Run("KindBox Does Not Exist", func(t *testing.T) {
|
||||
|
|
@ -76,7 +70,6 @@ func TestValidator_ValidateUpdateRequest(t *testing.T) {
|
|||
assert.Contains(t, fieldErrors, "KindBoxID")
|
||||
})
|
||||
|
||||
|
||||
t.Run("KindBox Delivered And Does Not Belong to Benefactor", func(t *testing.T) {
|
||||
req := adminupdateparam.KindBoxUpdateRequest{
|
||||
KindBoxID: 1,
|
||||
|
|
@ -110,14 +103,11 @@ func TestValidator_ValidateUpdateRequest(t *testing.T) {
|
|||
mockRepository.EXPECT().GetKindBox(ctx, req.KindBoxID).
|
||||
Return(entity.KindBox{}, nil).Once()
|
||||
|
||||
|
||||
fieldErrors, err := validator.ValidateUpdateRequest(ctx, req)
|
||||
|
||||
assert.Error(t, err)
|
||||
assert.NotNil(t, fieldErrors)
|
||||
assert.Contains(t, fieldErrors, "KindBoxID")
|
||||
|
||||
|
||||
})
|
||||
|
||||
t.Run("BenefactorID is Null", func(t *testing.T) {
|
||||
|
|
@ -131,7 +121,6 @@ func TestValidator_ValidateUpdateRequest(t *testing.T) {
|
|||
mockRepository.EXPECT().GetKindBox(ctx, req.KindBoxID).
|
||||
Return(entity.KindBox{Status: entity.KindBoxDeliveredStatus, BenefactorID: 1}, nil).Once() // Note the different BenefactorID
|
||||
|
||||
|
||||
fieldErrors, err := validator.ValidateUpdateRequest(ctx, req)
|
||||
|
||||
assert.Error(t, err)
|
||||
|
|
@ -139,7 +128,6 @@ func TestValidator_ValidateUpdateRequest(t *testing.T) {
|
|||
assert.Contains(t, fieldErrors, "benefactor_id")
|
||||
})
|
||||
|
||||
|
||||
t.Run("Valid KindBox Delivered Request", func(t *testing.T) {
|
||||
req := adminupdateparam.KindBoxUpdateRequest{
|
||||
KindBoxID: 1,
|
||||
|
|
@ -179,14 +167,13 @@ func TestValidator_ValidateUpdateRequest(t *testing.T) {
|
|||
addressExm := entity.Address{
|
||||
ID: 23,
|
||||
PostalCode: "1231231231",
|
||||
Address : "Tehran",
|
||||
Name : "Home",
|
||||
CityID : 1,
|
||||
Address: "Tehran",
|
||||
Name: "Home",
|
||||
CityID: 1,
|
||||
ProvinceID: 1,
|
||||
BenefactorID: 2,
|
||||
}
|
||||
|
||||
|
||||
mockRepository.EXPECT().KindBoxExist(ctx, req.KindBoxID).
|
||||
Return(true, nil).Once()
|
||||
|
||||
|
|
@ -205,7 +192,6 @@ func TestValidator_ValidateUpdateRequest(t *testing.T) {
|
|||
mockRepository.EXPECT().GetKindBox(ctx, uint(req.KindBoxID)).
|
||||
Return(entity.KindBox{Status: entity.KindBoxReadyToReturnStatus, BenefactorID: req.BenefactorID}, nil).Once()
|
||||
|
||||
|
||||
fieldErrors, err := validator.ValidateUpdateRequest(ctx, req)
|
||||
|
||||
assert.Error(t, err)
|
||||
|
|
@ -250,7 +236,6 @@ func TestValidator_ValidateUpdateRequest(t *testing.T) {
|
|||
mockRepository.EXPECT().GetKindBox(ctx, req.KindBoxID).
|
||||
Return(entity.KindBox{Status: entity.KindBoxReadyToReturnStatus, BenefactorID: req.BenefactorID}, nil).Once()
|
||||
|
||||
|
||||
fieldErrors, err := validator.ValidateUpdateRequest(ctx, req)
|
||||
|
||||
assert.Error(t, err)
|
||||
|
|
@ -258,7 +243,6 @@ func TestValidator_ValidateUpdateRequest(t *testing.T) {
|
|||
assert.Contains(t, fieldErrors, "return_refere_time_id")
|
||||
})
|
||||
|
||||
|
||||
t.Run("Valid KindBox Ready to Return Status Request", func(t *testing.T) {
|
||||
req := adminupdateparam.KindBoxUpdateRequest{
|
||||
KindBoxID: 1,
|
||||
|
|
@ -293,7 +277,6 @@ func TestValidator_ValidateUpdateRequest(t *testing.T) {
|
|||
mockRepository.EXPECT().GetKindBox(ctx, req.KindBoxID).
|
||||
Return(entity.KindBox{Status: entity.KindBoxReadyToReturnStatus, BenefactorID: req.BenefactorID}, nil).Once()
|
||||
|
||||
|
||||
mockAddressSvc.EXPECT().GetAddressByID(ctx, addressserviceparam.AddressGetRequest{AddressID: req.ReturnAddressID}).
|
||||
Return(addressserviceparam.AddressGetResponse{Address: validAddress}, nil).Once()
|
||||
|
||||
|
|
@ -303,7 +286,6 @@ func TestValidator_ValidateUpdateRequest(t *testing.T) {
|
|||
mockRepository.EXPECT().GetKindBox(ctx, uint(1)).
|
||||
Return(entity.KindBox{Status: entity.KindBoxReadyToReturnStatus, BenefactorID: req.BenefactorID}, nil).Once()
|
||||
|
||||
|
||||
fieldErrors, err := validator.ValidateUpdateRequest(ctx, req)
|
||||
|
||||
assert.NoError(t, err)
|
||||
|
|
@ -326,7 +308,7 @@ func TestValidator_ValidateUpdateRequest(t *testing.T) {
|
|||
|
||||
assert.Error(t, err)
|
||||
assert.NotNil(t, fieldErrors)
|
||||
assert.Contains(t, fieldErrors, "Return Refer Date" )
|
||||
assert.Contains(t, fieldErrors, "Return Refer Date")
|
||||
})
|
||||
|
||||
t.Run("Assigned Receiver Agent Status And ReturnAddressID Not Null", func(t *testing.T) {
|
||||
|
|
@ -345,7 +327,7 @@ func TestValidator_ValidateUpdateRequest(t *testing.T) {
|
|||
|
||||
assert.Error(t, err)
|
||||
assert.NotNil(t, fieldErrors)
|
||||
assert.Contains(t, fieldErrors, "Return Address ID" )
|
||||
assert.Contains(t, fieldErrors, "Return Address ID")
|
||||
})
|
||||
|
||||
t.Run("Valid KindBox Assigned Receiver Agent Status Request", func(t *testing.T) {
|
||||
|
|
@ -355,7 +337,6 @@ func TestValidator_ValidateUpdateRequest(t *testing.T) {
|
|||
ReceiverAgentID: 1,
|
||||
}
|
||||
|
||||
|
||||
mockRepository.EXPECT().KindBoxExist(ctx, req.KindBoxID).Return(true, nil).Once()
|
||||
|
||||
mockBenefactorSvc.EXPECT().BenefactorExistByID(ctx, benefactorserviceparam.BenefactorExistByIDRequest{ID: req.BenefactorID}).
|
||||
|
|
@ -394,7 +375,6 @@ func TestValidator_ValidateUpdateRequest(t *testing.T) {
|
|||
|
||||
assert.Error(t, err)
|
||||
assert.NotNil(t, fieldErrors)
|
||||
|
||||
})
|
||||
|
||||
t.Run("Invalid KindBox Enumerate Status Amount", func(t *testing.T) {
|
||||
|
|
@ -404,13 +384,11 @@ func TestValidator_ValidateUpdateRequest(t *testing.T) {
|
|||
Amount: 0,
|
||||
}
|
||||
|
||||
|
||||
mockRepository.EXPECT().KindBoxExist(ctx, req.KindBoxID).Return(true, nil).Once()
|
||||
|
||||
mockBenefactorSvc.EXPECT().BenefactorExistByID(ctx, benefactorserviceparam.BenefactorExistByIDRequest{ID: req.BenefactorID}).
|
||||
Return(benefactorserviceparam.BenefactorExistByIDResponse{Existed: true}, nil).Once()
|
||||
|
||||
|
||||
mockRepository.EXPECT().GetKindBox(ctx, req.KindBoxID).
|
||||
Return(entity.KindBox{
|
||||
Status: entity.KindBoxEnumeratedStatus,
|
||||
|
|
@ -421,10 +399,9 @@ func TestValidator_ValidateUpdateRequest(t *testing.T) {
|
|||
|
||||
assert.Error(t, err)
|
||||
assert.NotNil(t, fieldErrors)
|
||||
assert.Contains(t, fieldErrors, "amount" )
|
||||
assert.Contains(t, fieldErrors, "amount")
|
||||
})
|
||||
|
||||
|
||||
t.Run("Valid KindBox Enumerated Status Request", func(t *testing.T) {
|
||||
req := adminupdateparam.KindBoxUpdateRequest{
|
||||
KindBoxID: 1,
|
||||
|
|
@ -432,13 +409,11 @@ func TestValidator_ValidateUpdateRequest(t *testing.T) {
|
|||
Amount: 100,
|
||||
}
|
||||
|
||||
|
||||
mockRepository.EXPECT().KindBoxExist(ctx, req.KindBoxID).Return(true, nil).Once()
|
||||
|
||||
mockBenefactorSvc.EXPECT().BenefactorExistByID(ctx, benefactorserviceparam.BenefactorExistByIDRequest{ID: req.BenefactorID}).
|
||||
Return(benefactorserviceparam.BenefactorExistByIDResponse{Existed: true}, nil).Once()
|
||||
|
||||
|
||||
mockRepository.EXPECT().GetKindBox(ctx, req.KindBoxID).
|
||||
Return(entity.KindBox{
|
||||
Status: entity.KindBoxEnumeratedStatus,
|
||||
|
|
|
|||
|
|
@ -4,11 +4,11 @@ import (
|
|||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
params "git.gocasts.ir/ebhomengo/niki/param"
|
||||
"slices"
|
||||
"time"
|
||||
|
||||
entity "git.gocasts.ir/ebhomengo/niki/entity"
|
||||
params "git.gocasts.ir/ebhomengo/niki/param"
|
||||
adminaddressparam "git.gocasts.ir/ebhomengo/niki/param/admin/address"
|
||||
agentparam "git.gocasts.ir/ebhomengo/niki/param/admin/agent"
|
||||
param "git.gocasts.ir/ebhomengo/niki/param/admin/benefactor"
|
||||
|
|
@ -106,7 +106,6 @@ func (v Validator) doesBenefactorHaveKindBox(ctx context.Context, kindBoxID uint
|
|||
|
||||
fetchedKindBox, err := v.repo.GetKindBox(ctx, kindBoxID)
|
||||
if err != nil {
|
||||
|
||||
return richerror.New(op).WithErr(err).WithMessage("could not fetch KindBox").WithKind(richerror.KindUnexpected)
|
||||
}
|
||||
|
||||
|
|
@ -191,6 +190,7 @@ func (v Validator) CheckKindBoxStatusForEnumeration(ctx context.Context) validat
|
|||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
func (v Validator) doesBenefactorAddressExist(ctx context.Context, kindBoxID uint, benefactorID uint, addressID uint) validation.RuleFunc {
|
||||
return func(value interface{}) error {
|
||||
const op = "Validator.doesBenefactorAddressExist"
|
||||
|
|
|
|||
|
|
@ -3,9 +3,9 @@ package agentkindboxvalidator
|
|||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
params "git.gocasts.ir/ebhomengo/niki/param"
|
||||
"slices"
|
||||
|
||||
params "git.gocasts.ir/ebhomengo/niki/param"
|
||||
errmsg "git.gocasts.ir/ebhomengo/niki/pkg/err_msg"
|
||||
validation "github.com/go-ozzo/ozzo-validation/v4"
|
||||
)
|
||||
|
|
@ -39,6 +39,7 @@ func (v Validator) doesKindBoxExistForAgent(ctx context.Context, agentID uint) v
|
|||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
func (v Validator) AreSortFieldsValid(validSortFields []string) validation.RuleFunc {
|
||||
return func(value interface{}) error {
|
||||
sort, ok := value.(params.SortRequest)
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@ package agentkindboxreqvalidator
|
|||
import (
|
||||
"context"
|
||||
"errors"
|
||||
|
||||
param "git.gocasts.ir/ebhomengo/niki/param/agent/kind_box_req"
|
||||
errmsg "git.gocasts.ir/ebhomengo/niki/pkg/err_msg"
|
||||
richerror "git.gocasts.ir/ebhomengo/niki/pkg/rich_error"
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@ package agentkindboxreqvalidator
|
|||
|
||||
import (
|
||||
"errors"
|
||||
|
||||
kbrparam "git.gocasts.ir/ebhomengo/niki/param/agent/kind_box_req"
|
||||
errmsg "git.gocasts.ir/ebhomengo/niki/pkg/err_msg"
|
||||
richerror "git.gocasts.ir/ebhomengo/niki/pkg/rich_error"
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@ package agentkindboxreqvalidator
|
|||
|
||||
import (
|
||||
"errors"
|
||||
|
||||
param "git.gocasts.ir/ebhomengo/niki/param/agent/kind_box_req"
|
||||
errmsg "git.gocasts.ir/ebhomengo/niki/pkg/err_msg"
|
||||
richerror "git.gocasts.ir/ebhomengo/niki/pkg/rich_error"
|
||||
|
|
|
|||
|
|
@ -4,10 +4,10 @@ import (
|
|||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"git.gocasts.ir/ebhomengo/niki/entity"
|
||||
params "git.gocasts.ir/ebhomengo/niki/param"
|
||||
"slices"
|
||||
|
||||
"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"
|
||||
)
|
||||
|
|
|
|||
|
|
@ -2,12 +2,13 @@ package benefactorvalidator
|
|||
|
||||
import (
|
||||
"context"
|
||||
"testing"
|
||||
|
||||
"git.gocasts.ir/ebhomengo/niki/entity"
|
||||
benefactoreparam "git.gocasts.ir/ebhomengo/niki/param/benefactor/benefactor"
|
||||
errmsg "git.gocasts.ir/ebhomengo/niki/pkg/err_msg"
|
||||
richerror "git.gocasts.ir/ebhomengo/niki/pkg/rich_error"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestValidator_ValidateSendOtpRequest(t *testing.T) {
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@ import (
|
|||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
|
||||
"git.gocasts.ir/ebhomengo/niki/entity"
|
||||
errmsg "git.gocasts.ir/ebhomengo/niki/pkg/err_msg"
|
||||
richerror "git.gocasts.ir/ebhomengo/niki/pkg/rich_error"
|
||||
|
|
|
|||
Loading…
Reference in New Issue