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
|
package adminhandler
|
||||||
|
|
||||||
import (
|
import (
|
||||||
adminserviceparam "git.gocasts.ir/ebhomengo/niki/param/admin/admin"
|
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
|
adminserviceparam "git.gocasts.ir/ebhomengo/niki/param/admin/admin"
|
||||||
httpmsg "git.gocasts.ir/ebhomengo/niki/pkg/http_msg"
|
httpmsg "git.gocasts.ir/ebhomengo/niki/pkg/http_msg"
|
||||||
"github.com/labstack/echo/v4"
|
"github.com/labstack/echo/v4"
|
||||||
)
|
)
|
||||||
|
|
|
||||||
|
|
@ -1,26 +1,55 @@
|
||||||
package adminbenefactorhandler
|
package adminbenefactorhandler
|
||||||
|
|
||||||
import (
|
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"
|
"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
|
// GetAllBenefactor godoc
|
||||||
// @Summary Get all benefactor by admin
|
// @Summary Get all benefactors by admin
|
||||||
// @Tags Admins Benefactors
|
// @Tags Admins Benefactors
|
||||||
// @Accept json
|
// @Accept json
|
||||||
// @Produce json
|
// @Produce json
|
||||||
// @Success 200 {object} adminbenefactorparam.GetAllBenefactorResponse
|
// @Param filter_id query int false "Filter by ID"
|
||||||
// @Failure 400 {string} "Bad request"
|
// @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
|
// @Security AuthBearerAdmin
|
||||||
// @Router /admins/benefactors [get].
|
// @Router /admins/benefactors [get].
|
||||||
func (h Handler) GetAllBenefactor(c echo.Context) error {
|
func (h Handler) GetAllBenefactor(c echo.Context) error {
|
||||||
var resp adminbenefactorparam.GetAllBenefactorResponse
|
var req param.BenefactorGetAllRequest
|
||||||
resp, sErr := h.benefactorSvc.GetAllBenefactor(c.Request().Context())
|
|
||||||
|
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 {
|
if sErr != nil {
|
||||||
msg, code := httpmsg.Error(sErr)
|
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 echo.NewHTTPError(code, msg)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,9 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
func (h Handler) SetRoutes(e *echo.Echo) {
|
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
|
// @Security AuthBearerAdmin
|
||||||
// @Router /admins/kindboxes/update/{id} [put].
|
// @Router /admins/kindboxes/update/{id} [put].
|
||||||
func (h Handler) Update(c echo.Context) error {
|
func (h Handler) Update(c echo.Context) error {
|
||||||
|
|
||||||
var req param.KindBoxUpdateRequest
|
var req param.KindBoxUpdateRequest
|
||||||
|
|
||||||
if bErr := c.Bind(&req); bErr != nil {
|
if bErr := c.Bind(&req); bErr != nil {
|
||||||
|
|
|
||||||
|
|
@ -2,10 +2,10 @@ package agentkindboxreqhandler
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
params "git.gocasts.ir/ebhomengo/niki/param"
|
|
||||||
param "git.gocasts.ir/ebhomengo/niki/param/agent/kind_box_req"
|
|
||||||
"net/http"
|
"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"
|
errmsg "git.gocasts.ir/ebhomengo/niki/pkg/err_msg"
|
||||||
httpmsg "git.gocasts.ir/ebhomengo/niki/pkg/http_msg"
|
httpmsg "git.gocasts.ir/ebhomengo/niki/pkg/http_msg"
|
||||||
querier "git.gocasts.ir/ebhomengo/niki/pkg/query_transaction/sql"
|
querier "git.gocasts.ir/ebhomengo/niki/pkg/query_transaction/sql"
|
||||||
|
|
|
||||||
|
|
@ -1,10 +1,10 @@
|
||||||
package agentkindboxreqhandler
|
package agentkindboxreqhandler
|
||||||
|
|
||||||
import (
|
import (
|
||||||
param "git.gocasts.ir/ebhomengo/niki/param/agent/kind_box_req"
|
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
"git.gocasts.ir/ebhomengo/niki/entity"
|
"git.gocasts.ir/ebhomengo/niki/entity"
|
||||||
|
param "git.gocasts.ir/ebhomengo/niki/param/agent/kind_box_req"
|
||||||
"git.gocasts.ir/ebhomengo/niki/pkg/claim"
|
"git.gocasts.ir/ebhomengo/niki/pkg/claim"
|
||||||
httpmsg "git.gocasts.ir/ebhomengo/niki/pkg/http_msg"
|
httpmsg "git.gocasts.ir/ebhomengo/niki/pkg/http_msg"
|
||||||
queryparam "git.gocasts.ir/ebhomengo/niki/pkg/query_param"
|
queryparam "git.gocasts.ir/ebhomengo/niki/pkg/query_param"
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,9 @@
|
||||||
package agentkindboxreqhandler
|
package agentkindboxreqhandler
|
||||||
|
|
||||||
import (
|
import (
|
||||||
param "git.gocasts.ir/ebhomengo/niki/param/agent/kind_box_req"
|
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
|
param "git.gocasts.ir/ebhomengo/niki/param/agent/kind_box_req"
|
||||||
"git.gocasts.ir/ebhomengo/niki/pkg/claim"
|
"git.gocasts.ir/ebhomengo/niki/pkg/claim"
|
||||||
httpmsg "git.gocasts.ir/ebhomengo/niki/pkg/http_msg"
|
httpmsg "git.gocasts.ir/ebhomengo/niki/pkg/http_msg"
|
||||||
"github.com/labstack/echo/v4"
|
"github.com/labstack/echo/v4"
|
||||||
|
|
|
||||||
|
|
@ -1,10 +1,10 @@
|
||||||
package benefactorhandler
|
package benefactorhandler
|
||||||
|
|
||||||
import (
|
import (
|
||||||
benefactorparam "git.gocasts.ir/ebhomengo/niki/param/benefactor/benefactor"
|
|
||||||
httpmsg "git.gocasts.ir/ebhomengo/niki/pkg/http_msg"
|
|
||||||
"net/http"
|
"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"
|
"github.com/labstack/echo/v4"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -6,6 +6,7 @@ import (
|
||||||
"git.gocasts.ir/ebhomengo/niki/config"
|
"git.gocasts.ir/ebhomengo/niki/config"
|
||||||
adminhandler "git.gocasts.ir/ebhomengo/niki/delivery/http_server/admin/admin"
|
adminhandler "git.gocasts.ir/ebhomengo/niki/delivery/http_server/admin/admin"
|
||||||
adminagenthandler "git.gocasts.ir/ebhomengo/niki/delivery/http_server/admin/agent"
|
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"
|
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"
|
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"
|
adminrefertimehandler "git.gocasts.ir/ebhomengo/niki/delivery/http_server/admin/refer_time"
|
||||||
|
|
@ -30,6 +31,7 @@ type Server struct {
|
||||||
adminKindBoxReqHandler adminkindboxreqhandler.Handler
|
adminKindBoxReqHandler adminkindboxreqhandler.Handler
|
||||||
adminKindBoxHandler adminKindBoxHandler.Handler
|
adminKindBoxHandler adminKindBoxHandler.Handler
|
||||||
adminAgentHandler adminagenthandler.Handler
|
adminAgentHandler adminagenthandler.Handler
|
||||||
|
adminBenefactorHandler adminbenefactorhandler.Handler
|
||||||
adminReferTimeHandler adminrefertimehandler.Handler
|
adminReferTimeHandler adminrefertimehandler.Handler
|
||||||
agentKindBoxHandler agentkindboxhandler.Handler
|
agentKindBoxHandler agentkindboxhandler.Handler
|
||||||
agentKindBoxReqHandler agentkindboxreqhandler.Handler
|
agentKindBoxReqHandler agentkindboxreqhandler.Handler
|
||||||
|
|
@ -51,6 +53,7 @@ func New(
|
||||||
adminKindBoxReqHandler: adminkindboxreqhandler.New(svc.AdminAuthSvc, svc.AdminKindBoxReqSvc, svc.AdminAuthorizeSvc, svc.NotificationSvc),
|
adminKindBoxReqHandler: adminkindboxreqhandler.New(svc.AdminAuthSvc, svc.AdminKindBoxReqSvc, svc.AdminAuthorizeSvc, svc.NotificationSvc),
|
||||||
adminKindBoxHandler: adminKindBoxHandler.New(svc.AdminAuthSvc, svc.AdminKindBoxSvc, svc.AdminAuthorizeSvc, svc.NotificationSvc),
|
adminKindBoxHandler: adminKindBoxHandler.New(svc.AdminAuthSvc, svc.AdminKindBoxSvc, svc.AdminAuthorizeSvc, svc.NotificationSvc),
|
||||||
adminAgentHandler: adminagenthandler.New(svc.AdminAuthSvc, svc.AdminAgentSvc, svc.AdminAuthorizeSvc),
|
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),
|
adminReferTimeHandler: adminrefertimehandler.New(svc.AdminAuthSvc, svc.AdminReferTimeSvc, svc.AdminAuthorizeSvc),
|
||||||
agentKindBoxHandler: agentkindboxhandler.New(svc.AdminAuthSvc, svc.AgentKindBoxSvc, svc.AdminAuthorizeSvc, svc.NotificationSvc),
|
agentKindBoxHandler: agentkindboxhandler.New(svc.AdminAuthSvc, svc.AgentKindBoxSvc, svc.AdminAuthorizeSvc, svc.NotificationSvc),
|
||||||
agentKindBoxReqHandler: agentkindboxreqhandler.New(svc.AdminAuthSvc, svc.AgentKindBoxReqSvc, 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.adminKindBoxReqHandler.SetRoutes(s.Router)
|
||||||
s.adminKindBoxHandler.SetRoutes(s.Router)
|
s.adminKindBoxHandler.SetRoutes(s.Router)
|
||||||
s.adminReferTimeHandler.SetRoutes(s.Router)
|
s.adminReferTimeHandler.SetRoutes(s.Router)
|
||||||
|
s.adminBenefactorHandler.SetRoutes(s.Router)
|
||||||
s.agentKindBoxHandler.SetRoutes(s.Router)
|
s.agentKindBoxHandler.SetRoutes(s.Router)
|
||||||
s.agentKindBoxReqHandler.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": {
|
"/admins/kindboxes": {
|
||||||
"get": {
|
"get": {
|
||||||
"security": [
|
"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": {
|
"adminkindboxparam.AssignReceiverRequest": {
|
||||||
"type": "object",
|
"type": "object",
|
||||||
"properties": {
|
"properties": {
|
||||||
|
|
@ -4026,6 +4214,17 @@ const docTemplate = `{
|
||||||
"AdminInactiveStatus"
|
"AdminInactiveStatus"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
"entity.BenefactorStatus": {
|
||||||
|
"type": "string",
|
||||||
|
"enum": [
|
||||||
|
"active",
|
||||||
|
"inactive"
|
||||||
|
],
|
||||||
|
"x-enum-varnames": [
|
||||||
|
"BenefactorActiveStatus",
|
||||||
|
"BenefactorInactiveStatus"
|
||||||
|
]
|
||||||
|
},
|
||||||
"entity.City": {
|
"entity.City": {
|
||||||
"type": "object",
|
"type": "object",
|
||||||
"properties": {
|
"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": {
|
"/admins/kindboxes": {
|
||||||
"get": {
|
"get": {
|
||||||
"security": [
|
"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": {
|
"adminkindboxparam.AssignReceiverRequest": {
|
||||||
"type": "object",
|
"type": "object",
|
||||||
"properties": {
|
"properties": {
|
||||||
|
|
@ -4015,6 +4203,17 @@
|
||||||
"AdminInactiveStatus"
|
"AdminInactiveStatus"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
"entity.BenefactorStatus": {
|
||||||
|
"type": "string",
|
||||||
|
"enum": [
|
||||||
|
"active",
|
||||||
|
"inactive"
|
||||||
|
],
|
||||||
|
"x-enum-varnames": [
|
||||||
|
"BenefactorActiveStatus",
|
||||||
|
"BenefactorInactiveStatus"
|
||||||
|
]
|
||||||
|
},
|
||||||
"entity.City": {
|
"entity.City": {
|
||||||
"type": "object",
|
"type": "object",
|
||||||
"properties": {
|
"properties": {
|
||||||
|
|
|
||||||
|
|
@ -123,6 +123,40 @@ definitions:
|
||||||
$ref: '#/definitions/adminagentparam.Data'
|
$ref: '#/definitions/adminagentparam.Data'
|
||||||
type: array
|
type: array
|
||||||
type: object
|
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:
|
adminkindboxparam.AssignReceiverRequest:
|
||||||
properties:
|
properties:
|
||||||
receiver_agent_id:
|
receiver_agent_id:
|
||||||
|
|
@ -886,6 +920,14 @@ definitions:
|
||||||
x-enum-varnames:
|
x-enum-varnames:
|
||||||
- AdminActiveStatus
|
- AdminActiveStatus
|
||||||
- AdminInactiveStatus
|
- AdminInactiveStatus
|
||||||
|
entity.BenefactorStatus:
|
||||||
|
enum:
|
||||||
|
- active
|
||||||
|
- inactive
|
||||||
|
type: string
|
||||||
|
x-enum-varnames:
|
||||||
|
- BenefactorActiveStatus
|
||||||
|
- BenefactorInactiveStatus
|
||||||
entity.City:
|
entity.City:
|
||||||
properties:
|
properties:
|
||||||
id:
|
id:
|
||||||
|
|
@ -1015,6 +1057,97 @@ paths:
|
||||||
summary: Get all agents by admin
|
summary: Get all agents by admin
|
||||||
tags:
|
tags:
|
||||||
- Admins
|
- 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:
|
/admins/kindboxes:
|
||||||
get:
|
get:
|
||||||
consumes:
|
consumes:
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,9 @@
|
||||||
package adminbenefactoreparam
|
package adminbenefactoreparam
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"git.gocasts.ir/ebhomengo/niki/entity"
|
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"git.gocasts.ir/ebhomengo/niki/entity"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Data struct {
|
type Data struct {
|
||||||
|
|
@ -14,6 +15,5 @@ type Data struct {
|
||||||
Email string `json:"email"`
|
Email string `json:"email"`
|
||||||
Gender entity.Gender `json:"gender"`
|
Gender entity.Gender `json:"gender"`
|
||||||
BirthDate time.Time `json:"birth_date"`
|
BirthDate time.Time `json:"birth_date"`
|
||||||
Roll entity.UserRole `json:"roll"`
|
|
||||||
Status entity.BenefactorStatus `json:"status"`
|
Status entity.BenefactorStatus `json:"status"`
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -4,12 +4,12 @@ import (
|
||||||
"git.gocasts.ir/ebhomengo/niki/param"
|
"git.gocasts.ir/ebhomengo/niki/param"
|
||||||
)
|
)
|
||||||
|
|
||||||
type GetAllBenefactorRequest struct {
|
type BenefactorGetAllRequest struct {
|
||||||
Pagination param.PaginationRequest
|
Pagination param.PaginationRequest
|
||||||
Sort param.SortRequest
|
Sort param.SortRequest
|
||||||
Filter param.FilterRequest
|
Filter param.FilterRequest
|
||||||
}
|
}
|
||||||
type GetAllBenefactorResponse struct {
|
type BenefactorGetAllResponse struct {
|
||||||
Data []Data `json:"data"`
|
Data []Data `json:"data"`
|
||||||
Pagination param.PaginationResponse `json:"pagination"`
|
Pagination param.PaginationResponse `json:"pagination"`
|
||||||
FieldErrors map[string]string `json:"field_errors,omitempty"`
|
FieldErrors map[string]string `json:"field_errors,omitempty"`
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,9 @@
|
||||||
package adminkindboxreqparam
|
package adminkindboxreqparam
|
||||||
|
|
||||||
import (
|
import (
|
||||||
entity "git.gocasts.ir/ebhomengo/niki/entity"
|
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
entity "git.gocasts.ir/ebhomengo/niki/entity"
|
||||||
)
|
)
|
||||||
|
|
||||||
type KindBoxReqAddRequest struct {
|
type KindBoxReqAddRequest struct {
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,7 @@ package mysqlquerybuilder
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"regexp"
|
"regexp"
|
||||||
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
var datePattern = regexp.MustCompile(`^\d{4}-\d{2}-\d{2}(T\d{2}:\d{2}:\d{2}Z)?$`)
|
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)
|
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 {
|
for key, value := range filter {
|
||||||
if strVal, ok := value.(string); ok && isValidDateOrDateTime(strVal) {
|
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)
|
args = append(args, strVal)
|
||||||
} else {
|
} else {
|
||||||
filterQuery += fmt.Sprintf("AND %s = ? ", key)
|
conditions = append(conditions, fmt.Sprintf("%s = ?", key))
|
||||||
args = append(args, value)
|
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) {
|
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)
|
paginationQuery, pArgs := BuildPaginationQuery(pagination)
|
||||||
sortQuery := BuildSortQuery(sort)
|
sortQuery := BuildSortQuery(sort)
|
||||||
|
|
||||||
args = append(args, fArgs...)
|
args = append(args, fArgs...)
|
||||||
args = append(args, pArgs...)
|
args = append(args, pArgs...)
|
||||||
|
|
||||||
query = baseQuery
|
query = filterQuery
|
||||||
if filterQuery != "" {
|
|
||||||
query = fmt.Sprintf("%s %s", query, filterQuery)
|
|
||||||
}
|
|
||||||
if sortQuery != "" {
|
if sortQuery != "" {
|
||||||
query = fmt.Sprintf("%s %s", query, sortQuery)
|
query = fmt.Sprintf("%s %s", query, sortQuery)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,7 @@ package mysqlbenefactor
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"errors"
|
"errors"
|
||||||
|
|
||||||
"git.gocasts.ir/ebhomengo/niki/entity"
|
"git.gocasts.ir/ebhomengo/niki/entity"
|
||||||
richerror "git.gocasts.ir/ebhomengo/niki/pkg/rich_error"
|
richerror "git.gocasts.ir/ebhomengo/niki/pkg/rich_error"
|
||||||
)
|
)
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,7 @@ import (
|
||||||
"context"
|
"context"
|
||||||
"database/sql"
|
"database/sql"
|
||||||
"errors"
|
"errors"
|
||||||
|
|
||||||
"git.gocasts.ir/ebhomengo/niki/entity"
|
"git.gocasts.ir/ebhomengo/niki/entity"
|
||||||
errmsg "git.gocasts.ir/ebhomengo/niki/pkg/err_msg"
|
errmsg "git.gocasts.ir/ebhomengo/niki/pkg/err_msg"
|
||||||
richerror "git.gocasts.ir/ebhomengo/niki/pkg/rich_error"
|
richerror "git.gocasts.ir/ebhomengo/niki/pkg/rich_error"
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,7 @@ package mysqlbenefactor
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
|
||||||
"git.gocasts.ir/ebhomengo/niki/entity"
|
"git.gocasts.ir/ebhomengo/niki/entity"
|
||||||
params "git.gocasts.ir/ebhomengo/niki/param"
|
params "git.gocasts.ir/ebhomengo/niki/param"
|
||||||
errmsg "git.gocasts.ir/ebhomengo/niki/pkg/err_msg"
|
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
|
var total uint
|
||||||
baseQuery = `SELECT COUNT(*) FROM benefactors`
|
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)
|
qErr = d.conn.Conn().QueryRowContext(ctx, query, args...).Scan(&total)
|
||||||
if qErr != nil {
|
if qErr != nil {
|
||||||
return nil, 0, richerror.New(op).WithErr(qErr).WithMessage(errmsg.ErrorMsgSomethingWentWrong).WithKind(richerror.KindUnexpected)
|
return nil, 0, richerror.New(op).WithErr(qErr).WithMessage(errmsg.ErrorMsgSomethingWentWrong).WithKind(richerror.KindUnexpected)
|
||||||
|
|
|
||||||
|
|
@ -2,9 +2,10 @@ package mysqlbenefactor
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"database/sql"
|
"database/sql"
|
||||||
|
"time"
|
||||||
|
|
||||||
"git.gocasts.ir/ebhomengo/niki/entity"
|
"git.gocasts.ir/ebhomengo/niki/entity"
|
||||||
"git.gocasts.ir/ebhomengo/niki/repository/mysql"
|
"git.gocasts.ir/ebhomengo/niki/repository/mysql"
|
||||||
"time"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func scanBenefactor(scanner mysql.Scanner) (entity.Benefactor, error) {
|
func scanBenefactor(scanner mysql.Scanner) (entity.Benefactor, error) {
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,6 @@ import (
|
||||||
"database/sql"
|
"database/sql"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
|
||||||
"git.gocasts.ir/ebhomengo/niki/entity"
|
"git.gocasts.ir/ebhomengo/niki/entity"
|
||||||
errmsg "git.gocasts.ir/ebhomengo/niki/pkg/err_msg"
|
errmsg "git.gocasts.ir/ebhomengo/niki/pkg/err_msg"
|
||||||
richerror "git.gocasts.ir/ebhomengo/niki/pkg/rich_error"
|
richerror "git.gocasts.ir/ebhomengo/niki/pkg/rich_error"
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,7 @@ package mysqlkindboxreq
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
|
||||||
"git.gocasts.ir/ebhomengo/niki/entity"
|
"git.gocasts.ir/ebhomengo/niki/entity"
|
||||||
errmsg "git.gocasts.ir/ebhomengo/niki/pkg/err_msg"
|
errmsg "git.gocasts.ir/ebhomengo/niki/pkg/err_msg"
|
||||||
richerror "git.gocasts.ir/ebhomengo/niki/pkg/rich_error"
|
richerror "git.gocasts.ir/ebhomengo/niki/pkg/rich_error"
|
||||||
|
|
|
||||||
|
|
@ -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 (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
|
||||||
"git.gocasts.ir/ebhomengo/niki/entity"
|
"git.gocasts.ir/ebhomengo/niki/entity"
|
||||||
adminserviceparam "git.gocasts.ir/ebhomengo/niki/param/admin/admin"
|
adminserviceparam "git.gocasts.ir/ebhomengo/niki/param/admin/admin"
|
||||||
errmsg "git.gocasts.ir/ebhomengo/niki/pkg/err_msg"
|
errmsg "git.gocasts.ir/ebhomengo/niki/pkg/err_msg"
|
||||||
|
|
|
||||||
|
|
@ -3,10 +3,10 @@ package adminservice
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
"git.gocasts.ir/ebhomengo/niki/service/auth"
|
|
||||||
|
|
||||||
"git.gocasts.ir/ebhomengo/niki/config"
|
"git.gocasts.ir/ebhomengo/niki/config"
|
||||||
"git.gocasts.ir/ebhomengo/niki/entity"
|
"git.gocasts.ir/ebhomengo/niki/entity"
|
||||||
|
"git.gocasts.ir/ebhomengo/niki/service/auth"
|
||||||
validator "git.gocasts.ir/ebhomengo/niki/validator/admin/admin"
|
validator "git.gocasts.ir/ebhomengo/niki/validator/admin/admin"
|
||||||
"golang.org/x/crypto/bcrypt"
|
"golang.org/x/crypto/bcrypt"
|
||||||
)
|
)
|
||||||
|
|
|
||||||
|
|
@ -2,23 +2,29 @@ package adminbenefactorservice
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
|
||||||
paginationparam "git.gocasts.ir/ebhomengo/niki/param"
|
paginationparam "git.gocasts.ir/ebhomengo/niki/param"
|
||||||
param "git.gocasts.ir/ebhomengo/niki/param/admin/benefactor"
|
param "git.gocasts.ir/ebhomengo/niki/param/admin/benefactor"
|
||||||
richerror "git.gocasts.ir/ebhomengo/niki/pkg/rich_error"
|
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"
|
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 {
|
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 {
|
for _, benefactor := range benefactors {
|
||||||
benefactorInfo = append(benefactorInfo, param.Data{
|
resp = append(resp, param.Data{
|
||||||
ID: benefactor.ID,
|
ID: benefactor.ID,
|
||||||
FirstName: benefactor.FirstName,
|
FirstName: benefactor.FirstName,
|
||||||
LastName: benefactor.LastName,
|
LastName: benefactor.LastName,
|
||||||
|
|
@ -27,14 +33,16 @@ func (s Service) GetAllBenefactor(ctx context.Context, req param.GetAllBenefacto
|
||||||
Email: benefactor.Email,
|
Email: benefactor.Email,
|
||||||
Gender: benefactor.Gender,
|
Gender: benefactor.Gender,
|
||||||
BirthDate: benefactor.BirthDate,
|
BirthDate: benefactor.BirthDate,
|
||||||
Roll: benefactor.Role,
|
|
||||||
Status: benefactor.Status,
|
Status: benefactor.Status,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
return param.GetAllBenefactorResponse{Data: benefactorInfo, Pagination: paginationparam.PaginationResponse{
|
return param.BenefactorGetAllResponse{
|
||||||
|
Data: resp,
|
||||||
|
Pagination: paginationparam.PaginationResponse{
|
||||||
PageSize: req.Pagination.PageSize,
|
PageSize: req.Pagination.PageSize,
|
||||||
PageNumber: req.Pagination.PageNumber,
|
PageNumber: req.Pagination.PageNumber,
|
||||||
Total: total,
|
Total: total,
|
||||||
}}, nil
|
},
|
||||||
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -2,18 +2,17 @@ package adminbenefactorservice
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"git.gocasts.ir/ebhomengo/niki/param"
|
|
||||||
|
|
||||||
"git.gocasts.ir/ebhomengo/niki/entity"
|
"git.gocasts.ir/ebhomengo/niki/entity"
|
||||||
|
"git.gocasts.ir/ebhomengo/niki/param"
|
||||||
adminaddressparam "git.gocasts.ir/ebhomengo/niki/param/admin/address"
|
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 {
|
type Repository interface {
|
||||||
IsExistBenefactorByID(ctx context.Context, id uint) (bool, error)
|
IsExistBenefactorByID(ctx context.Context, id uint) (bool, error)
|
||||||
GetByID(ctx context.Context, id uint) (entity.Benefactor, 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 {
|
type AddressSvc interface {
|
||||||
GetAddressByID(ctx context.Context, request adminaddressparam.AddressGetRequest) (adminaddressparam.AddressGetResponse, error)
|
GetAddressByID(ctx context.Context, request adminaddressparam.AddressGetRequest) (adminaddressparam.AddressGetResponse, error)
|
||||||
|
|
@ -22,9 +21,9 @@ type AddressSvc interface {
|
||||||
type Service struct {
|
type Service struct {
|
||||||
repo Repository
|
repo Repository
|
||||||
addressSvc AddressSvc
|
addressSvc AddressSvc
|
||||||
benefactorSvc BenefactorSvc
|
vld validator.Validator
|
||||||
}
|
}
|
||||||
|
|
||||||
func New(repo Repository, addressSvc AddressSvc, benefactorSvc BenefactorSvc) Service {
|
func New(repo Repository, addressSvc AddressSvc, vld validator.Validator) Service {
|
||||||
return Service{repo: repo, addressSvc: addressSvc, benefactorSvc: benefactorSvc}
|
return Service{repo: repo, addressSvc: addressSvc, vld: vld}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,7 @@ package adminkindboxreqservice
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
|
||||||
"git.gocasts.ir/ebhomengo/niki/entity"
|
"git.gocasts.ir/ebhomengo/niki/entity"
|
||||||
param "git.gocasts.ir/ebhomengo/niki/param/admin/kind_box_req"
|
param "git.gocasts.ir/ebhomengo/niki/param/admin/kind_box_req"
|
||||||
richerror "git.gocasts.ir/ebhomengo/niki/pkg/rich_error"
|
richerror "git.gocasts.ir/ebhomengo/niki/pkg/rich_error"
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,7 @@ package agentkindboxservice
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
|
||||||
entity "git.gocasts.ir/ebhomengo/niki/entity"
|
entity "git.gocasts.ir/ebhomengo/niki/entity"
|
||||||
param "git.gocasts.ir/ebhomengo/niki/param/agent/kind_box"
|
param "git.gocasts.ir/ebhomengo/niki/param/agent/kind_box"
|
||||||
richerror "git.gocasts.ir/ebhomengo/niki/pkg/rich_error"
|
richerror "git.gocasts.ir/ebhomengo/niki/pkg/rich_error"
|
||||||
|
|
|
||||||
|
|
@ -2,10 +2,10 @@ package agentkindboxreqservice
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
kindboxParam "git.gocasts.ir/ebhomengo/niki/param/agent/kind_box"
|
|
||||||
param "git.gocasts.ir/ebhomengo/niki/param/agent/kind_box_req"
|
|
||||||
"time"
|
"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"
|
richerror "git.gocasts.ir/ebhomengo/niki/pkg/rich_error"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,7 @@ package agentkindboxreqservice
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
|
||||||
param "git.gocasts.ir/ebhomengo/niki/param/agent/kind_box_req"
|
param "git.gocasts.ir/ebhomengo/niki/param/agent/kind_box_req"
|
||||||
richerror "git.gocasts.ir/ebhomengo/niki/pkg/rich_error"
|
richerror "git.gocasts.ir/ebhomengo/niki/pkg/rich_error"
|
||||||
)
|
)
|
||||||
|
|
|
||||||
|
|
@ -2,10 +2,10 @@ package agentkindboxreqservice
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
param "git.gocasts.ir/ebhomengo/niki/param/agent/kind_box"
|
|
||||||
|
|
||||||
"git.gocasts.ir/ebhomengo/niki/entity"
|
"git.gocasts.ir/ebhomengo/niki/entity"
|
||||||
params "git.gocasts.ir/ebhomengo/niki/param"
|
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"
|
validator "git.gocasts.ir/ebhomengo/niki/validator/agent/kind_box_req"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,10 @@
|
||||||
package auth
|
package auth
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"time"
|
||||||
|
|
||||||
"git.gocasts.ir/ebhomengo/niki/entity"
|
"git.gocasts.ir/ebhomengo/niki/entity"
|
||||||
"github.com/golang-jwt/jwt/v4"
|
"github.com/golang-jwt/jwt/v4"
|
||||||
"time"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func (s Service) CreateAccessToken(user entity.Authenticable) (string, error) {
|
func (s Service) CreateAccessToken(user entity.Authenticable) (string, error) {
|
||||||
|
|
|
||||||
|
|
@ -2,9 +2,10 @@ package auth
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"strings"
|
||||||
|
|
||||||
errmsg "git.gocasts.ir/ebhomengo/niki/pkg/err_msg"
|
errmsg "git.gocasts.ir/ebhomengo/niki/pkg/err_msg"
|
||||||
"github.com/golang-jwt/jwt/v4"
|
"github.com/golang-jwt/jwt/v4"
|
||||||
"strings"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func (s Service) ParseBearerToken(bearerToken string) (*Claims, error) {
|
func (s Service) ParseBearerToken(bearerToken string) (*Claims, error) {
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,7 @@ package benefactorservice
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
|
||||||
"git.gocasts.ir/ebhomengo/niki/entity"
|
"git.gocasts.ir/ebhomengo/niki/entity"
|
||||||
benefactorparam "git.gocasts.ir/ebhomengo/niki/param/benefactor/benefactor"
|
benefactorparam "git.gocasts.ir/ebhomengo/niki/param/benefactor/benefactor"
|
||||||
errmsg "git.gocasts.ir/ebhomengo/niki/pkg/err_msg"
|
errmsg "git.gocasts.ir/ebhomengo/niki/pkg/err_msg"
|
||||||
|
|
|
||||||
|
|
@ -2,11 +2,11 @@ package benefactorservice
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"git.gocasts.ir/ebhomengo/niki/service/auth"
|
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
smscontract "git.gocasts.ir/ebhomengo/niki/contract/sms"
|
smscontract "git.gocasts.ir/ebhomengo/niki/contract/sms"
|
||||||
"git.gocasts.ir/ebhomengo/niki/entity"
|
"git.gocasts.ir/ebhomengo/niki/entity"
|
||||||
|
"git.gocasts.ir/ebhomengo/niki/service/auth"
|
||||||
benefactorvalidator "git.gocasts.ir/ebhomengo/niki/validator/benefactor/benefactor"
|
benefactorvalidator "git.gocasts.ir/ebhomengo/niki/validator/benefactor/benefactor"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,7 @@ package notification
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
"git.gocasts.ir/ebhomengo/niki/param"
|
"git.gocasts.ir/ebhomengo/niki/param"
|
||||||
bnfparam "git.gocasts.ir/ebhomengo/niki/param/admin/benefactor"
|
bnfparam "git.gocasts.ir/ebhomengo/niki/param/admin/benefactor"
|
||||||
kbp "git.gocasts.ir/ebhomengo/niki/param/admin/kind_box"
|
kbp "git.gocasts.ir/ebhomengo/niki/param/admin/kind_box"
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,7 @@ package notification
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
"git.gocasts.ir/ebhomengo/niki/param"
|
"git.gocasts.ir/ebhomengo/niki/param"
|
||||||
bnfparam "git.gocasts.ir/ebhomengo/niki/param/admin/benefactor"
|
bnfparam "git.gocasts.ir/ebhomengo/niki/param/admin/benefactor"
|
||||||
kbparam "git.gocasts.ir/ebhomengo/niki/param/admin/kind_box_req"
|
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"
|
benefactorrefertimeservice "git.gocasts.ir/ebhomengo/niki/service/benefactor/refer_time"
|
||||||
"git.gocasts.ir/ebhomengo/niki/service/notification"
|
"git.gocasts.ir/ebhomengo/niki/service/notification"
|
||||||
adminvalidator "git.gocasts.ir/ebhomengo/niki/validator/admin/admin"
|
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"
|
adminkindboxvalidator "git.gocasts.ir/ebhomengo/niki/validator/admin/kind_box"
|
||||||
adminkindboxreqvalidator "git.gocasts.ir/ebhomengo/niki/validator/admin/kind_box_req"
|
adminkindboxreqvalidator "git.gocasts.ir/ebhomengo/niki/validator/admin/kind_box_req"
|
||||||
agentkindboxvalidator "git.gocasts.ir/ebhomengo/niki/validator/agent/kind_box"
|
agentkindboxvalidator "git.gocasts.ir/ebhomengo/niki/validator/agent/kind_box"
|
||||||
|
|
@ -48,6 +49,7 @@ type Service struct {
|
||||||
AdminAuthorizeSvc adminauthorizationservice.Service
|
AdminAuthorizeSvc adminauthorizationservice.Service
|
||||||
AdminSvc adminservice.Service
|
AdminSvc adminservice.Service
|
||||||
AdminAgentSvc adminagentservice.Service
|
AdminAgentSvc adminagentservice.Service
|
||||||
|
AdminBenefactorSvc adminbenefactorservice.Service
|
||||||
AgentKindBoxSvc agentkindboxservice.Service
|
AgentKindBoxSvc agentkindboxservice.Service
|
||||||
AgentKindBoxReqSvc agentkindboxreqservice.Service
|
AgentKindBoxReqSvc agentkindboxreqservice.Service
|
||||||
BenefactorAuthSvc auth.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)
|
AdminAuthorizeSvc = adminauthorizationservice.New(adminRepo)
|
||||||
AdminReferTimeSvc = adminrefertimeservice.New(referTimeRepo)
|
AdminReferTimeSvc = adminrefertimeservice.New(referTimeRepo)
|
||||||
AdminAddressSvc = adminaddressservice.New(addressRepo)
|
AdminAddressSvc = adminaddressservice.New(addressRepo)
|
||||||
AdminBenefactorSvc = adminbenefactorservice.New(benefactorRepo, AdminAddressSvc)
|
AdminBenefactorVld = adminbenefactorvalidator.New()
|
||||||
|
AdminBenefactorSvc = adminbenefactorservice.New(benefactorRepo, AdminAddressSvc, AdminBenefactorVld)
|
||||||
AdminAgentSvc = adminagentservice.New(agentRepo)
|
AdminAgentSvc = adminagentservice.New(agentRepo)
|
||||||
|
|
||||||
AdminVld = adminvalidator.New(adminRepo)
|
AdminVld = adminvalidator.New(adminRepo)
|
||||||
|
|
@ -116,6 +119,7 @@ func New(cfg config.Config, db *mysql.DB, rds *redis.Adapter, smsAdapter smscont
|
||||||
AdminAuthorizeSvc: AdminAuthorizeSvc,
|
AdminAuthorizeSvc: AdminAuthorizeSvc,
|
||||||
AdminSvc: AdminSvc,
|
AdminSvc: AdminSvc,
|
||||||
AdminAgentSvc: AdminAgentSvc,
|
AdminAgentSvc: AdminAgentSvc,
|
||||||
|
AdminBenefactorSvc: AdminBenefactorSvc,
|
||||||
AgentKindBoxSvc: AgentKindBoxSvc,
|
AgentKindBoxSvc: AgentKindBoxSvc,
|
||||||
AgentKindBoxReqSvc: AgentKindBoxReqSvc,
|
AgentKindBoxReqSvc: AgentKindBoxReqSvc,
|
||||||
BenefactorAuthSvc: BenefactorAuthSvc,
|
BenefactorAuthSvc: BenefactorAuthSvc,
|
||||||
|
|
|
||||||
|
|
@ -3,9 +3,9 @@ package adminvalidator
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"errors"
|
"errors"
|
||||||
"git.gocasts.ir/ebhomengo/niki/entity"
|
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"git.gocasts.ir/ebhomengo/niki/entity"
|
||||||
adminserviceparam "git.gocasts.ir/ebhomengo/niki/param/admin/admin"
|
adminserviceparam "git.gocasts.ir/ebhomengo/niki/param/admin/admin"
|
||||||
errmsg "git.gocasts.ir/ebhomengo/niki/pkg/err_msg"
|
errmsg "git.gocasts.ir/ebhomengo/niki/pkg/err_msg"
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,7 @@ package adminvalidator
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
"git.gocasts.ir/ebhomengo/niki/entity"
|
"git.gocasts.ir/ebhomengo/niki/entity"
|
||||||
errmsg "git.gocasts.ir/ebhomengo/niki/pkg/err_msg"
|
errmsg "git.gocasts.ir/ebhomengo/niki/pkg/err_msg"
|
||||||
validation "github.com/go-ozzo/ozzo-validation/v4"
|
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.By(v.CheckKindBoxStatusForEnumeration(ctx))),
|
||||||
|
|
||||||
validation.Field(&req.Amount, validation.Required),
|
validation.Field(&req.Amount, validation.Required),
|
||||||
|
|
||||||
); err != nil {
|
); err != nil {
|
||||||
fieldErrors := make(map[string]string)
|
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.doesBenefactorExist(ctx)),
|
||||||
validation.By(v.doesBenefactorHaveKindBox(ctx, req.KindBoxID, req.BenefactorID))),
|
validation.By(v.doesBenefactorHaveKindBox(ctx, req.KindBoxID, req.BenefactorID))),
|
||||||
)
|
)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fieldErrors := make(map[string]string)
|
fieldErrors := make(map[string]string)
|
||||||
v.processValidationErrors(err, fieldErrors)
|
v.processValidationErrors(err, fieldErrors)
|
||||||
|
|
|
||||||
|
|
@ -5,19 +5,16 @@ import (
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/stretchr/testify/assert"
|
|
||||||
"git.gocasts.ir/ebhomengo/niki/entity"
|
"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"
|
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"
|
refertimeserviceparam "git.gocasts.ir/ebhomengo/niki/param/admin/refer_time"
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
func TestValidator_ValidateUpdateRequest(t *testing.T) {
|
func TestValidator_ValidateUpdateRequest(t *testing.T) {
|
||||||
|
|
||||||
now := time.Now()
|
now := time.Now()
|
||||||
twoDaysLater := now.Add(48 * time.Hour)
|
twoDaysLater := now.Add(48 * time.Hour)
|
||||||
threeDaysLater := now.Add(52 * 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)
|
validator := New(mockRepository, mockAgentSvc, mockBenefactorSvc, mockReferTimeSvc, mockAddressSvc)
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
|
|
||||||
|
|
||||||
t.Run("KindBox Delivered And Benefactor Does Not Exist", func(t *testing.T) {
|
t.Run("KindBox Delivered And Benefactor Does Not Exist", func(t *testing.T) {
|
||||||
req := adminupdateparam.KindBoxUpdateRequest{
|
req := adminupdateparam.KindBoxUpdateRequest{
|
||||||
KindBoxID: 1,
|
KindBoxID: 1,
|
||||||
|
|
@ -46,13 +42,11 @@ func TestValidator_ValidateUpdateRequest(t *testing.T) {
|
||||||
mockRepository.EXPECT().GetKindBox(ctx, req.KindBoxID).
|
mockRepository.EXPECT().GetKindBox(ctx, req.KindBoxID).
|
||||||
Return(entity.KindBox{Status: entity.KindBoxDeliveredStatus}, nil).Once()
|
Return(entity.KindBox{Status: entity.KindBoxDeliveredStatus}, nil).Once()
|
||||||
|
|
||||||
|
|
||||||
fieldErrors, err := validator.ValidateUpdateRequest(ctx, req)
|
fieldErrors, err := validator.ValidateUpdateRequest(ctx, req)
|
||||||
|
|
||||||
assert.Error(t, err)
|
assert.Error(t, err)
|
||||||
assert.NotNil(t, fieldErrors)
|
assert.NotNil(t, fieldErrors)
|
||||||
assert.Contains(t, fieldErrors, "benefactor_id")
|
assert.Contains(t, fieldErrors, "benefactor_id")
|
||||||
|
|
||||||
})
|
})
|
||||||
|
|
||||||
t.Run("KindBox Does Not Exist", func(t *testing.T) {
|
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")
|
assert.Contains(t, fieldErrors, "KindBoxID")
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
t.Run("KindBox Delivered And Does Not Belong to Benefactor", func(t *testing.T) {
|
t.Run("KindBox Delivered And Does Not Belong to Benefactor", func(t *testing.T) {
|
||||||
req := adminupdateparam.KindBoxUpdateRequest{
|
req := adminupdateparam.KindBoxUpdateRequest{
|
||||||
KindBoxID: 1,
|
KindBoxID: 1,
|
||||||
|
|
@ -110,14 +103,11 @@ func TestValidator_ValidateUpdateRequest(t *testing.T) {
|
||||||
mockRepository.EXPECT().GetKindBox(ctx, req.KindBoxID).
|
mockRepository.EXPECT().GetKindBox(ctx, req.KindBoxID).
|
||||||
Return(entity.KindBox{}, nil).Once()
|
Return(entity.KindBox{}, nil).Once()
|
||||||
|
|
||||||
|
|
||||||
fieldErrors, err := validator.ValidateUpdateRequest(ctx, req)
|
fieldErrors, err := validator.ValidateUpdateRequest(ctx, req)
|
||||||
|
|
||||||
assert.Error(t, err)
|
assert.Error(t, err)
|
||||||
assert.NotNil(t, fieldErrors)
|
assert.NotNil(t, fieldErrors)
|
||||||
assert.Contains(t, fieldErrors, "KindBoxID")
|
assert.Contains(t, fieldErrors, "KindBoxID")
|
||||||
|
|
||||||
|
|
||||||
})
|
})
|
||||||
|
|
||||||
t.Run("BenefactorID is Null", func(t *testing.T) {
|
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).
|
mockRepository.EXPECT().GetKindBox(ctx, req.KindBoxID).
|
||||||
Return(entity.KindBox{Status: entity.KindBoxDeliveredStatus, BenefactorID: 1}, nil).Once() // Note the different BenefactorID
|
Return(entity.KindBox{Status: entity.KindBoxDeliveredStatus, BenefactorID: 1}, nil).Once() // Note the different BenefactorID
|
||||||
|
|
||||||
|
|
||||||
fieldErrors, err := validator.ValidateUpdateRequest(ctx, req)
|
fieldErrors, err := validator.ValidateUpdateRequest(ctx, req)
|
||||||
|
|
||||||
assert.Error(t, err)
|
assert.Error(t, err)
|
||||||
|
|
@ -139,7 +128,6 @@ func TestValidator_ValidateUpdateRequest(t *testing.T) {
|
||||||
assert.Contains(t, fieldErrors, "benefactor_id")
|
assert.Contains(t, fieldErrors, "benefactor_id")
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
t.Run("Valid KindBox Delivered Request", func(t *testing.T) {
|
t.Run("Valid KindBox Delivered Request", func(t *testing.T) {
|
||||||
req := adminupdateparam.KindBoxUpdateRequest{
|
req := adminupdateparam.KindBoxUpdateRequest{
|
||||||
KindBoxID: 1,
|
KindBoxID: 1,
|
||||||
|
|
@ -186,7 +174,6 @@ func TestValidator_ValidateUpdateRequest(t *testing.T) {
|
||||||
BenefactorID: 2,
|
BenefactorID: 2,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
mockRepository.EXPECT().KindBoxExist(ctx, req.KindBoxID).
|
mockRepository.EXPECT().KindBoxExist(ctx, req.KindBoxID).
|
||||||
Return(true, nil).Once()
|
Return(true, nil).Once()
|
||||||
|
|
||||||
|
|
@ -205,7 +192,6 @@ func TestValidator_ValidateUpdateRequest(t *testing.T) {
|
||||||
mockRepository.EXPECT().GetKindBox(ctx, uint(req.KindBoxID)).
|
mockRepository.EXPECT().GetKindBox(ctx, uint(req.KindBoxID)).
|
||||||
Return(entity.KindBox{Status: entity.KindBoxReadyToReturnStatus, BenefactorID: req.BenefactorID}, nil).Once()
|
Return(entity.KindBox{Status: entity.KindBoxReadyToReturnStatus, BenefactorID: req.BenefactorID}, nil).Once()
|
||||||
|
|
||||||
|
|
||||||
fieldErrors, err := validator.ValidateUpdateRequest(ctx, req)
|
fieldErrors, err := validator.ValidateUpdateRequest(ctx, req)
|
||||||
|
|
||||||
assert.Error(t, err)
|
assert.Error(t, err)
|
||||||
|
|
@ -250,7 +236,6 @@ func TestValidator_ValidateUpdateRequest(t *testing.T) {
|
||||||
mockRepository.EXPECT().GetKindBox(ctx, req.KindBoxID).
|
mockRepository.EXPECT().GetKindBox(ctx, req.KindBoxID).
|
||||||
Return(entity.KindBox{Status: entity.KindBoxReadyToReturnStatus, BenefactorID: req.BenefactorID}, nil).Once()
|
Return(entity.KindBox{Status: entity.KindBoxReadyToReturnStatus, BenefactorID: req.BenefactorID}, nil).Once()
|
||||||
|
|
||||||
|
|
||||||
fieldErrors, err := validator.ValidateUpdateRequest(ctx, req)
|
fieldErrors, err := validator.ValidateUpdateRequest(ctx, req)
|
||||||
|
|
||||||
assert.Error(t, err)
|
assert.Error(t, err)
|
||||||
|
|
@ -258,7 +243,6 @@ func TestValidator_ValidateUpdateRequest(t *testing.T) {
|
||||||
assert.Contains(t, fieldErrors, "return_refere_time_id")
|
assert.Contains(t, fieldErrors, "return_refere_time_id")
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
t.Run("Valid KindBox Ready to Return Status Request", func(t *testing.T) {
|
t.Run("Valid KindBox Ready to Return Status Request", func(t *testing.T) {
|
||||||
req := adminupdateparam.KindBoxUpdateRequest{
|
req := adminupdateparam.KindBoxUpdateRequest{
|
||||||
KindBoxID: 1,
|
KindBoxID: 1,
|
||||||
|
|
@ -293,7 +277,6 @@ func TestValidator_ValidateUpdateRequest(t *testing.T) {
|
||||||
mockRepository.EXPECT().GetKindBox(ctx, req.KindBoxID).
|
mockRepository.EXPECT().GetKindBox(ctx, req.KindBoxID).
|
||||||
Return(entity.KindBox{Status: entity.KindBoxReadyToReturnStatus, BenefactorID: req.BenefactorID}, nil).Once()
|
Return(entity.KindBox{Status: entity.KindBoxReadyToReturnStatus, BenefactorID: req.BenefactorID}, nil).Once()
|
||||||
|
|
||||||
|
|
||||||
mockAddressSvc.EXPECT().GetAddressByID(ctx, addressserviceparam.AddressGetRequest{AddressID: req.ReturnAddressID}).
|
mockAddressSvc.EXPECT().GetAddressByID(ctx, addressserviceparam.AddressGetRequest{AddressID: req.ReturnAddressID}).
|
||||||
Return(addressserviceparam.AddressGetResponse{Address: validAddress}, nil).Once()
|
Return(addressserviceparam.AddressGetResponse{Address: validAddress}, nil).Once()
|
||||||
|
|
||||||
|
|
@ -303,7 +286,6 @@ func TestValidator_ValidateUpdateRequest(t *testing.T) {
|
||||||
mockRepository.EXPECT().GetKindBox(ctx, uint(1)).
|
mockRepository.EXPECT().GetKindBox(ctx, uint(1)).
|
||||||
Return(entity.KindBox{Status: entity.KindBoxReadyToReturnStatus, BenefactorID: req.BenefactorID}, nil).Once()
|
Return(entity.KindBox{Status: entity.KindBoxReadyToReturnStatus, BenefactorID: req.BenefactorID}, nil).Once()
|
||||||
|
|
||||||
|
|
||||||
fieldErrors, err := validator.ValidateUpdateRequest(ctx, req)
|
fieldErrors, err := validator.ValidateUpdateRequest(ctx, req)
|
||||||
|
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
|
|
@ -355,7 +337,6 @@ func TestValidator_ValidateUpdateRequest(t *testing.T) {
|
||||||
ReceiverAgentID: 1,
|
ReceiverAgentID: 1,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
mockRepository.EXPECT().KindBoxExist(ctx, req.KindBoxID).Return(true, nil).Once()
|
mockRepository.EXPECT().KindBoxExist(ctx, req.KindBoxID).Return(true, nil).Once()
|
||||||
|
|
||||||
mockBenefactorSvc.EXPECT().BenefactorExistByID(ctx, benefactorserviceparam.BenefactorExistByIDRequest{ID: req.BenefactorID}).
|
mockBenefactorSvc.EXPECT().BenefactorExistByID(ctx, benefactorserviceparam.BenefactorExistByIDRequest{ID: req.BenefactorID}).
|
||||||
|
|
@ -394,7 +375,6 @@ func TestValidator_ValidateUpdateRequest(t *testing.T) {
|
||||||
|
|
||||||
assert.Error(t, err)
|
assert.Error(t, err)
|
||||||
assert.NotNil(t, fieldErrors)
|
assert.NotNil(t, fieldErrors)
|
||||||
|
|
||||||
})
|
})
|
||||||
|
|
||||||
t.Run("Invalid KindBox Enumerate Status Amount", func(t *testing.T) {
|
t.Run("Invalid KindBox Enumerate Status Amount", func(t *testing.T) {
|
||||||
|
|
@ -404,13 +384,11 @@ func TestValidator_ValidateUpdateRequest(t *testing.T) {
|
||||||
Amount: 0,
|
Amount: 0,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
mockRepository.EXPECT().KindBoxExist(ctx, req.KindBoxID).Return(true, nil).Once()
|
mockRepository.EXPECT().KindBoxExist(ctx, req.KindBoxID).Return(true, nil).Once()
|
||||||
|
|
||||||
mockBenefactorSvc.EXPECT().BenefactorExistByID(ctx, benefactorserviceparam.BenefactorExistByIDRequest{ID: req.BenefactorID}).
|
mockBenefactorSvc.EXPECT().BenefactorExistByID(ctx, benefactorserviceparam.BenefactorExistByIDRequest{ID: req.BenefactorID}).
|
||||||
Return(benefactorserviceparam.BenefactorExistByIDResponse{Existed: true}, nil).Once()
|
Return(benefactorserviceparam.BenefactorExistByIDResponse{Existed: true}, nil).Once()
|
||||||
|
|
||||||
|
|
||||||
mockRepository.EXPECT().GetKindBox(ctx, req.KindBoxID).
|
mockRepository.EXPECT().GetKindBox(ctx, req.KindBoxID).
|
||||||
Return(entity.KindBox{
|
Return(entity.KindBox{
|
||||||
Status: entity.KindBoxEnumeratedStatus,
|
Status: entity.KindBoxEnumeratedStatus,
|
||||||
|
|
@ -424,7 +402,6 @@ func TestValidator_ValidateUpdateRequest(t *testing.T) {
|
||||||
assert.Contains(t, fieldErrors, "amount")
|
assert.Contains(t, fieldErrors, "amount")
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
t.Run("Valid KindBox Enumerated Status Request", func(t *testing.T) {
|
t.Run("Valid KindBox Enumerated Status Request", func(t *testing.T) {
|
||||||
req := adminupdateparam.KindBoxUpdateRequest{
|
req := adminupdateparam.KindBoxUpdateRequest{
|
||||||
KindBoxID: 1,
|
KindBoxID: 1,
|
||||||
|
|
@ -432,13 +409,11 @@ func TestValidator_ValidateUpdateRequest(t *testing.T) {
|
||||||
Amount: 100,
|
Amount: 100,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
mockRepository.EXPECT().KindBoxExist(ctx, req.KindBoxID).Return(true, nil).Once()
|
mockRepository.EXPECT().KindBoxExist(ctx, req.KindBoxID).Return(true, nil).Once()
|
||||||
|
|
||||||
mockBenefactorSvc.EXPECT().BenefactorExistByID(ctx, benefactorserviceparam.BenefactorExistByIDRequest{ID: req.BenefactorID}).
|
mockBenefactorSvc.EXPECT().BenefactorExistByID(ctx, benefactorserviceparam.BenefactorExistByIDRequest{ID: req.BenefactorID}).
|
||||||
Return(benefactorserviceparam.BenefactorExistByIDResponse{Existed: true}, nil).Once()
|
Return(benefactorserviceparam.BenefactorExistByIDResponse{Existed: true}, nil).Once()
|
||||||
|
|
||||||
|
|
||||||
mockRepository.EXPECT().GetKindBox(ctx, req.KindBoxID).
|
mockRepository.EXPECT().GetKindBox(ctx, req.KindBoxID).
|
||||||
Return(entity.KindBox{
|
Return(entity.KindBox{
|
||||||
Status: entity.KindBoxEnumeratedStatus,
|
Status: entity.KindBoxEnumeratedStatus,
|
||||||
|
|
|
||||||
|
|
@ -4,11 +4,11 @@ import (
|
||||||
"context"
|
"context"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
params "git.gocasts.ir/ebhomengo/niki/param"
|
|
||||||
"slices"
|
"slices"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
entity "git.gocasts.ir/ebhomengo/niki/entity"
|
entity "git.gocasts.ir/ebhomengo/niki/entity"
|
||||||
|
params "git.gocasts.ir/ebhomengo/niki/param"
|
||||||
adminaddressparam "git.gocasts.ir/ebhomengo/niki/param/admin/address"
|
adminaddressparam "git.gocasts.ir/ebhomengo/niki/param/admin/address"
|
||||||
agentparam "git.gocasts.ir/ebhomengo/niki/param/admin/agent"
|
agentparam "git.gocasts.ir/ebhomengo/niki/param/admin/agent"
|
||||||
param "git.gocasts.ir/ebhomengo/niki/param/admin/benefactor"
|
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)
|
fetchedKindBox, err := v.repo.GetKindBox(ctx, kindBoxID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
||||||
return richerror.New(op).WithErr(err).WithMessage("could not fetch KindBox").WithKind(richerror.KindUnexpected)
|
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
|
return nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (v Validator) doesBenefactorAddressExist(ctx context.Context, kindBoxID uint, benefactorID uint, addressID uint) validation.RuleFunc {
|
func (v Validator) doesBenefactorAddressExist(ctx context.Context, kindBoxID uint, benefactorID uint, addressID uint) validation.RuleFunc {
|
||||||
return func(value interface{}) error {
|
return func(value interface{}) error {
|
||||||
const op = "Validator.doesBenefactorAddressExist"
|
const op = "Validator.doesBenefactorAddressExist"
|
||||||
|
|
|
||||||
|
|
@ -3,9 +3,9 @@ package agentkindboxvalidator
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
params "git.gocasts.ir/ebhomengo/niki/param"
|
|
||||||
"slices"
|
"slices"
|
||||||
|
|
||||||
|
params "git.gocasts.ir/ebhomengo/niki/param"
|
||||||
errmsg "git.gocasts.ir/ebhomengo/niki/pkg/err_msg"
|
errmsg "git.gocasts.ir/ebhomengo/niki/pkg/err_msg"
|
||||||
validation "github.com/go-ozzo/ozzo-validation/v4"
|
validation "github.com/go-ozzo/ozzo-validation/v4"
|
||||||
)
|
)
|
||||||
|
|
@ -39,6 +39,7 @@ func (v Validator) doesKindBoxExistForAgent(ctx context.Context, agentID uint) v
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (v Validator) AreSortFieldsValid(validSortFields []string) validation.RuleFunc {
|
func (v Validator) AreSortFieldsValid(validSortFields []string) validation.RuleFunc {
|
||||||
return func(value interface{}) error {
|
return func(value interface{}) error {
|
||||||
sort, ok := value.(params.SortRequest)
|
sort, ok := value.(params.SortRequest)
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,7 @@ package agentkindboxreqvalidator
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"errors"
|
"errors"
|
||||||
|
|
||||||
param "git.gocasts.ir/ebhomengo/niki/param/agent/kind_box_req"
|
param "git.gocasts.ir/ebhomengo/niki/param/agent/kind_box_req"
|
||||||
errmsg "git.gocasts.ir/ebhomengo/niki/pkg/err_msg"
|
errmsg "git.gocasts.ir/ebhomengo/niki/pkg/err_msg"
|
||||||
richerror "git.gocasts.ir/ebhomengo/niki/pkg/rich_error"
|
richerror "git.gocasts.ir/ebhomengo/niki/pkg/rich_error"
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,7 @@ package agentkindboxreqvalidator
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
|
|
||||||
kbrparam "git.gocasts.ir/ebhomengo/niki/param/agent/kind_box_req"
|
kbrparam "git.gocasts.ir/ebhomengo/niki/param/agent/kind_box_req"
|
||||||
errmsg "git.gocasts.ir/ebhomengo/niki/pkg/err_msg"
|
errmsg "git.gocasts.ir/ebhomengo/niki/pkg/err_msg"
|
||||||
richerror "git.gocasts.ir/ebhomengo/niki/pkg/rich_error"
|
richerror "git.gocasts.ir/ebhomengo/niki/pkg/rich_error"
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,7 @@ package agentkindboxreqvalidator
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
|
|
||||||
param "git.gocasts.ir/ebhomengo/niki/param/agent/kind_box_req"
|
param "git.gocasts.ir/ebhomengo/niki/param/agent/kind_box_req"
|
||||||
errmsg "git.gocasts.ir/ebhomengo/niki/pkg/err_msg"
|
errmsg "git.gocasts.ir/ebhomengo/niki/pkg/err_msg"
|
||||||
richerror "git.gocasts.ir/ebhomengo/niki/pkg/rich_error"
|
richerror "git.gocasts.ir/ebhomengo/niki/pkg/rich_error"
|
||||||
|
|
|
||||||
|
|
@ -4,10 +4,10 @@ import (
|
||||||
"context"
|
"context"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"git.gocasts.ir/ebhomengo/niki/entity"
|
|
||||||
params "git.gocasts.ir/ebhomengo/niki/param"
|
|
||||||
"slices"
|
"slices"
|
||||||
|
|
||||||
|
"git.gocasts.ir/ebhomengo/niki/entity"
|
||||||
|
params "git.gocasts.ir/ebhomengo/niki/param"
|
||||||
errmsg "git.gocasts.ir/ebhomengo/niki/pkg/err_msg"
|
errmsg "git.gocasts.ir/ebhomengo/niki/pkg/err_msg"
|
||||||
validation "github.com/go-ozzo/ozzo-validation/v4"
|
validation "github.com/go-ozzo/ozzo-validation/v4"
|
||||||
)
|
)
|
||||||
|
|
|
||||||
|
|
@ -2,12 +2,13 @@ package benefactorvalidator
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"testing"
|
||||||
|
|
||||||
"git.gocasts.ir/ebhomengo/niki/entity"
|
"git.gocasts.ir/ebhomengo/niki/entity"
|
||||||
benefactoreparam "git.gocasts.ir/ebhomengo/niki/param/benefactor/benefactor"
|
benefactoreparam "git.gocasts.ir/ebhomengo/niki/param/benefactor/benefactor"
|
||||||
errmsg "git.gocasts.ir/ebhomengo/niki/pkg/err_msg"
|
errmsg "git.gocasts.ir/ebhomengo/niki/pkg/err_msg"
|
||||||
richerror "git.gocasts.ir/ebhomengo/niki/pkg/rich_error"
|
richerror "git.gocasts.ir/ebhomengo/niki/pkg/rich_error"
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
"testing"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestValidator_ValidateSendOtpRequest(t *testing.T) {
|
func TestValidator_ValidateSendOtpRequest(t *testing.T) {
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,7 @@ import (
|
||||||
"context"
|
"context"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
"git.gocasts.ir/ebhomengo/niki/entity"
|
"git.gocasts.ir/ebhomengo/niki/entity"
|
||||||
errmsg "git.gocasts.ir/ebhomengo/niki/pkg/err_msg"
|
errmsg "git.gocasts.ir/ebhomengo/niki/pkg/err_msg"
|
||||||
richerror "git.gocasts.ir/ebhomengo/niki/pkg/rich_error"
|
richerror "git.gocasts.ir/ebhomengo/niki/pkg/rich_error"
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue