forked from ebhomengo/niki
feat(admin): add search query param(#195)
add search on get all in benefactor, kindbox and kindboxreq endpoint
This commit is contained in:
parent
e1fde10138
commit
07b7509a50
|
|
@ -14,6 +14,7 @@ import (
|
||||||
// @Tags Admins Benefactors
|
// @Tags Admins Benefactors
|
||||||
// @Accept json
|
// @Accept json
|
||||||
// @Produce json
|
// @Produce json
|
||||||
|
// @Param search query string false "Search by id, phone_number, concat(first_name, last_name) benefactor"
|
||||||
// @Param filter_id query int false "Filter by ID"
|
// @Param filter_id query int false "Filter by ID"
|
||||||
// @Param filter_first_name query string false "Filter by first_name"
|
// @Param filter_first_name query string false "Filter by first_name"
|
||||||
// @Param filter_last_name query string false "Filter by last_name"
|
// @Param filter_last_name query string false "Filter by last_name"
|
||||||
|
|
|
||||||
|
|
@ -15,6 +15,7 @@ import (
|
||||||
// @Tags Admins KindBoxes
|
// @Tags Admins KindBoxes
|
||||||
// @Accept json
|
// @Accept json
|
||||||
// @Produce json
|
// @Produce json
|
||||||
|
// @Param search query string false "Search by id, phone_number, concat(first_name, last_name) benefactor"
|
||||||
// @Param filter_id query int false "Filter by ID"
|
// @Param filter_id query int false "Filter by ID"
|
||||||
// @Param filter_kind_box_req_id query int false "Filter by KindBox request ID"
|
// @Param filter_kind_box_req_id query int false "Filter by KindBox request ID"
|
||||||
// @Param filter_benefactor_id query int false "Filter by benefactor ID"
|
// @Param filter_benefactor_id query int false "Filter by benefactor ID"
|
||||||
|
|
|
||||||
|
|
@ -15,6 +15,7 @@ import (
|
||||||
// @Tags Admins KindBoxReqs
|
// @Tags Admins KindBoxReqs
|
||||||
// @Accept json
|
// @Accept json
|
||||||
// @Produce json
|
// @Produce json
|
||||||
|
// @Param search query string false "Search by id, phone_number, concat(first_name, last_name) benefactor"
|
||||||
// @Param filter_id query int false "Filter by ID"
|
// @Param filter_id query int false "Filter by ID"
|
||||||
// @Param filter_benefactor_id query int false "Filter by benefactor ID"
|
// @Param filter_benefactor_id query int false "Filter by benefactor ID"
|
||||||
// @Param filter_sender_agent_id query int false "Filter by sender agent ID"
|
// @Param filter_sender_agent_id query int false "Filter by sender agent ID"
|
||||||
|
|
|
||||||
|
|
@ -10,10 +10,6 @@ func (h Handler) SetRoutes(e *echo.Echo) {
|
||||||
r := e.Group("/admins/refer-times")
|
r := e.Group("/admins/refer-times")
|
||||||
|
|
||||||
r.Use(middleware.Auth(h.authSvc))
|
r.Use(middleware.Auth(h.authSvc))
|
||||||
r.Use(
|
|
||||||
middleware.Auth(h.authSvc),
|
|
||||||
middleware.AdminAuthorization(h.adminAuthorizeSvc, entity.AdminKindBoxReqAddPermission),
|
|
||||||
)
|
|
||||||
|
|
||||||
r.GET("", h.GetAll)
|
r.GET("", h.GetAll, middleware.AdminAuthorization(h.adminAuthorizeSvc, entity.AdminReferTimeGetAllPermission))
|
||||||
}
|
}
|
||||||
|
|
|
||||||
18
docs/docs.go
18
docs/docs.go
|
|
@ -66,6 +66,12 @@ const docTemplate = `{
|
||||||
],
|
],
|
||||||
"summary": "Get all benefactors by admin",
|
"summary": "Get all benefactors by admin",
|
||||||
"parameters": [
|
"parameters": [
|
||||||
|
{
|
||||||
|
"type": "string",
|
||||||
|
"description": "Search by id, phone_number, concat(first_name, last_name) benefactor",
|
||||||
|
"name": "search",
|
||||||
|
"in": "query"
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"type": "integer",
|
"type": "integer",
|
||||||
"description": "Filter by ID",
|
"description": "Filter by ID",
|
||||||
|
|
@ -270,6 +276,12 @@ const docTemplate = `{
|
||||||
],
|
],
|
||||||
"summary": "Get all KindBoxes by admin",
|
"summary": "Get all KindBoxes by admin",
|
||||||
"parameters": [
|
"parameters": [
|
||||||
|
{
|
||||||
|
"type": "string",
|
||||||
|
"description": "Search by id, phone_number, concat(first_name, last_name) benefactor",
|
||||||
|
"name": "search",
|
||||||
|
"in": "query"
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"type": "integer",
|
"type": "integer",
|
||||||
"description": "Filter by ID",
|
"description": "Filter by ID",
|
||||||
|
|
@ -706,6 +718,12 @@ const docTemplate = `{
|
||||||
],
|
],
|
||||||
"summary": "Admin get all kindboxreq",
|
"summary": "Admin get all kindboxreq",
|
||||||
"parameters": [
|
"parameters": [
|
||||||
|
{
|
||||||
|
"type": "string",
|
||||||
|
"description": "Search by id, phone_number, concat(first_name, last_name) benefactor",
|
||||||
|
"name": "search",
|
||||||
|
"in": "query"
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"type": "integer",
|
"type": "integer",
|
||||||
"description": "Filter by ID",
|
"description": "Filter by ID",
|
||||||
|
|
|
||||||
|
|
@ -55,6 +55,12 @@
|
||||||
],
|
],
|
||||||
"summary": "Get all benefactors by admin",
|
"summary": "Get all benefactors by admin",
|
||||||
"parameters": [
|
"parameters": [
|
||||||
|
{
|
||||||
|
"type": "string",
|
||||||
|
"description": "Search by id, phone_number, concat(first_name, last_name) benefactor",
|
||||||
|
"name": "search",
|
||||||
|
"in": "query"
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"type": "integer",
|
"type": "integer",
|
||||||
"description": "Filter by ID",
|
"description": "Filter by ID",
|
||||||
|
|
@ -259,6 +265,12 @@
|
||||||
],
|
],
|
||||||
"summary": "Get all KindBoxes by admin",
|
"summary": "Get all KindBoxes by admin",
|
||||||
"parameters": [
|
"parameters": [
|
||||||
|
{
|
||||||
|
"type": "string",
|
||||||
|
"description": "Search by id, phone_number, concat(first_name, last_name) benefactor",
|
||||||
|
"name": "search",
|
||||||
|
"in": "query"
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"type": "integer",
|
"type": "integer",
|
||||||
"description": "Filter by ID",
|
"description": "Filter by ID",
|
||||||
|
|
@ -695,6 +707,12 @@
|
||||||
],
|
],
|
||||||
"summary": "Admin get all kindboxreq",
|
"summary": "Admin get all kindboxreq",
|
||||||
"parameters": [
|
"parameters": [
|
||||||
|
{
|
||||||
|
"type": "string",
|
||||||
|
"description": "Search by id, phone_number, concat(first_name, last_name) benefactor",
|
||||||
|
"name": "search",
|
||||||
|
"in": "query"
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"type": "integer",
|
"type": "integer",
|
||||||
"description": "Filter by ID",
|
"description": "Filter by ID",
|
||||||
|
|
|
||||||
|
|
@ -1109,6 +1109,10 @@ paths:
|
||||||
consumes:
|
consumes:
|
||||||
- application/json
|
- application/json
|
||||||
parameters:
|
parameters:
|
||||||
|
- description: Search by id, phone_number, concat(first_name, last_name) benefactor
|
||||||
|
in: query
|
||||||
|
name: search
|
||||||
|
type: string
|
||||||
- description: Filter by ID
|
- description: Filter by ID
|
||||||
in: query
|
in: query
|
||||||
name: filter_id
|
name: filter_id
|
||||||
|
|
@ -1245,6 +1249,10 @@ paths:
|
||||||
description: Retrieves a list of all KindBoxes with filtering, sorting, and
|
description: Retrieves a list of all KindBoxes with filtering, sorting, and
|
||||||
pagination options
|
pagination options
|
||||||
parameters:
|
parameters:
|
||||||
|
- description: Search by id, phone_number, concat(first_name, last_name) benefactor
|
||||||
|
in: query
|
||||||
|
name: search
|
||||||
|
type: string
|
||||||
- description: Filter by ID
|
- description: Filter by ID
|
||||||
in: query
|
in: query
|
||||||
name: filter_id
|
name: filter_id
|
||||||
|
|
@ -1536,6 +1544,10 @@ paths:
|
||||||
description: Retrieves a list of all KindBox requests with filtering, sorting,
|
description: Retrieves a list of all KindBox requests with filtering, sorting,
|
||||||
and pagination options
|
and pagination options
|
||||||
parameters:
|
parameters:
|
||||||
|
- description: Search by id, phone_number, concat(first_name, last_name) benefactor
|
||||||
|
in: query
|
||||||
|
name: search
|
||||||
|
type: string
|
||||||
- description: Filter by ID
|
- description: Filter by ID
|
||||||
in: query
|
in: query
|
||||||
name: filter_id
|
name: filter_id
|
||||||
|
|
|
||||||
|
|
@ -23,4 +23,5 @@ const (
|
||||||
AdminKindBoxEnumeratePermission = AdminPermission("kindbox-enumerate")
|
AdminKindBoxEnumeratePermission = AdminPermission("kindbox-enumerate")
|
||||||
AdminKindBoxUpdatePermission = AdminPermission("kindbox-update")
|
AdminKindBoxUpdatePermission = AdminPermission("kindbox-update")
|
||||||
AdminBenefactorGetPermission = AdminPermission("benefactor-get")
|
AdminBenefactorGetPermission = AdminPermission("benefactor-get")
|
||||||
|
AdminReferTimeGetAllPermission = AdminPermission("refertime-getall")
|
||||||
)
|
)
|
||||||
|
|
|
||||||
|
|
@ -8,6 +8,7 @@ type BenefactorGetAllRequest struct {
|
||||||
Pagination param.PaginationRequest
|
Pagination param.PaginationRequest
|
||||||
Sort param.SortRequest
|
Sort param.SortRequest
|
||||||
Filter param.FilterRequest
|
Filter param.FilterRequest
|
||||||
|
Search param.SearchRequest
|
||||||
}
|
}
|
||||||
type BenefactorGetAllResponse struct {
|
type BenefactorGetAllResponse struct {
|
||||||
Data []Data `json:"data"`
|
Data []Data `json:"data"`
|
||||||
|
|
|
||||||
|
|
@ -8,6 +8,7 @@ type KindBoxGetAllRequest struct {
|
||||||
Pagination param.PaginationRequest
|
Pagination param.PaginationRequest
|
||||||
Sort param.SortRequest
|
Sort param.SortRequest
|
||||||
Filter param.FilterRequest
|
Filter param.FilterRequest
|
||||||
|
Search param.SearchRequest
|
||||||
}
|
}
|
||||||
|
|
||||||
type KindBoxGetAllResponse struct {
|
type KindBoxGetAllResponse struct {
|
||||||
|
|
|
||||||
|
|
@ -8,6 +8,7 @@ type KindBoxReqGetAllRequest struct {
|
||||||
Pagination param.PaginationRequest
|
Pagination param.PaginationRequest
|
||||||
Sort param.SortRequest
|
Sort param.SortRequest
|
||||||
Filter param.FilterRequest
|
Filter param.FilterRequest
|
||||||
|
Search param.SearchRequest
|
||||||
}
|
}
|
||||||
|
|
||||||
type KindBoxReqGetAllResponse struct {
|
type KindBoxReqGetAllResponse struct {
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,34 @@
|
||||||
|
package param
|
||||||
|
|
||||||
|
import (
|
||||||
|
"regexp"
|
||||||
|
"strings"
|
||||||
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
id = "benefactors.id"
|
||||||
|
phoneNumber = "benefactors.phone_number"
|
||||||
|
fullName = "concat(benefactors.first_name, benefactors.last_name)"
|
||||||
|
)
|
||||||
|
|
||||||
|
var searchItems = []string{id, phoneNumber, fullName}
|
||||||
|
|
||||||
|
type SearchRequest struct {
|
||||||
|
Query string `query:"search" example:"09123456789"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type QuerySearch map[string]any
|
||||||
|
|
||||||
|
func (s *SearchRequest) GetSearch() *QuerySearch {
|
||||||
|
searchParams := QuerySearch{}
|
||||||
|
|
||||||
|
if s.Query != "" {
|
||||||
|
s.Query = strings.TrimSpace(s.Query)
|
||||||
|
re := regexp.MustCompile(`[\p{P}\p{S}]+`)
|
||||||
|
s.Query = re.ReplaceAllString(s.Query, "")
|
||||||
|
for _, val := range searchItems {
|
||||||
|
searchParams[val] = s.Query
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return &searchParams
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,35 @@
|
||||||
|
package mysqlquerybuilder
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"strings"
|
||||||
|
)
|
||||||
|
|
||||||
|
func BuildDeletedAtQuery(query, table string) string {
|
||||||
|
deletedAtClause := fmt.Sprintf(" %s.deleted_at IS NULL ", table)
|
||||||
|
|
||||||
|
if !strings.Contains(query, "WHERE") {
|
||||||
|
return appendStringBefore(query, "WHERE", deletedAtClause)
|
||||||
|
}
|
||||||
|
|
||||||
|
return appendStringAfter(query, "AND", deletedAtClause)
|
||||||
|
}
|
||||||
|
|
||||||
|
func appendStringBefore(s, operator, appendage string) string {
|
||||||
|
limitIndex := strings.Index(strings.ToUpper(s), "LIMIT")
|
||||||
|
if limitIndex == -1 {
|
||||||
|
return s + operator + appendage
|
||||||
|
}
|
||||||
|
return s[:limitIndex] + operator + appendage + s[limitIndex:]
|
||||||
|
}
|
||||||
|
|
||||||
|
func appendStringAfter(s, operator, appendage string) string {
|
||||||
|
index := strings.Index(strings.ToUpper(s), "WHERE")
|
||||||
|
|
||||||
|
spaceAfterTarget := strings.Index(s[index:], " ")
|
||||||
|
if spaceAfterTarget == -1 {
|
||||||
|
spaceAfterTarget = len(s) - index
|
||||||
|
}
|
||||||
|
|
||||||
|
return s[:index+spaceAfterTarget] + appendage + operator + s[index+spaceAfterTarget:]
|
||||||
|
}
|
||||||
|
|
@ -12,16 +12,16 @@ func isValidDateOrDateTime(value string) bool {
|
||||||
return datePattern.MatchString(value)
|
return datePattern.MatchString(value)
|
||||||
}
|
}
|
||||||
|
|
||||||
func BuildFilterQuery(baseQuery string, filter map[string]interface{}) (string, []any) {
|
func BuildFilterQuery(baseQuery, table string, filter map[string]interface{}) (string, []any) {
|
||||||
var conditions []string
|
var conditions []string
|
||||||
var args []any
|
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) {
|
||||||
conditions = append(conditions, fmt.Sprintf("DATE(%s) = ?", key))
|
conditions = append(conditions, fmt.Sprintf("DATE(%s.%s) = ?", table, key))
|
||||||
args = append(args, strVal)
|
args = append(args, strVal)
|
||||||
} else {
|
} else {
|
||||||
conditions = append(conditions, fmt.Sprintf("%s = ?", key))
|
conditions = append(conditions, fmt.Sprintf("%s.%s = ?", table, key))
|
||||||
args = append(args, value)
|
args = append(args, value)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,8 +6,8 @@ import (
|
||||||
"git.gocasts.ir/ebhomengo/niki/param"
|
"git.gocasts.ir/ebhomengo/niki/param"
|
||||||
)
|
)
|
||||||
|
|
||||||
func BuildGetAllQuery(baseQuery string, filter param.FilterRequest, pagination param.PaginationRequest, sort param.SortRequest) (query string, args []any) {
|
func BuildGetAllQuery(baseQuery, table string, filter param.FilterRequest, pagination param.PaginationRequest, sort param.SortRequest) (query string, args []any) {
|
||||||
filterQuery, fArgs := BuildFilterQuery(baseQuery, filter)
|
filterQuery, fArgs := BuildFilterQuery(baseQuery, table, filter)
|
||||||
paginationQuery, pArgs := BuildPaginationQuery(pagination)
|
paginationQuery, pArgs := BuildPaginationQuery(pagination)
|
||||||
sortQuery := BuildSortQuery(sort)
|
sortQuery := BuildSortQuery(sort)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,38 @@
|
||||||
|
package mysqlquerybuilder
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"strings"
|
||||||
|
)
|
||||||
|
|
||||||
|
// TODO: implementation more complete search service.
|
||||||
|
|
||||||
|
func BuildGetSearchQuery(baseQuery string, filter map[string]interface{}, exist bool) (string, []any) {
|
||||||
|
var conditions []string
|
||||||
|
var args []any
|
||||||
|
for key, value := range filter {
|
||||||
|
if key == "id" {
|
||||||
|
conditions = append(conditions, fmt.Sprintf("%s = ?", key))
|
||||||
|
} else {
|
||||||
|
conditions = append(conditions, fmt.Sprintf("%s LIKE ?", key))
|
||||||
|
}
|
||||||
|
args = append(args, value)
|
||||||
|
}
|
||||||
|
|
||||||
|
query := baseQuery
|
||||||
|
if len(conditions) > 0 {
|
||||||
|
subQuery := strings.Join(conditions, " OR ")
|
||||||
|
if exist {
|
||||||
|
query += fmt.Sprintf(" INNER JOIN benefactors ON benefactor_id = benefactors.id WHERE (%s) ", subQuery)
|
||||||
|
} else {
|
||||||
|
if strings.Contains(strings.ToUpper(baseQuery), "WHERE") {
|
||||||
|
query += " AND "
|
||||||
|
} else {
|
||||||
|
query += " WHERE "
|
||||||
|
}
|
||||||
|
query += subQuery
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return query, args
|
||||||
|
}
|
||||||
|
|
@ -10,11 +10,16 @@ import (
|
||||||
richerror "git.gocasts.ir/ebhomengo/niki/pkg/rich_error"
|
richerror "git.gocasts.ir/ebhomengo/niki/pkg/rich_error"
|
||||||
)
|
)
|
||||||
|
|
||||||
func (d *DB) GetAllBenefactor(ctx context.Context, filter params.FilterRequest, pagination params.PaginationRequest, sort params.SortRequest) ([]entity.Benefactor, uint, error) {
|
func (d *DB) GetAllBenefactor(ctx context.Context, filter params.FilterRequest, pagination params.PaginationRequest, sort params.SortRequest, searchParams *params.QuerySearch) ([]entity.Benefactor, uint, error) {
|
||||||
const op = "mysqlbenefactor.GetAllBenefactor"
|
const op = "mysqlbenefactor.GetAllBenefactor"
|
||||||
|
table := "benefactors"
|
||||||
|
|
||||||
baseQuery := `SELECT * FROM benefactors`
|
baseQuery := `SELECT * FROM benefactors`
|
||||||
query, args := builder.BuildGetAllQuery(baseQuery, filter, pagination, sort)
|
|
||||||
|
searchQuery, sArgs := builder.BuildGetSearchQuery(baseQuery, *searchParams, false)
|
||||||
|
query, fArgs := builder.BuildGetAllQuery(searchQuery, table, filter, pagination, sort)
|
||||||
|
args := append(sArgs, fArgs...)
|
||||||
|
|
||||||
rows, qErr := d.conn.Conn().QueryContext(ctx, query, args...)
|
rows, qErr := d.conn.Conn().QueryContext(ctx, query, args...)
|
||||||
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)
|
||||||
|
|
@ -38,7 +43,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, params.PaginationRequest{}, params.SortRequest{})
|
query, args = builder.BuildGetAllQuery(baseQuery, table, filter, params.PaginationRequest{}, params.SortRequest{})
|
||||||
qErr = d.conn.Conn().QueryRowContext(ctx, query, args...).Scan(&total)
|
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)
|
||||||
|
|
|
||||||
|
|
@ -10,11 +10,17 @@ import (
|
||||||
richerror "git.gocasts.ir/ebhomengo/niki/pkg/rich_error"
|
richerror "git.gocasts.ir/ebhomengo/niki/pkg/rich_error"
|
||||||
)
|
)
|
||||||
|
|
||||||
func (d *DB) GetAllKindBox(ctx context.Context, filter params.FilterRequest, pagination params.PaginationRequest, sort params.SortRequest) ([]entity.KindBox, uint, error) {
|
func (d *DB) GetAllKindBox(ctx context.Context, filter params.FilterRequest, pagination params.PaginationRequest, sort params.SortRequest, searchParams *params.QuerySearch) ([]entity.KindBox, uint, error) {
|
||||||
const op = "mysqlkindbox.GetAllKindBox"
|
const op = "mysqlkindbox.GetAllKindBox"
|
||||||
|
table := "kind_boxes"
|
||||||
|
|
||||||
|
baseQuery := `SELECT kind_boxes.* FROM kind_boxes`
|
||||||
|
|
||||||
|
searchQuery, sArgs := builder.BuildGetSearchQuery(baseQuery, *searchParams, true)
|
||||||
|
filterQuery, fArgs := builder.BuildGetAllQuery(searchQuery, table, filter, pagination, sort)
|
||||||
|
query := builder.BuildDeletedAtQuery(filterQuery, table)
|
||||||
|
args := append(sArgs, fArgs...)
|
||||||
|
|
||||||
baseQuery := `SELECT * FROM kind_boxes WHERE deleted_at IS NULL`
|
|
||||||
query, args := builder.BuildGetAllQuery(baseQuery, filter, pagination, sort)
|
|
||||||
rows, qErr := d.conn.Conn().QueryContext(ctx, query, args...)
|
rows, qErr := d.conn.Conn().QueryContext(ctx, query, args...)
|
||||||
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)
|
||||||
|
|
@ -37,7 +43,7 @@ func (d *DB) GetAllKindBox(ctx context.Context, filter params.FilterRequest, pag
|
||||||
|
|
||||||
var total uint
|
var total uint
|
||||||
baseQuery = `SELECT COUNT(*) FROM kind_boxes WHERE deleted_at IS NULL`
|
baseQuery = `SELECT COUNT(*) FROM kind_boxes WHERE deleted_at IS NULL`
|
||||||
query, args = builder.BuildGetAllQuery(baseQuery, filter, params.PaginationRequest{}, params.SortRequest{})
|
query, args = builder.BuildGetAllQuery(baseQuery, table, filter, params.PaginationRequest{}, params.SortRequest{})
|
||||||
qErr = d.conn.Conn().QueryRowContext(ctx, query, args...).Scan(&total)
|
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)
|
||||||
|
|
|
||||||
|
|
@ -10,11 +10,17 @@ import (
|
||||||
richerror "git.gocasts.ir/ebhomengo/niki/pkg/rich_error"
|
richerror "git.gocasts.ir/ebhomengo/niki/pkg/rich_error"
|
||||||
)
|
)
|
||||||
|
|
||||||
func (d *DB) GetAllKindBoxReq(ctx context.Context, filter param.FilterRequest, pagination param.PaginationRequest, sort param.SortRequest) ([]entity.KindBoxReq, uint, error) {
|
func (d *DB) GetAllKindBoxReq(ctx context.Context, filter param.FilterRequest, pagination param.PaginationRequest, sort param.SortRequest, searchParams *param.QuerySearch) ([]entity.KindBoxReq, uint, error) {
|
||||||
const op = "mysqlkindboxreq.GetAllKindBoxReq"
|
const op = "mysqlkindboxreq.GetAllKindBoxReq"
|
||||||
|
table := "kind_box_reqs"
|
||||||
|
|
||||||
|
baseQuery := `SELECT kind_box_reqs.* FROM kind_box_reqs`
|
||||||
|
|
||||||
|
searchQuery, sArgs := builder.BuildGetSearchQuery(baseQuery, *searchParams, true)
|
||||||
|
filterQuery, fArgs := builder.BuildGetAllQuery(searchQuery, table, filter, pagination, sort)
|
||||||
|
query := builder.BuildDeletedAtQuery(filterQuery, table)
|
||||||
|
args := append(sArgs, fArgs...)
|
||||||
|
|
||||||
baseQuery := `SELECT * FROM kind_box_reqs WHERE deleted_at IS NULL`
|
|
||||||
query, args := builder.BuildGetAllQuery(baseQuery, filter, pagination, sort)
|
|
||||||
rows, qErr := d.conn.Conn().QueryContext(ctx, query, args...)
|
rows, qErr := d.conn.Conn().QueryContext(ctx, query, args...)
|
||||||
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)
|
||||||
|
|
@ -37,7 +43,7 @@ func (d *DB) GetAllKindBoxReq(ctx context.Context, filter param.FilterRequest, p
|
||||||
|
|
||||||
var total uint
|
var total uint
|
||||||
baseQuery = `SELECT COUNT(*) FROM kind_box_reqs WHERE deleted_at IS NULL`
|
baseQuery = `SELECT COUNT(*) FROM kind_box_reqs WHERE deleted_at IS NULL`
|
||||||
query, args = builder.BuildGetAllQuery(baseQuery, filter, param.PaginationRequest{}, param.SortRequest{})
|
query, args = builder.BuildGetAllQuery(baseQuery, table, filter, param.PaginationRequest{}, param.SortRequest{})
|
||||||
qErr = d.conn.Conn().QueryRowContext(ctx, query, args...).Scan(&total)
|
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)
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,33 @@
|
||||||
|
-- +migrate Up
|
||||||
|
ALTER TABLE `admin_access_controls` MODIFY COLUMN `permission`
|
||||||
|
enum (
|
||||||
|
'admin-register',
|
||||||
|
'kindboxreq-accept',
|
||||||
|
'kindboxreq-reject',
|
||||||
|
'kindboxreq-getall',
|
||||||
|
'kindboxreq-deliver',
|
||||||
|
'kindboxreq-assign_sender_agent',
|
||||||
|
'admin-getall_agent',
|
||||||
|
'kindboxreq-get_awaiting_delivery',
|
||||||
|
'kindbox-get',
|
||||||
|
'kindboxreq-add',
|
||||||
|
'kindbox-assign_receiver_agent',
|
||||||
|
'kindbox-getall',
|
||||||
|
'kindboxreq-update',
|
||||||
|
'kindboxreq-get',
|
||||||
|
'kindbox-get_awaiting_return',
|
||||||
|
'kindbox-return',
|
||||||
|
'kindbox-enumerate',
|
||||||
|
'kindbox-update',
|
||||||
|
'benefactor-getall',
|
||||||
|
'benefactor-get',
|
||||||
|
'refertime-getall'
|
||||||
|
) NOT NULL;
|
||||||
|
|
||||||
|
INSERT INTO `admin_access_controls` (`actor_id`, `actor_type`, `permission`)
|
||||||
|
VALUES (1, 'role', 'refertime-getall'),
|
||||||
|
(2, 'role', 'refertime-getall');
|
||||||
|
|
||||||
|
-- +migrate Down
|
||||||
|
DELETE
|
||||||
|
FROM `admin_access_controls`;
|
||||||
|
|
@ -17,7 +17,7 @@ func (s Service) GetAllBenefactor(ctx context.Context, req param.BenefactorGetAl
|
||||||
req.Pagination.GetPageSize()
|
req.Pagination.GetPageSize()
|
||||||
req.Pagination.GetPageNumber()
|
req.Pagination.GetPageNumber()
|
||||||
|
|
||||||
benefactors, total, err := s.repo.GetAllBenefactor(ctx, req.Filter, req.Pagination, req.Sort)
|
benefactors, total, err := s.repo.GetAllBenefactor(ctx, req.Filter, req.Pagination, req.Sort, req.Search.GetSearch())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return param.BenefactorGetAllResponse{}, richerror.New(op).WithErr(err).WithKind(richerror.KindUnexpected)
|
return param.BenefactorGetAllResponse{}, richerror.New(op).WithErr(err).WithKind(richerror.KindUnexpected)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -12,7 +12,7 @@ import (
|
||||||
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)
|
GetAllBenefactor(ctx context.Context, filter param.FilterRequest, pagination param.PaginationRequest, sort param.SortRequest, searchParams *param.QuerySearch) ([]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)
|
||||||
|
|
|
||||||
|
|
@ -18,7 +18,7 @@ func (s Service) GetAll(ctx context.Context, req param.KindBoxGetAllRequest) (pa
|
||||||
req.Pagination.GetPageSize()
|
req.Pagination.GetPageSize()
|
||||||
req.Pagination.GetPageNumber()
|
req.Pagination.GetPageNumber()
|
||||||
|
|
||||||
allKindBox, total, err := s.repo.GetAllKindBox(ctx, req.Filter, req.Pagination, req.Sort)
|
allKindBox, total, err := s.repo.GetAllKindBox(ctx, req.Filter, req.Pagination, req.Sort, req.Search.GetSearch())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return param.KindBoxGetAllResponse{}, richerror.New(op).WithErr(err)
|
return param.KindBoxGetAllResponse{}, richerror.New(op).WithErr(err)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -11,7 +11,7 @@ import (
|
||||||
type Repository interface {
|
type Repository interface {
|
||||||
GetKindBox(ctx context.Context, kindBoxID uint) (entity.KindBox, error)
|
GetKindBox(ctx context.Context, kindBoxID uint) (entity.KindBox, error)
|
||||||
AssignReceiverAgent(ctx context.Context, kindBox entity.KindBox) error
|
AssignReceiverAgent(ctx context.Context, kindBox entity.KindBox) error
|
||||||
GetAllKindBox(ctx context.Context, filter params.FilterRequest, pagination params.PaginationRequest, sort params.SortRequest) ([]entity.KindBox, uint, error)
|
GetAllKindBox(ctx context.Context, filter params.FilterRequest, pagination params.PaginationRequest, sort params.SortRequest, searchParams *params.QuerySearch) ([]entity.KindBox, uint, error)
|
||||||
EnumerateKindBox(ctx context.Context, kindBoxID uint, amount uint) error
|
EnumerateKindBox(ctx context.Context, kindBoxID uint, amount uint) error
|
||||||
UpdateKindBox(ctx context.Context, KindBox entity.KindBox) error
|
UpdateKindBox(ctx context.Context, KindBox entity.KindBox) error
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -18,7 +18,7 @@ func (s Service) GetAll(ctx context.Context, req param.KindBoxReqGetAllRequest)
|
||||||
req.Pagination.GetPageSize()
|
req.Pagination.GetPageSize()
|
||||||
req.Pagination.GetPageNumber()
|
req.Pagination.GetPageNumber()
|
||||||
|
|
||||||
allKindBoxReq, total, err := s.repo.GetAllKindBoxReq(ctx, req.Filter, req.Pagination, req.Sort)
|
allKindBoxReq, total, err := s.repo.GetAllKindBoxReq(ctx, req.Filter, req.Pagination, req.Sort, req.Search.GetSearch())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return param.KindBoxReqGetAllResponse{}, richerror.New(op).WithErr(err).WithKind(richerror.KindUnexpected)
|
return param.KindBoxReqGetAllResponse{}, richerror.New(op).WithErr(err).WithKind(richerror.KindUnexpected)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -14,7 +14,7 @@ type Repository interface {
|
||||||
RejectKindBoxReq(ctx context.Context, kindBoxReqID uint, description string) error
|
RejectKindBoxReq(ctx context.Context, kindBoxReqID uint, description string) error
|
||||||
AssignSenderAgentToKindBoxReq(ctx context.Context, kindBoxReqID uint, senderAgentID uint) error
|
AssignSenderAgentToKindBoxReq(ctx context.Context, kindBoxReqID uint, senderAgentID uint) error
|
||||||
DeliverKindBoxReq(ctx context.Context, kindBoxReqID uint) error
|
DeliverKindBoxReq(ctx context.Context, kindBoxReqID uint) error
|
||||||
GetAllKindBoxReq(ctx context.Context, filter params.FilterRequest, pagination params.PaginationRequest, sort params.SortRequest) ([]entity.KindBoxReq, uint, error)
|
GetAllKindBoxReq(ctx context.Context, filter params.FilterRequest, pagination params.PaginationRequest, sort params.SortRequest, searchParams *params.QuerySearch) ([]entity.KindBoxReq, uint, error)
|
||||||
GetAwaitingDeliveryByAgent(ctx context.Context, kindBoxReqID uint, agentID uint) (entity.KindBoxReq, error)
|
GetAwaitingDeliveryByAgent(ctx context.Context, kindBoxReqID uint, agentID uint) (entity.KindBoxReq, error)
|
||||||
AddKindBoxReq(ctx context.Context, kindBoxReq entity.KindBoxReq) (entity.KindBoxReq, error)
|
AddKindBoxReq(ctx context.Context, kindBoxReq entity.KindBoxReq) (entity.KindBoxReq, error)
|
||||||
UpdateKindBoxReq(ctx context.Context, kindBoxReq entity.KindBoxReq) error
|
UpdateKindBoxReq(ctx context.Context, kindBoxReq entity.KindBoxReq) error
|
||||||
|
|
|
||||||
|
|
@ -20,7 +20,7 @@ func (s Service) GetAll(ctx context.Context, req param.GetAllRequest) (param.Get
|
||||||
req.Filter["receiver_agent_id"] = req.ReceiverAgentId
|
req.Filter["receiver_agent_id"] = req.ReceiverAgentId
|
||||||
req.Filter["status"] = req.Status
|
req.Filter["status"] = req.Status
|
||||||
|
|
||||||
allKindBoxes, total, err := s.repo.GetAllKindBox(ctx, req.Filter, req.Pagination, req.Sort)
|
allKindBoxes, total, err := s.repo.GetAllKindBox(ctx, req.Filter, req.Pagination, req.Sort, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return param.GetAllResponse{}, richerror.New(op).WithErr(err)
|
return param.GetAllResponse{}, richerror.New(op).WithErr(err)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -10,7 +10,7 @@ import (
|
||||||
|
|
||||||
type Repository interface {
|
type Repository interface {
|
||||||
GetAwaitingReturnByAgent(ctx context.Context, kindBoxID uint, agentID uint) (entity.KindBox, error)
|
GetAwaitingReturnByAgent(ctx context.Context, kindBoxID uint, agentID uint) (entity.KindBox, error)
|
||||||
GetAllKindBox(ctx context.Context, filter params.FilterRequest, pagination params.PaginationRequest, sort params.SortRequest) ([]entity.KindBox, uint, error)
|
GetAllKindBox(ctx context.Context, filter params.FilterRequest, pagination params.PaginationRequest, sort params.SortRequest, searchParams *params.QuerySearch) ([]entity.KindBox, uint, error)
|
||||||
ReturnKindBox(ctx context.Context, kindBoxID uint, serialNumber string) error
|
ReturnKindBox(ctx context.Context, kindBoxID uint, serialNumber string) error
|
||||||
AddBatchKindBox(ctx context.Context, kindBoxes []entity.KindBox) error
|
AddBatchKindBox(ctx context.Context, kindBoxes []entity.KindBox) error
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -20,7 +20,7 @@ func (s Service) GetAllAwaitingDelivery(ctx context.Context, req param.DeliveryA
|
||||||
req.Filter["sender_agent_id"] = req.SenderAgentId
|
req.Filter["sender_agent_id"] = req.SenderAgentId
|
||||||
req.Filter["status"] = req.Status
|
req.Filter["status"] = req.Status
|
||||||
|
|
||||||
allAwaitingKindBoxReq, total, err := s.repo.GetAllKindBoxReq(ctx, req.Filter, req.Pagination, req.Sort)
|
allAwaitingKindBoxReq, total, err := s.repo.GetAllKindBoxReq(ctx, req.Filter, req.Pagination, req.Sort, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return param.DeliveryAwaitingGetAllResponse{}, richerror.New(op).WithErr(err)
|
return param.DeliveryAwaitingGetAllResponse{}, richerror.New(op).WithErr(err)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -10,7 +10,7 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
type Repository interface {
|
type Repository interface {
|
||||||
GetAllKindBoxReq(ctx context.Context, filter params.FilterRequest, pagination params.PaginationRequest, sort params.SortRequest) ([]entity.KindBoxReq, uint, error)
|
GetAllKindBoxReq(ctx context.Context, filter params.FilterRequest, pagination params.PaginationRequest, sort params.SortRequest, searchParams *params.QuerySearch) ([]entity.KindBoxReq, uint, error)
|
||||||
DeliverKindBoxReq(ctx context.Context, kindBoxReqID uint) error
|
DeliverKindBoxReq(ctx context.Context, kindBoxReqID uint) error
|
||||||
GetAwaitingDeliveryByAgent(ctx context.Context, kindBoxReqID uint, agentID uint) (entity.KindBoxReq, error)
|
GetAwaitingDeliveryByAgent(ctx context.Context, kindBoxReqID uint, agentID uint) (entity.KindBoxReq, error)
|
||||||
GetByID(ctx context.Context, id uint) (entity.KindBoxReq, error)
|
GetByID(ctx context.Context, id uint) (entity.KindBoxReq, error)
|
||||||
|
|
|
||||||
|
|
@ -18,7 +18,7 @@ func (s Service) GetAll(ctx context.Context, req param.KindBoxGetAllRequest) (pa
|
||||||
req.Pagination.GetPageSize()
|
req.Pagination.GetPageSize()
|
||||||
req.Pagination.GetPageNumber()
|
req.Pagination.GetPageNumber()
|
||||||
|
|
||||||
allKindBox, total, err := s.repo.GetAllKindBox(ctx, req.Filter, req.Pagination, req.Sort)
|
allKindBox, total, err := s.repo.GetAllKindBox(ctx, req.Filter, req.Pagination, req.Sort, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return param.KindBoxGetAllResponse{}, richerror.New(op).WithErr(err)
|
return param.KindBoxGetAllResponse{}, richerror.New(op).WithErr(err)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -9,7 +9,7 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
type Repository interface {
|
type Repository interface {
|
||||||
GetAllKindBox(ctx context.Context, filter params.FilterRequest, pagination params.PaginationRequest, sort params.SortRequest) ([]entity.KindBox, uint, error)
|
GetAllKindBox(ctx context.Context, filter params.FilterRequest, pagination params.PaginationRequest, sort params.SortRequest, searchParams *params.QuerySearch) ([]entity.KindBox, uint, error)
|
||||||
GetKindBox(ctx context.Context, kindBoxID uint) (entity.KindBox, error)
|
GetKindBox(ctx context.Context, kindBoxID uint) (entity.KindBox, error)
|
||||||
RegisterEmptyingRequestForKindBox(ctx context.Context, kindBox entity.KindBox) error
|
RegisterEmptyingRequestForKindBox(ctx context.Context, kindBox entity.KindBox) error
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -18,7 +18,7 @@ func (s Service) GetAll(ctx context.Context, req param.GetAllRequest) (param.Get
|
||||||
req.Pagination.GetPageSize()
|
req.Pagination.GetPageSize()
|
||||||
req.Pagination.GetPageNumber()
|
req.Pagination.GetPageNumber()
|
||||||
|
|
||||||
allKindBoxReq, total, err := s.repo.GetAllKindBoxReq(ctx, req.Filter, req.Pagination, req.Sort)
|
allKindBoxReq, total, err := s.repo.GetAllKindBoxReq(ctx, req.Filter, req.Pagination, req.Sort, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return param.GetAllResponse{}, richerror.New(op).WithErr(err)
|
return param.GetAllResponse{}, richerror.New(op).WithErr(err)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -12,7 +12,7 @@ type Repository interface {
|
||||||
AddKindBoxReq(ctx context.Context, kindBoxReq entity.KindBoxReq) (entity.KindBoxReq, error)
|
AddKindBoxReq(ctx context.Context, kindBoxReq entity.KindBoxReq) (entity.KindBoxReq, error)
|
||||||
GetKindBoxReqByID(ctx context.Context, kindBoxReqID uint) (entity.KindBoxReq, error)
|
GetKindBoxReqByID(ctx context.Context, kindBoxReqID uint) (entity.KindBoxReq, error)
|
||||||
DeleteKindBoxReqByID(ctx context.Context, kindBoxReqID uint) error
|
DeleteKindBoxReqByID(ctx context.Context, kindBoxReqID uint) error
|
||||||
GetAllKindBoxReq(ctx context.Context, filter params.FilterRequest, pagination params.PaginationRequest, sort params.SortRequest) ([]entity.KindBoxReq, uint, error)
|
GetAllKindBoxReq(ctx context.Context, filter params.FilterRequest, pagination params.PaginationRequest, sort params.SortRequest, searchParams *params.QuerySearch) ([]entity.KindBoxReq, uint, error)
|
||||||
UpdateKindBoxReq(ctx context.Context, kindBoxReq entity.KindBoxReq) error
|
UpdateKindBoxReq(ctx context.Context, kindBoxReq entity.KindBoxReq) error
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -17,6 +17,7 @@ func (v Validator) ValidateGetAll(req param.BenefactorGetAllRequest) (map[string
|
||||||
if err := validation.ValidateStruct(&req,
|
if err := validation.ValidateStruct(&req,
|
||||||
validation.Field(&req.Filter, validation.By(v.AreFilterFieldsValid(validFields))),
|
validation.Field(&req.Filter, validation.By(v.AreFilterFieldsValid(validFields))),
|
||||||
validation.Field(&req.Sort, validation.By(v.AreSortFieldsValid(validFields))),
|
validation.Field(&req.Sort, validation.By(v.AreSortFieldsValid(validFields))),
|
||||||
|
validation.Field(&req.Search, validation.By(v.AreSearchValid())),
|
||||||
); err != nil {
|
); err != nil {
|
||||||
|
|
||||||
fieldErrors := make(map[string]string)
|
fieldErrors := make(map[string]string)
|
||||||
|
|
|
||||||
|
|
@ -9,6 +9,10 @@ import (
|
||||||
validation "github.com/go-ozzo/ozzo-validation/v4"
|
validation "github.com/go-ozzo/ozzo-validation/v4"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
MaxLengthQuerySearch = 32
|
||||||
|
)
|
||||||
|
|
||||||
type Validator struct{}
|
type Validator struct{}
|
||||||
|
|
||||||
func New() Validator {
|
func New() Validator {
|
||||||
|
|
@ -50,3 +54,17 @@ func (v Validator) AreFilterFieldsValid(validFilters []string) validation.RuleFu
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (v Validator) AreSearchValid() validation.RuleFunc {
|
||||||
|
return func(value interface{}) error {
|
||||||
|
search, ok := value.(params.SearchRequest)
|
||||||
|
if !ok {
|
||||||
|
return fmt.Errorf(errmsg.ErrorMsgSomethingWentWrong)
|
||||||
|
}
|
||||||
|
if len(search.Query) > MaxLengthQuerySearch {
|
||||||
|
return fmt.Errorf(errmsg.ErrorMsgInvalidInput)
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -21,6 +21,7 @@ func (v Validator) ValidateGetAll(req param.KindBoxGetAllRequest) (map[string]st
|
||||||
if err := validation.ValidateStruct(&req,
|
if err := validation.ValidateStruct(&req,
|
||||||
validation.Field(&req.Filter, validation.By(v.AreFilterFieldsValid(validFields))),
|
validation.Field(&req.Filter, validation.By(v.AreFilterFieldsValid(validFields))),
|
||||||
validation.Field(&req.Sort, validation.By(v.AreSortFieldsValid(validFields))),
|
validation.Field(&req.Sort, validation.By(v.AreSortFieldsValid(validFields))),
|
||||||
|
validation.Field(&req.Search, validation.By(v.AreSearchValid())),
|
||||||
); err != nil {
|
); err != nil {
|
||||||
|
|
||||||
fieldErrors := make(map[string]string)
|
fieldErrors := make(map[string]string)
|
||||||
|
|
|
||||||
|
|
@ -18,6 +18,10 @@ import (
|
||||||
validation "github.com/go-ozzo/ozzo-validation/v4"
|
validation "github.com/go-ozzo/ozzo-validation/v4"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
MaxLengthQuerySearch = 32
|
||||||
|
)
|
||||||
|
|
||||||
//go:generate mockery --name Repository
|
//go:generate mockery --name Repository
|
||||||
type Repository interface {
|
type Repository interface {
|
||||||
KindBoxExist(ctx context.Context, kindBoxID uint) (bool, error)
|
KindBoxExist(ctx context.Context, kindBoxID uint) (bool, error)
|
||||||
|
|
@ -279,3 +283,17 @@ func (v Validator) AreFilterFieldsValid(validFilters []string) validation.RuleFu
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (v Validator) AreSearchValid() validation.RuleFunc {
|
||||||
|
return func(value interface{}) error {
|
||||||
|
search, ok := value.(params.SearchRequest)
|
||||||
|
if !ok {
|
||||||
|
return fmt.Errorf(errmsg.ErrorMsgSomethingWentWrong)
|
||||||
|
}
|
||||||
|
if len(search.Query) > MaxLengthQuerySearch {
|
||||||
|
return fmt.Errorf(errmsg.ErrorMsgInvalidInput)
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -20,6 +20,7 @@ func (v Validator) ValidateGetAll(req param.KindBoxReqGetAllRequest) (map[string
|
||||||
if err := validation.ValidateStruct(&req,
|
if err := validation.ValidateStruct(&req,
|
||||||
validation.Field(&req.Filter, validation.By(v.AreFilterFieldsValid(validFields))),
|
validation.Field(&req.Filter, validation.By(v.AreFilterFieldsValid(validFields))),
|
||||||
validation.Field(&req.Sort, validation.By(v.AreSortFieldsValid(validFields))),
|
validation.Field(&req.Sort, validation.By(v.AreSortFieldsValid(validFields))),
|
||||||
|
validation.Field(&req.Search, validation.By(v.AreSearchValid())),
|
||||||
); err != nil {
|
); err != nil {
|
||||||
fieldErrors := make(map[string]string)
|
fieldErrors := make(map[string]string)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -18,8 +18,9 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
MinKindBoxReq = 1
|
MinKindBoxReq = 1
|
||||||
MaxKindBoxReq = 100
|
MaxKindBoxReq = 100
|
||||||
|
MaxLengthQuerySearch = 32
|
||||||
)
|
)
|
||||||
|
|
||||||
type Repository interface {
|
type Repository interface {
|
||||||
|
|
@ -340,3 +341,17 @@ func (v Validator) AreFilterFieldsValid(validFilters []string) validation.RuleFu
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (v Validator) AreSearchValid() validation.RuleFunc {
|
||||||
|
return func(value interface{}) error {
|
||||||
|
search, ok := value.(params.SearchRequest)
|
||||||
|
if !ok {
|
||||||
|
return fmt.Errorf(errmsg.ErrorMsgSomethingWentWrong)
|
||||||
|
}
|
||||||
|
if len(search.Query) > MaxLengthQuerySearch {
|
||||||
|
return fmt.Errorf(errmsg.ErrorMsgInvalidInput)
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue