forked from ebhomengo/niki
fix(niki): agent structure refactor
This commit is contained in:
parent
47b7f7f216
commit
d26d4fc179
|
@ -1,4 +1,4 @@
|
|||
package adminkindboxparam
|
||||
package agentkindboxparam
|
||||
|
||||
import (
|
||||
"time"
|
|
@ -8,29 +8,8 @@ import (
|
|||
errmsg "git.gocasts.ir/ebhomengo/niki/pkg/err_msg"
|
||||
querytransaction "git.gocasts.ir/ebhomengo/niki/pkg/query_transaction/sql"
|
||||
richerror "git.gocasts.ir/ebhomengo/niki/pkg/rich_error"
|
||||
"git.gocasts.ir/ebhomengo/niki/repository/mysql"
|
||||
)
|
||||
|
||||
func (d *DB) AddKindBox(ctx context.Context, kindBox entity.KindBox) error {
|
||||
const op = "mysqlkindbox.AddKindBox"
|
||||
|
||||
query := `insert into kind_boxes(kind_box_req_id,benefactor_id,type,status,sender_agent_id) values (?,?,?,?,?)`
|
||||
//nolint
|
||||
stmt, err := d.conn.PrepareStatement(ctx, mysql.StatementKeyKindBoxAdd, query)
|
||||
if err != nil {
|
||||
return richerror.New(op).WithErr(err).
|
||||
WithMessage(errmsg.ErrorMsgCantPrepareStatement).WithKind(richerror.KindUnexpected)
|
||||
}
|
||||
|
||||
_, err = stmt.ExecContext(ctx, kindBox.KindBoxReqID, kindBox.BenefactorID, kindBox.KindBoxType, entity.KindBoxDeliveredStatus, kindBox.SenderAgentID)
|
||||
if err != nil {
|
||||
return richerror.New(op).WithErr(err).
|
||||
WithMessage(errmsg.ErrorMsgNotFound).WithKind(richerror.KindUnexpected)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (d *DB) AddBatchKindBox(ctx context.Context, kindBoxes []entity.KindBox) error {
|
||||
const op = "mysqlkindbox.AddBatchKindBoxConcurrentlyRollback"
|
||||
|
||||
|
|
|
@ -9,8 +9,6 @@ import (
|
|||
)
|
||||
|
||||
type Repository interface {
|
||||
AddBatchKindBox(ctx context.Context, kindBoxes []entity.KindBox) error
|
||||
AddKindBox(ctx context.Context, kindBox entity.KindBox) error
|
||||
GetKindBox(ctx context.Context, kindBoxID uint) (entity.KindBox, error)
|
||||
AssignReceiverAgent(ctx context.Context, kindBox entity.KindBox) error
|
||||
GetAllKindBox(ctx context.Context, filter params.FilterRequest, pagination params.PaginationRequest, sort params.SortRequest) ([]entity.KindBox, uint, error)
|
||||
|
|
|
@ -1,15 +1,14 @@
|
|||
package adminkindboxservice
|
||||
package agentkindboxservice
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
entity "git.gocasts.ir/ebhomengo/niki/entity"
|
||||
param "git.gocasts.ir/ebhomengo/niki/param/admin/kind_box"
|
||||
param "git.gocasts.ir/ebhomengo/niki/param/agent/kind_box"
|
||||
richerror "git.gocasts.ir/ebhomengo/niki/pkg/rich_error"
|
||||
)
|
||||
|
||||
func (s Service) AddBatchKindBox(ctx context.Context, req param.AddKindBoxRequest) (param.AddKindBoxResponse, error) {
|
||||
const op = "adminkindboxservice.AddKindBox"
|
||||
const op = "agentkindboxservice.AddKindBox"
|
||||
|
||||
kindBoxes := make([]entity.KindBox, 0)
|
||||
for i := 0; i < int(req.CountAccepted); i++ {
|
|
@ -12,6 +12,7 @@ type Repository interface {
|
|||
GetAwaitingReturnByAgent(ctx context.Context, kindBoxID uint, agentID uint) (entity.KindBox, error)
|
||||
GetAllKindBox(ctx context.Context, filter params.FilterRequest, pagination params.PaginationRequest, sort params.SortRequest) ([]entity.KindBox, uint, error)
|
||||
ReturnKindBox(ctx context.Context, kindBoxID uint, serialNumber string) error
|
||||
AddBatchKindBox(ctx context.Context, kindBoxes []entity.KindBox) error
|
||||
}
|
||||
|
||||
type Service struct {
|
||||
|
|
|
@ -2,15 +2,15 @@ package agentkindboxreqservice
|
|||
|
||||
import (
|
||||
"context"
|
||||
kindboxParam "git.gocasts.ir/ebhomengo/niki/param/agent/kind_box"
|
||||
param "git.gocasts.ir/ebhomengo/niki/param/agent/kind_box_req"
|
||||
"time"
|
||||
|
||||
kindboxParam "git.gocasts.ir/ebhomengo/niki/param/admin/kind_box"
|
||||
richerror "git.gocasts.ir/ebhomengo/niki/pkg/rich_error"
|
||||
)
|
||||
|
||||
func (s Service) Deliver(ctx context.Context, req param.DeliverKindBoxReqRequest) (param.DeliverKindBoxReqResponse, error) {
|
||||
const op = "adminkindboxreqservice.Deliver"
|
||||
const op = "agentkindboxreqservice.Deliver"
|
||||
if fieldErrors, vErr := s.vld.ValidateDeliver(ctx, req); vErr != nil {
|
||||
return param.DeliverKindBoxReqResponse{FieldErrors: fieldErrors}, richerror.New(op).WithErr(vErr)
|
||||
}
|
||||
|
|
|
@ -8,7 +8,7 @@ import (
|
|||
)
|
||||
|
||||
func (s Service) GetAllAwaitingDelivery(ctx context.Context, req param.DeliveryAwaitingGetAllRequest) (param.DeliveryAwaitingGetAllResponse, error) {
|
||||
const op = "adminkindboxreqservice.GetAllAwaitingDelivery"
|
||||
const op = "agentkindboxreqservice.GetAllAwaitingDelivery"
|
||||
|
||||
if fieldErrors, vErr := s.vld.ValidateGetAllAwaitingDelivery(req); vErr != nil {
|
||||
return param.DeliveryAwaitingGetAllResponse{FieldErrors: fieldErrors}, richerror.New(op).WithErr(vErr)
|
||||
|
|
|
@ -7,7 +7,7 @@ import (
|
|||
)
|
||||
|
||||
func (s Service) GetAwaitingDelivery(ctx context.Context, req param.DeliveryAwaitingGetRequest) (param.DeliveryAwaitingGetResponse, error) {
|
||||
const op = "adminkindboxreqservice.GetAwaitingDelivery"
|
||||
const op = "agentkindboxreqservice.GetAwaitingDelivery"
|
||||
if fieldErrors, vErr := s.vld.ValidateGetAwaitingDeliveryRequest(req); vErr != nil {
|
||||
return param.DeliveryAwaitingGetResponse{FieldErrors: fieldErrors}, richerror.New(op).WithErr(vErr)
|
||||
}
|
||||
|
|
|
@ -2,7 +2,7 @@ package agentkindboxreqservice
|
|||
|
||||
import (
|
||||
"context"
|
||||
param "git.gocasts.ir/ebhomengo/niki/param/admin/kind_box"
|
||||
param "git.gocasts.ir/ebhomengo/niki/param/agent/kind_box"
|
||||
|
||||
"git.gocasts.ir/ebhomengo/niki/entity"
|
||||
params "git.gocasts.ir/ebhomengo/niki/param"
|
||||
|
@ -26,9 +26,10 @@ type Service struct {
|
|||
vld validator.Validator
|
||||
}
|
||||
|
||||
func New(repo Repository, vld validator.Validator) Service {
|
||||
func New(repo Repository, vld validator.Validator, kindBoxSvc KindBoxSvc) Service {
|
||||
return Service{
|
||||
repo: repo,
|
||||
vld: vld,
|
||||
kindBoxSvc: kindBoxSvc,
|
||||
}
|
||||
}
|
||||
|
|
|
@ -88,7 +88,7 @@ func New(cfg config.Config, db *mysql.DB, rds *redis.Adapter, smsAdapter smscont
|
|||
AgentKindBoxVld = agentkindboxvalidator.New(kindBoxRepo)
|
||||
AgentKindBoxSvc = agentkindboxservice.New(kindBoxRepo, AgentKindBoxVld)
|
||||
AgentKindBoxReqVld = agentkindboxreqvalidator.New(kindBoxReqRepo)
|
||||
AgentKindBoxReqSvc = agentkindboxreqservice.New(kindBoxReqRepo, AgentKindBoxReqVld)
|
||||
AgentKindBoxReqSvc = agentkindboxreqservice.New(kindBoxReqRepo, AgentKindBoxReqVld, AgentKindBoxSvc)
|
||||
)
|
||||
var (
|
||||
BenefactorAuthSvc = auth.New(cfg.BenefactorAuth)
|
||||
|
|
Loading…
Reference in New Issue