Remove unused var
This commit is contained in:
@@ -1,89 +0,0 @@
|
||||
package branch
|
||||
|
||||
import (
|
||||
"context"
|
||||
"furtuna-be/internal/common/logger"
|
||||
"furtuna-be/internal/common/mycontext"
|
||||
"furtuna-be/internal/entity"
|
||||
"furtuna-be/internal/repository"
|
||||
|
||||
"go.uber.org/zap"
|
||||
)
|
||||
|
||||
type BranchService struct {
|
||||
repo repository.Branch
|
||||
}
|
||||
|
||||
func NewBranchService(repo repository.Branch) *BranchService {
|
||||
return &BranchService{
|
||||
repo: repo,
|
||||
}
|
||||
}
|
||||
|
||||
func (s *BranchService) Create(ctx mycontext.Context, branchReq *entity.Branch) (*entity.Branch, error) {
|
||||
branchDB := branchReq.ToBranchDB()
|
||||
branchDB.CreatedBy = ctx.RequestedBy()
|
||||
|
||||
branchDB, err := s.repo.CreateBranch(ctx, branchDB)
|
||||
if err != nil {
|
||||
logger.ContextLogger(ctx).Error("error when create branch", zap.Error(err))
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return branchDB.ToBranch(), nil
|
||||
}
|
||||
|
||||
func (s *BranchService) Update(ctx mycontext.Context, id int64, branchReq *entity.Branch) (*entity.Branch, error) {
|
||||
existingBranch, err := s.repo.GetBranchByID(ctx, id)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
existingBranch.ToUpdatedBranch(ctx.RequestedBy(), *branchReq)
|
||||
|
||||
updatedBranchDB, err := s.repo.UpdateBranch(ctx, existingBranch.ToBranchDB())
|
||||
if err != nil {
|
||||
logger.ContextLogger(ctx).Error("error when update branch", zap.Error(err))
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return updatedBranchDB.ToBranch(), nil
|
||||
}
|
||||
|
||||
func (s *BranchService) GetByID(ctx context.Context, id int64) (*entity.Branch, error) {
|
||||
branchDB, err := s.repo.GetBranchByID(ctx, id)
|
||||
if err != nil {
|
||||
logger.ContextLogger(ctx).Error("error when get branch by id", zap.Error(err))
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return branchDB.ToBranch(), nil
|
||||
}
|
||||
|
||||
func (s *BranchService) GetAll(ctx context.Context, search entity.BranchSearch) ([]*entity.Branch, int, error) {
|
||||
branches, total, err := s.repo.GetAllBranches(ctx, search)
|
||||
if err != nil {
|
||||
logger.ContextLogger(ctx).Error("error when get all branches", zap.Error(err))
|
||||
return nil, 0, err
|
||||
}
|
||||
|
||||
return branches.ToBranchList(), total, nil
|
||||
}
|
||||
|
||||
func (s *BranchService) Delete(ctx mycontext.Context, id int64) error {
|
||||
branchDB, err := s.repo.GetBranchByID(ctx, id)
|
||||
if err != nil {
|
||||
logger.ContextLogger(ctx).Error("error when get branch by id", zap.Error(err))
|
||||
return err
|
||||
}
|
||||
|
||||
branchDB.SetDeleted(ctx.RequestedBy())
|
||||
|
||||
_, err = s.repo.UpdateBranch(ctx, branchDB)
|
||||
if err != nil {
|
||||
logger.ContextLogger(ctx).Error("error when update branch", zap.Error(err))
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
@@ -4,7 +4,6 @@ import (
|
||||
"context"
|
||||
"furtuna-be/internal/common/mycontext"
|
||||
"furtuna-be/internal/services/balance"
|
||||
"furtuna-be/internal/services/branch"
|
||||
"furtuna-be/internal/services/discovery"
|
||||
service "furtuna-be/internal/services/license"
|
||||
"furtuna-be/internal/services/order"
|
||||
@@ -29,7 +28,6 @@ type ServiceManagerImpl struct {
|
||||
AuthSvc Auth
|
||||
EventSvc Event
|
||||
UserSvc User
|
||||
BranchSvc Branch
|
||||
StudioSvc Studio
|
||||
ProductSvc Product
|
||||
OrderSvc Order
|
||||
@@ -46,14 +44,13 @@ func NewServiceManagerImpl(cfg *config.Config, repo *repository.RepoManagerImpl)
|
||||
return &ServiceManagerImpl{
|
||||
AuthSvc: auth.New(repo.Auth, repo.Crypto, repo.User, repo.EmailService, cfg.Email, repo.Trx, repo.License),
|
||||
EventSvc: event.NewEventService(repo.Event),
|
||||
UserSvc: users.NewUserService(repo.User, repo.Branch),
|
||||
BranchSvc: branch.NewBranchService(repo.Branch),
|
||||
UserSvc: users.NewUserService(repo.User),
|
||||
StudioSvc: studio.NewStudioService(repo.Studio),
|
||||
ProductSvc: product.NewProductService(repo.Product),
|
||||
OrderSvc: order.NewOrderService(repo.Order, repo.Product, repo.Crypto, repo.Midtrans, repo.Payment, repo.Trx, repo.Wallet, &cfg.Order, repo.Transaction),
|
||||
OSSSvc: oss.NewOSSService(repo.OSS),
|
||||
PartnerSvc: partner.NewPartnerService(
|
||||
repo.Partner, users.NewUserService(repo.User, repo.Branch), repo.Trx, repo.Wallet, repo.User),
|
||||
repo.Partner, users.NewUserService(repo.User), repo.Trx, repo.Wallet, repo.User),
|
||||
SiteSvc: site.NewSiteService(repo.Site, repo.User),
|
||||
LicenseSvc: service.NewLicenseService(repo.License),
|
||||
Transaction: transaction.New(repo.Transaction, repo.Wallet, repo.Trx),
|
||||
@@ -87,14 +84,6 @@ type User interface {
|
||||
Delete(ctx mycontext.Context, id int64) error
|
||||
}
|
||||
|
||||
type Branch interface {
|
||||
Create(ctx mycontext.Context, branchReq *entity.Branch) (*entity.Branch, error)
|
||||
Update(ctx mycontext.Context, id int64, branchReq *entity.Branch) (*entity.Branch, error)
|
||||
GetByID(ctx context.Context, id int64) (*entity.Branch, error)
|
||||
GetAll(ctx context.Context, search entity.BranchSearch) ([]*entity.Branch, int, error)
|
||||
Delete(ctx mycontext.Context, id int64) error
|
||||
}
|
||||
|
||||
type Studio interface {
|
||||
Create(ctx mycontext.Context, studioReq *entity.Studio) (*entity.Studio, error)
|
||||
Update(ctx mycontext.Context, id int64, studioReq *entity.Studio) (*entity.Studio, error)
|
||||
|
||||
@@ -14,14 +14,12 @@ import (
|
||||
)
|
||||
|
||||
type UserService struct {
|
||||
repo repository.User
|
||||
branchRepo repository.Branch
|
||||
repo repository.User
|
||||
}
|
||||
|
||||
func NewUserService(repo repository.User, branchRepo repository.Branch) *UserService {
|
||||
func NewUserService(repo repository.User) *UserService {
|
||||
return &UserService{
|
||||
repo: repo,
|
||||
branchRepo: branchRepo,
|
||||
repo: repo,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user