forked from ebhomengo/niki
feat(admin): add benefactor aggregator service(#198)
This commit is contained in:
parent
bf8a141f68
commit
1d14e86602
|
|
@ -4,6 +4,7 @@ import (
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
param "git.gocasts.ir/ebhomengo/niki/param/admin/kind_box"
|
param "git.gocasts.ir/ebhomengo/niki/param/admin/kind_box"
|
||||||
|
arrayfunc "git.gocasts.ir/ebhomengo/niki/pkg/array_func"
|
||||||
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"
|
||||||
"github.com/labstack/echo/v4"
|
"github.com/labstack/echo/v4"
|
||||||
|
|
@ -50,18 +51,46 @@ func (h Handler) GetAll(c echo.Context) error {
|
||||||
|
|
||||||
req.Filter = queryparam.GetFilterParams(c)
|
req.Filter = queryparam.GetFilterParams(c)
|
||||||
|
|
||||||
resp, sErr := h.adminKindBoxSvc.GetAll(c.Request().Context(), req)
|
kindboxes, sErr := h.adminKindBoxSvc.GetAll(c.Request().Context(), req)
|
||||||
if sErr != nil {
|
if sErr != nil {
|
||||||
msg, code := httpmsg.Error(sErr)
|
msg, code := httpmsg.Error(sErr)
|
||||||
if resp.FieldErrors != nil {
|
if kindboxes.FieldErrors != nil {
|
||||||
return c.JSON(code, echo.Map{
|
return c.JSON(code, echo.Map{
|
||||||
"message": msg,
|
"message": msg,
|
||||||
"errors": resp.FieldErrors,
|
"errors": kindboxes.FieldErrors,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
return echo.NewHTTPError(code, msg)
|
return echo.NewHTTPError(code, msg)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
benefactors, bErr := h.adminBenefactorAggSvc.GetByIDs(c.Request().Context(), getBenefactorIDs(kindboxes.Data))
|
||||||
|
if bErr != nil {
|
||||||
|
msg, code := httpmsg.Error(sErr)
|
||||||
|
if kindboxes.FieldErrors != nil {
|
||||||
|
return c.JSON(code, echo.Map{
|
||||||
|
"message": msg,
|
||||||
|
"errors": kindboxes.FieldErrors,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
return echo.NewHTTPError(code, msg)
|
||||||
|
}
|
||||||
|
|
||||||
|
resp := param.KindBoxGetAllResponse{
|
||||||
|
Data: kindboxes.Data,
|
||||||
|
Info: param.Info{
|
||||||
|
Benefactors: benefactors,
|
||||||
|
},
|
||||||
|
Pagination: kindboxes.Pagination,
|
||||||
|
}
|
||||||
return c.JSON(http.StatusOK, resp)
|
return c.JSON(http.StatusOK, resp)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func getBenefactorIDs(kindBoxes []param.Data) []any {
|
||||||
|
benefactorsMap := make(map[uint]bool)
|
||||||
|
for _, kindBox := range kindBoxes {
|
||||||
|
benefactorsMap[kindBox.BenefactorID] = true
|
||||||
|
}
|
||||||
|
return arrayfunc.MapToSlice(benefactorsMap)
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -2,27 +2,31 @@ package adminkindboxhandler
|
||||||
|
|
||||||
import (
|
import (
|
||||||
adminauthorizationservice "git.gocasts.ir/ebhomengo/niki/service/admin/authorization"
|
adminauthorizationservice "git.gocasts.ir/ebhomengo/niki/service/admin/authorization"
|
||||||
|
adminbenefactoraggsvc "git.gocasts.ir/ebhomengo/niki/service/admin/benefactor_aggregator"
|
||||||
adminkindboxservice "git.gocasts.ir/ebhomengo/niki/service/admin/kind_box"
|
adminkindboxservice "git.gocasts.ir/ebhomengo/niki/service/admin/kind_box"
|
||||||
authservice "git.gocasts.ir/ebhomengo/niki/service/auth"
|
authservice "git.gocasts.ir/ebhomengo/niki/service/auth"
|
||||||
"git.gocasts.ir/ebhomengo/niki/service/notification"
|
"git.gocasts.ir/ebhomengo/niki/service/notification"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Handler struct {
|
type Handler struct {
|
||||||
authSvc authservice.Service
|
authSvc authservice.Service
|
||||||
adminKindBoxSvc adminkindboxservice.Service
|
adminKindBoxSvc adminkindboxservice.Service
|
||||||
adminAuthorizeSvc adminauthorizationservice.Service
|
adminBenefactorAggSvc adminbenefactoraggsvc.Service
|
||||||
notificationSvc notification.Service
|
adminAuthorizeSvc adminauthorizationservice.Service
|
||||||
|
notificationSvc notification.Service
|
||||||
}
|
}
|
||||||
|
|
||||||
func New(authSvc authservice.Service,
|
func New(authSvc authservice.Service,
|
||||||
adminKindBoxSvc adminkindboxservice.Service,
|
adminKindBoxSvc adminkindboxservice.Service,
|
||||||
|
adminBenefactorAggSvc adminbenefactoraggsvc.Service,
|
||||||
adminAuthorizeSvc adminauthorizationservice.Service,
|
adminAuthorizeSvc adminauthorizationservice.Service,
|
||||||
notificationSvc notification.Service,
|
notificationSvc notification.Service,
|
||||||
) Handler {
|
) Handler {
|
||||||
return Handler{
|
return Handler{
|
||||||
authSvc: authSvc,
|
authSvc: authSvc,
|
||||||
adminKindBoxSvc: adminKindBoxSvc,
|
adminKindBoxSvc: adminKindBoxSvc,
|
||||||
adminAuthorizeSvc: adminAuthorizeSvc,
|
adminBenefactorAggSvc: adminBenefactorAggSvc,
|
||||||
notificationSvc: notificationSvc,
|
adminAuthorizeSvc: adminAuthorizeSvc,
|
||||||
|
notificationSvc: notificationSvc,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,7 @@ import (
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
param "git.gocasts.ir/ebhomengo/niki/param/admin/kind_box_req"
|
param "git.gocasts.ir/ebhomengo/niki/param/admin/kind_box_req"
|
||||||
|
arrayfunc "git.gocasts.ir/ebhomengo/niki/pkg/array_func"
|
||||||
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"
|
||||||
echo "github.com/labstack/echo/v4"
|
echo "github.com/labstack/echo/v4"
|
||||||
|
|
@ -48,18 +49,46 @@ func (h Handler) GetAll(c echo.Context) error {
|
||||||
|
|
||||||
req.Filter = queryparam.GetFilterParams(c)
|
req.Filter = queryparam.GetFilterParams(c)
|
||||||
|
|
||||||
resp, err := h.adminKindBoxReqSvc.GetAll(c.Request().Context(), req)
|
kindBoxReqs, err := h.adminKindBoxReqSvc.GetAll(c.Request().Context(), req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
msg, code := httpmsg.Error(err)
|
msg, code := httpmsg.Error(err)
|
||||||
if resp.FieldErrors != nil {
|
if kindBoxReqs.FieldErrors != nil {
|
||||||
return c.JSON(code, httpmsg.ErrorResponse{
|
return c.JSON(code, httpmsg.ErrorResponse{
|
||||||
Message: msg,
|
Message: msg,
|
||||||
Errors: resp.FieldErrors,
|
Errors: kindBoxReqs.FieldErrors,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
return echo.NewHTTPError(code, msg)
|
return echo.NewHTTPError(code, msg)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
benefactors, bErr := h.adminBenefactorAggSvc.GetByIDs(c.Request().Context(), getBenefactorIDs(kindBoxReqs.Data))
|
||||||
|
if bErr != nil {
|
||||||
|
msg, code := httpmsg.Error(bErr)
|
||||||
|
if kindBoxReqs.FieldErrors != nil {
|
||||||
|
return c.JSON(code, echo.Map{
|
||||||
|
"message": msg,
|
||||||
|
"errors": kindBoxReqs.FieldErrors,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
return echo.NewHTTPError(code, msg)
|
||||||
|
}
|
||||||
|
|
||||||
|
resp := param.KindBoxReqGetAllResponse{
|
||||||
|
Data: kindBoxReqs.Data,
|
||||||
|
Info: param.Info{
|
||||||
|
Benefactors: benefactors,
|
||||||
|
},
|
||||||
|
Pagination: kindBoxReqs.Pagination,
|
||||||
|
}
|
||||||
return c.JSON(http.StatusOK, resp)
|
return c.JSON(http.StatusOK, resp)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func getBenefactorIDs(kindBoxReqs []param.Data) []any {
|
||||||
|
benefactorsMap := make(map[uint]bool)
|
||||||
|
for _, kindBox := range kindBoxReqs {
|
||||||
|
benefactorsMap[kindBox.BenefactorID] = true
|
||||||
|
}
|
||||||
|
return arrayfunc.MapToSlice(benefactorsMap)
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -2,26 +2,31 @@ package adminkindboxreqhandler
|
||||||
|
|
||||||
import (
|
import (
|
||||||
adminauthorizationservice "git.gocasts.ir/ebhomengo/niki/service/admin/authorization"
|
adminauthorizationservice "git.gocasts.ir/ebhomengo/niki/service/admin/authorization"
|
||||||
|
adminbenefactoraggsvc "git.gocasts.ir/ebhomengo/niki/service/admin/benefactor_aggregator"
|
||||||
adminkindboxreqservice "git.gocasts.ir/ebhomengo/niki/service/admin/kind_box_req"
|
adminkindboxreqservice "git.gocasts.ir/ebhomengo/niki/service/admin/kind_box_req"
|
||||||
authservice "git.gocasts.ir/ebhomengo/niki/service/auth"
|
authservice "git.gocasts.ir/ebhomengo/niki/service/auth"
|
||||||
"git.gocasts.ir/ebhomengo/niki/service/notification"
|
"git.gocasts.ir/ebhomengo/niki/service/notification"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Handler struct {
|
type Handler struct {
|
||||||
authSvc authservice.Service
|
authSvc authservice.Service
|
||||||
adminKindBoxReqSvc adminkindboxreqservice.Service
|
adminKindBoxReqSvc adminkindboxreqservice.Service
|
||||||
adminAuthorizeSvc adminauthorizationservice.Service
|
adminBenefactorAggSvc adminbenefactoraggsvc.Service
|
||||||
notificationSvc notification.Service
|
adminAuthorizeSvc adminauthorizationservice.Service
|
||||||
|
notificationSvc notification.Service
|
||||||
}
|
}
|
||||||
|
|
||||||
func New(authSvc authservice.Service,
|
func New(authSvc authservice.Service,
|
||||||
adminKindBoxReqSvc adminkindboxreqservice.Service,
|
adminKindBoxReqSvc adminkindboxreqservice.Service,
|
||||||
adminAuthorizeSvc adminauthorizationservice.Service, notificationSvc notification.Service,
|
adminBenefactorAggSvc adminbenefactoraggsvc.Service,
|
||||||
|
adminAuthorizeSvc adminauthorizationservice.Service,
|
||||||
|
notificationSvc notification.Service,
|
||||||
) Handler {
|
) Handler {
|
||||||
return Handler{
|
return Handler{
|
||||||
authSvc: authSvc,
|
authSvc: authSvc,
|
||||||
adminKindBoxReqSvc: adminKindBoxReqSvc,
|
adminKindBoxReqSvc: adminKindBoxReqSvc,
|
||||||
adminAuthorizeSvc: adminAuthorizeSvc,
|
adminBenefactorAggSvc: adminBenefactorAggSvc,
|
||||||
notificationSvc: notificationSvc,
|
adminAuthorizeSvc: adminAuthorizeSvc,
|
||||||
|
notificationSvc: notificationSvc,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -50,8 +50,8 @@ func New(
|
||||||
Router: echo.New(),
|
Router: echo.New(),
|
||||||
config: cfg,
|
config: cfg,
|
||||||
adminHandler: adminhandler.New(svc.AdminAuthSvc, svc.AdminSvc, svc.AdminAuthorizeSvc),
|
adminHandler: adminhandler.New(svc.AdminAuthSvc, svc.AdminSvc, svc.AdminAuthorizeSvc),
|
||||||
adminKindBoxReqHandler: adminkindboxreqhandler.New(svc.AdminAuthSvc, svc.AdminKindBoxReqSvc, svc.AdminAuthorizeSvc, svc.NotificationSvc),
|
adminKindBoxReqHandler: adminkindboxreqhandler.New(svc.AdminAuthSvc, svc.AdminKindBoxReqSvc, svc.AdminBenefactorAggSvc, svc.AdminAuthorizeSvc, svc.NotificationSvc),
|
||||||
adminKindBoxHandler: adminKindBoxHandler.New(svc.AdminAuthSvc, svc.AdminKindBoxSvc, svc.AdminAuthorizeSvc, svc.NotificationSvc),
|
adminKindBoxHandler: adminKindBoxHandler.New(svc.AdminAuthSvc, svc.AdminKindBoxSvc, svc.AdminBenefactorAggSvc, 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.AdminAuthorizeSvc, svc.AdminBenefactorSvc, svc.AdminAddressSvc, svc.AdminKindBoxSvc, svc.AdminKindBoxReqSvc),
|
adminBenefactorHandler: adminbenefactorhandler.New(svc.AdminAuthSvc, svc.AdminAuthorizeSvc, svc.AdminBenefactorSvc, svc.AdminAddressSvc, svc.AdminKindBoxSvc, svc.AdminKindBoxReqSvc),
|
||||||
adminReferTimeHandler: adminrefertimehandler.New(svc.AdminAuthSvc, svc.AdminReferTimeSvc, svc.AdminAuthorizeSvc),
|
adminReferTimeHandler: adminrefertimehandler.New(svc.AdminAuthSvc, svc.AdminReferTimeSvc, svc.AdminAuthorizeSvc),
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,7 @@ package adminkindboxparam
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"git.gocasts.ir/ebhomengo/niki/param"
|
"git.gocasts.ir/ebhomengo/niki/param"
|
||||||
|
adminbenefactoreparam "git.gocasts.ir/ebhomengo/niki/param/admin/benefactor"
|
||||||
)
|
)
|
||||||
|
|
||||||
type KindBoxGetAllRequest struct {
|
type KindBoxGetAllRequest struct {
|
||||||
|
|
@ -11,8 +12,13 @@ type KindBoxGetAllRequest struct {
|
||||||
Search param.SearchRequest
|
Search param.SearchRequest
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type Info struct {
|
||||||
|
Benefactors []adminbenefactoreparam.Data `json:"benefactors"`
|
||||||
|
}
|
||||||
|
|
||||||
type KindBoxGetAllResponse struct {
|
type KindBoxGetAllResponse struct {
|
||||||
Data []Data `json:"data"`
|
Data []Data `json:"data"`
|
||||||
|
Info Info `json:"info"`
|
||||||
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"`
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,7 @@ package adminkindboxreqparam
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"git.gocasts.ir/ebhomengo/niki/param"
|
"git.gocasts.ir/ebhomengo/niki/param"
|
||||||
|
adminbenefactoreparam "git.gocasts.ir/ebhomengo/niki/param/admin/benefactor"
|
||||||
)
|
)
|
||||||
|
|
||||||
type KindBoxReqGetAllRequest struct {
|
type KindBoxReqGetAllRequest struct {
|
||||||
|
|
@ -11,8 +12,13 @@ type KindBoxReqGetAllRequest struct {
|
||||||
Search param.SearchRequest
|
Search param.SearchRequest
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type Info struct {
|
||||||
|
Benefactors []adminbenefactoreparam.Data `json:"benefactors"`
|
||||||
|
}
|
||||||
|
|
||||||
type KindBoxReqGetAllResponse struct {
|
type KindBoxReqGetAllResponse struct {
|
||||||
Data []Data `json:"data"`
|
Data []Data `json:"data"`
|
||||||
|
Info Info `json:"info"`
|
||||||
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"`
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,9 @@
|
||||||
|
package arrayfunc
|
||||||
|
|
||||||
|
func MapToSlice(mapList map[uint]bool) []any {
|
||||||
|
arrayList := make([]any, 0, len(mapList))
|
||||||
|
for id := range mapList {
|
||||||
|
arrayList = append(arrayList, id)
|
||||||
|
}
|
||||||
|
return arrayList
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,45 @@
|
||||||
|
package mysqlbenefactor
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"fmt"
|
||||||
|
|
||||||
|
"git.gocasts.ir/ebhomengo/niki/entity"
|
||||||
|
errmsg "git.gocasts.ir/ebhomengo/niki/pkg/err_msg"
|
||||||
|
richerror "git.gocasts.ir/ebhomengo/niki/pkg/rich_error"
|
||||||
|
)
|
||||||
|
|
||||||
|
func (d *DB) GetBenefactorByIds(ctx context.Context, benefactorIDs []any) (map[uint]entity.Benefactor, error) {
|
||||||
|
const op = "mysqlbenefactor.GetBenefactorByIds"
|
||||||
|
|
||||||
|
if len(benefactorIDs) <= 0 {
|
||||||
|
return nil, nil
|
||||||
|
}
|
||||||
|
query := `select * from benefactors where id in (%s)`
|
||||||
|
param := "?"
|
||||||
|
for i := 1; i < len(benefactorIDs); i++ {
|
||||||
|
param += ",?"
|
||||||
|
}
|
||||||
|
query = fmt.Sprintf(query, param)
|
||||||
|
rows, qErr := d.conn.Conn().QueryContext(ctx, query, benefactorIDs...)
|
||||||
|
if qErr != nil {
|
||||||
|
return nil, richerror.New(op).WithErr(qErr).WithMessage(errmsg.ErrorMsgSomethingWentWrong).WithKind(richerror.KindUnexpected)
|
||||||
|
}
|
||||||
|
|
||||||
|
defer rows.Close()
|
||||||
|
|
||||||
|
benefactors := make(map[uint]entity.Benefactor)
|
||||||
|
for rows.Next() {
|
||||||
|
benefactor, sErr := scanBenefactor(rows)
|
||||||
|
if sErr != nil {
|
||||||
|
return nil, richerror.New(op).WithErr(sErr).
|
||||||
|
WithMessage(errmsg.ErrorMsgCantScanQueryResult).WithKind(richerror.KindUnexpected)
|
||||||
|
}
|
||||||
|
benefactors[benefactor.ID] = benefactor
|
||||||
|
}
|
||||||
|
if rErr := rows.Err(); rErr != nil {
|
||||||
|
return nil, richerror.New(op).WithErr(rErr).
|
||||||
|
WithMessage(errmsg.ErrorMsgSomethingWentWrong).WithKind(richerror.KindUnexpected)
|
||||||
|
}
|
||||||
|
return benefactors, nil
|
||||||
|
}
|
||||||
|
|
@ -23,6 +23,7 @@ const (
|
||||||
StatementKeyAdminGetByPhoneNumber
|
StatementKeyAdminGetByPhoneNumber
|
||||||
StatementKeyAdminAgentGetAll
|
StatementKeyAdminAgentGetAll
|
||||||
StatementKeyBenefactorGetByID
|
StatementKeyBenefactorGetByID
|
||||||
|
StatementKeyBenefactorGetByIDs
|
||||||
StatementKeyBenefactorGetByPhoneNumber
|
StatementKeyBenefactorGetByPhoneNumber
|
||||||
StatementKeyBenefactorCreate
|
StatementKeyBenefactorCreate
|
||||||
StatementKeyBenefactorGetAll
|
StatementKeyBenefactorGetAll
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,33 @@
|
||||||
|
package adminbenefactoraggregatorservice
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
|
||||||
|
param "git.gocasts.ir/ebhomengo/niki/param/admin/benefactor"
|
||||||
|
response "git.gocasts.ir/ebhomengo/niki/pkg/response_builder"
|
||||||
|
richerror "git.gocasts.ir/ebhomengo/niki/pkg/rich_error"
|
||||||
|
)
|
||||||
|
|
||||||
|
func (s Service) GetByIDs(ctx context.Context, benefactorIDs []any) ([]param.Data, error) {
|
||||||
|
const op = "adminbenefactoraggregatorservice.GetByIDs"
|
||||||
|
var data []param.Data
|
||||||
|
|
||||||
|
benefactors, err := s.repo.GetBenefactorByIds(ctx, benefactorIDs)
|
||||||
|
if err != nil {
|
||||||
|
return nil, richerror.New(op).WithErr(err)
|
||||||
|
}
|
||||||
|
for _, benefactor := range benefactors {
|
||||||
|
data = append(data, param.Data{
|
||||||
|
ID: benefactor.ID,
|
||||||
|
FirstName: benefactor.FirstName,
|
||||||
|
LastName: benefactor.LastName,
|
||||||
|
PhoneNumber: benefactor.PhoneNumber,
|
||||||
|
Description: benefactor.Description,
|
||||||
|
Email: benefactor.Email,
|
||||||
|
Gender: benefactor.Gender,
|
||||||
|
BirthDate: response.GetNullDate(benefactor.BirthDate),
|
||||||
|
Status: benefactor.Status,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
return data, nil
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,19 @@
|
||||||
|
package adminbenefactoraggregatorservice
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
|
||||||
|
"git.gocasts.ir/ebhomengo/niki/entity"
|
||||||
|
)
|
||||||
|
|
||||||
|
type Repository interface {
|
||||||
|
GetBenefactorByIds(ctx context.Context, benefactorIDs []any) (map[uint]entity.Benefactor, error)
|
||||||
|
}
|
||||||
|
|
||||||
|
type Service struct {
|
||||||
|
repo Repository
|
||||||
|
}
|
||||||
|
|
||||||
|
func New(repo Repository) Service {
|
||||||
|
return Service{repo: repo}
|
||||||
|
}
|
||||||
|
|
@ -5,6 +5,7 @@ import (
|
||||||
|
|
||||||
"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"
|
||||||
|
adminbenefactoraggsvc "git.gocasts.ir/ebhomengo/niki/service/admin/benefactor_aggregator"
|
||||||
validator "git.gocasts.ir/ebhomengo/niki/validator/admin/kind_box"
|
validator "git.gocasts.ir/ebhomengo/niki/validator/admin/kind_box"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
@ -17,13 +18,15 @@ type Repository interface {
|
||||||
}
|
}
|
||||||
|
|
||||||
type Service struct {
|
type Service struct {
|
||||||
repo Repository
|
repo Repository
|
||||||
vld validator.Validator
|
benefactorAggSvc adminbenefactoraggsvc.Service
|
||||||
|
vld validator.Validator
|
||||||
}
|
}
|
||||||
|
|
||||||
func New(repo Repository, vld validator.Validator) Service {
|
func New(repo Repository, benefactorAggSvc adminbenefactoraggsvc.Service, vld validator.Validator) Service {
|
||||||
return Service{
|
return Service{
|
||||||
repo: repo,
|
repo: repo,
|
||||||
vld: vld,
|
benefactorAggSvc: benefactorAggSvc,
|
||||||
|
vld: vld,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -18,6 +18,7 @@ import (
|
||||||
adminagentservice "git.gocasts.ir/ebhomengo/niki/service/admin/agent"
|
adminagentservice "git.gocasts.ir/ebhomengo/niki/service/admin/agent"
|
||||||
adminauthorizationservice "git.gocasts.ir/ebhomengo/niki/service/admin/authorization"
|
adminauthorizationservice "git.gocasts.ir/ebhomengo/niki/service/admin/authorization"
|
||||||
adminbenefactorservice "git.gocasts.ir/ebhomengo/niki/service/admin/benefactor"
|
adminbenefactorservice "git.gocasts.ir/ebhomengo/niki/service/admin/benefactor"
|
||||||
|
adminbenefactoraggsvc "git.gocasts.ir/ebhomengo/niki/service/admin/benefactor_aggregator"
|
||||||
adminkindboxservice "git.gocasts.ir/ebhomengo/niki/service/admin/kind_box"
|
adminkindboxservice "git.gocasts.ir/ebhomengo/niki/service/admin/kind_box"
|
||||||
adminkindboxreqservice "git.gocasts.ir/ebhomengo/niki/service/admin/kind_box_req"
|
adminkindboxreqservice "git.gocasts.ir/ebhomengo/niki/service/admin/kind_box_req"
|
||||||
adminrefertimeservice "git.gocasts.ir/ebhomengo/niki/service/admin/refer_time"
|
adminrefertimeservice "git.gocasts.ir/ebhomengo/niki/service/admin/refer_time"
|
||||||
|
|
@ -62,6 +63,7 @@ type Service struct {
|
||||||
NotificationSvc notification.Service
|
NotificationSvc notification.Service
|
||||||
BenefactorReferTimeSvc benefactorrefertimeservice.Service
|
BenefactorReferTimeSvc benefactorrefertimeservice.Service
|
||||||
AdminReferTimeSvc adminrefertimeservice.Service
|
AdminReferTimeSvc adminrefertimeservice.Service
|
||||||
|
AdminBenefactorAggSvc adminbenefactoraggsvc.Service
|
||||||
}
|
}
|
||||||
|
|
||||||
func New(cfg config.Config, db *mysql.DB, rds *redis.Adapter, smsAdapter smscontract.SmsAdapter) *Service {
|
func New(cfg config.Config, db *mysql.DB, rds *redis.Adapter, smsAdapter smscontract.SmsAdapter) *Service {
|
||||||
|
|
@ -76,19 +78,20 @@ func New(cfg config.Config, db *mysql.DB, rds *redis.Adapter, smsAdapter smscont
|
||||||
)
|
)
|
||||||
redisOtp := redisotp.New(rds)
|
redisOtp := redisotp.New(rds)
|
||||||
var (
|
var (
|
||||||
AdminAuthSvc = auth.New(cfg.AdminAuth)
|
AdminAuthSvc = auth.New(cfg.AdminAuth)
|
||||||
AdminAuthorizeSvc = adminauthorizationservice.New(adminRepo)
|
AdminAuthorizeSvc = adminauthorizationservice.New(adminRepo)
|
||||||
AdminReferTimeVld = adminrefertimevalidator.New()
|
AdminReferTimeVld = adminrefertimevalidator.New()
|
||||||
AdminReferTimeSvc = adminrefertimeservice.New(referTimeRepo, AdminReferTimeVld)
|
AdminReferTimeSvc = adminrefertimeservice.New(referTimeRepo, AdminReferTimeVld)
|
||||||
AdminAddressSvc = adminaddressservice.New(addressRepo)
|
AdminAddressSvc = adminaddressservice.New(addressRepo)
|
||||||
AdminBenefactorVld = adminbenefactorvalidator.New(benefactorRepo)
|
AdminBenefactorVld = adminbenefactorvalidator.New(benefactorRepo)
|
||||||
AdminBenefactorSvc = adminbenefactorservice.New(benefactorRepo, AdminAddressSvc, AdminBenefactorVld)
|
AdminBenefactorSvc = adminbenefactorservice.New(benefactorRepo, AdminAddressSvc, AdminBenefactorVld)
|
||||||
AdminAgentSvc = adminagentservice.New(agentRepo)
|
AdminAgentSvc = adminagentservice.New(agentRepo)
|
||||||
|
AdminBenefactorAggSvc = adminbenefactoraggsvc.New(benefactorRepo)
|
||||||
|
|
||||||
AdminVld = adminvalidator.New(adminRepo)
|
AdminVld = adminvalidator.New(adminRepo)
|
||||||
AdminSvc = adminservice.New(adminRepo, AdminAuthSvc, AdminVld)
|
AdminSvc = adminservice.New(adminRepo, AdminAuthSvc, AdminVld)
|
||||||
AdminKindBoxVld = adminkindboxvalidator.New(kindBoxRepo, AdminAgentSvc, AdminBenefactorSvc, AdminReferTimeSvc, AdminAddressSvc)
|
AdminKindBoxVld = adminkindboxvalidator.New(kindBoxRepo, AdminAgentSvc, AdminBenefactorSvc, AdminReferTimeSvc, AdminAddressSvc)
|
||||||
AdminKindBoxSvc = adminkindboxservice.New(kindBoxRepo, AdminKindBoxVld)
|
AdminKindBoxSvc = adminkindboxservice.New(kindBoxRepo, AdminBenefactorAggSvc, AdminKindBoxVld)
|
||||||
AdminKindBoxReqVld = adminkindboxreqvalidator.New(kindBoxReqRepo, AdminSvc, AdminAgentSvc, AdminBenefactorSvc, AdminReferTimeSvc, AdminAddressSvc)
|
AdminKindBoxReqVld = adminkindboxreqvalidator.New(kindBoxReqRepo, AdminSvc, AdminAgentSvc, AdminBenefactorSvc, AdminReferTimeSvc, AdminAddressSvc)
|
||||||
AdminKindBoxReqSvc = adminkindboxreqservice.New(kindBoxReqRepo, AdminKindBoxReqVld)
|
AdminKindBoxReqSvc = adminkindboxreqservice.New(kindBoxReqRepo, AdminKindBoxReqVld)
|
||||||
)
|
)
|
||||||
|
|
@ -132,5 +135,6 @@ func New(cfg config.Config, db *mysql.DB, rds *redis.Adapter, smsAdapter smscont
|
||||||
NotificationSvc: NotificationSvc,
|
NotificationSvc: NotificationSvc,
|
||||||
BenefactorReferTimeSvc: BenefactorReferTimeSvc,
|
BenefactorReferTimeSvc: BenefactorReferTimeSvc,
|
||||||
AdminReferTimeSvc: AdminReferTimeSvc,
|
AdminReferTimeSvc: AdminReferTimeSvc,
|
||||||
|
AdminBenefactorAggSvc: AdminBenefactorAggSvc,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue