Remove unused var

This commit is contained in:
aditya.siregar 2024-08-28 00:36:26 +07:00
parent 654ddc0b4a
commit cc9933f675
7 changed files with 5 additions and 328 deletions

View File

@ -1,83 +0,0 @@
package entity
import (
"furtuna-be/internal/constants/branch"
"time"
)
type Branch struct {
ID int64
Name string
Status branch.BranchStatus
Location string
CreatedAt time.Time
UpdatedAt time.Time
DeletedAt *time.Time
CreatedBy int64
UpdatedBy int64
}
type BranchSearch struct {
Search string
Name string
Limit int
Offset int
}
type BranchList []*BranchDB
type BranchDB struct {
Branch
}
func (b *Branch) ToBranchDB() *BranchDB {
return &BranchDB{
Branch: *b,
}
}
func (BranchDB) TableName() string {
return "branches"
}
func (e *BranchDB) ToBranch() *Branch {
return &Branch{
ID: e.ID,
Name: e.Name,
Status: e.Status,
Location: e.Location,
CreatedAt: e.CreatedAt,
UpdatedAt: e.UpdatedAt,
CreatedBy: e.CreatedBy,
}
}
func (b *BranchList) ToBranchList() []*Branch {
var branches []*Branch
for _, branch := range *b {
branches = append(branches, branch.ToBranch())
}
return branches
}
func (o *BranchDB) ToUpdatedBranch(updatedby int64, req Branch) {
o.UpdatedBy = updatedby
if req.Name != "" {
o.Name = req.Name
}
if req.Status != "" {
o.Status = req.Status
}
if req.Location != "" {
o.Location = req.Location
}
}
func (o *BranchDB) SetDeleted(updatedby int64) {
currentTime := time.Now()
o.DeletedAt = &currentTime
o.UpdatedBy = updatedby
}

View File

@ -1,36 +0,0 @@
package request
import (
"furtuna-be/internal/constants/branch"
"furtuna-be/internal/entity"
)
type BranchParam struct {
Search string `form:"search" json:"search" example:"Ketua Umum"`
Name string `form:"name" json:"name" example:"Ketua Umum"`
Limit int `form:"limit" json:"limit" example:"10"`
Offset int `form:"offset" json:"offset" example:"0"`
}
func (p *BranchParam) ToEntity() entity.BranchSearch {
return entity.BranchSearch{
Search: p.Search,
Name: p.Name,
Limit: p.Limit,
Offset: p.Offset,
}
}
type Branch struct {
Name string `json:"name" validate:"required"`
Location string `json:"location" validate:"required"`
Status branch.BranchStatus `json:"status"`
}
func (e *Branch) ToEntity() *entity.Branch {
return &entity.Branch{
Name: e.Name,
Location: e.Location,
Status: e.Status,
}
}

View File

@ -1,91 +0,0 @@
package branches
import (
"context"
"furtuna-be/internal/common/logger"
"furtuna-be/internal/entity"
"go.uber.org/zap"
"gorm.io/gorm"
)
type BranchRepository struct {
db *gorm.DB
}
func NewBranchRepository(db *gorm.DB) *BranchRepository {
return &BranchRepository{
db: db,
}
}
func (b *BranchRepository) CreateBranch(ctx context.Context, branch *entity.BranchDB) (*entity.BranchDB, error) {
err := b.db.Create(branch).Error
if err != nil {
logger.ContextLogger(ctx).Error("error when create branch", zap.Error(err))
return nil, err
}
return branch, nil
}
func (b *BranchRepository) UpdateBranch(ctx context.Context, branch *entity.BranchDB) (*entity.BranchDB, error) {
if err := b.db.Save(branch).Error; err != nil {
logger.ContextLogger(ctx).Error("error when update branch", zap.Error(err))
return nil, err
}
return branch, nil
}
func (b *BranchRepository) GetBranchByID(ctx context.Context, id int64) (*entity.BranchDB, error) {
branch := new(entity.BranchDB)
if err := b.db.First(branch, id).Error; err != nil {
logger.ContextLogger(ctx).Error("error when get by id branch", zap.Error(err))
return nil, err
}
return branch, nil
}
func (b *BranchRepository) GetAllBranches(ctx context.Context, req entity.BranchSearch) (entity.BranchList, int, error) {
var branches []*entity.BranchDB
var total int64
query := b.db
query = query.Where("deleted_at is null")
if req.Search != "" {
query = query.Where("name ILIKE ?", "%"+req.Search+"%")
}
if req.Name != "" {
query = query.Where("name ILIKE ?", "%"+req.Name+"%")
}
if req.Limit > 0 {
query = query.Limit(req.Limit)
}
if req.Offset > 0 {
query = query.Offset(req.Offset)
}
if err := query.Find(&branches).Error; err != nil {
logger.ContextLogger(ctx).Error("error when get all branches", zap.Error(err))
return nil, 0, err
}
if err := b.db.Model(&entity.BranchDB{}).Where(query).Count(&total).Error; err != nil {
logger.ContextLogger(ctx).Error("error when count branches", zap.Error(err))
return nil, 0, err
}
return branches, int(total), nil
}
func (b *BranchRepository) DeleteBranch(ctx context.Context, id int64) error {
branch := new(entity.BranchDB)
branch.ID = id
if err := b.db.Delete(branch).Error; err != nil {
return err
}
return nil
}

View File

@ -4,7 +4,6 @@ import (
"context"
"database/sql"
"furtuna-be/internal/common/mycontext"
"furtuna-be/internal/repository/branches"
"furtuna-be/internal/repository/brevo"
"furtuna-be/internal/repository/license"
mdtrns "furtuna-be/internal/repository/midtrans"
@ -35,7 +34,6 @@ type RepoManagerImpl struct {
Auth Auth
Event Event
User User
Branch Branch
Studio Studio
Product Product
Order Order
@ -57,7 +55,6 @@ func NewRepoManagerImpl(db *gorm.DB, cfg *config.Config) *RepoManagerImpl {
Auth: auth.NewAuthRepository(db),
Event: event.NewEventRepo(db),
User: users.NewUserRepository(db),
Branch: branches.NewBranchRepository(db),
Studio: studios.NewStudioRepository(db),
Product: products.NewProductRepository(db),
Order: orders.NewOrderRepository(db),
@ -114,14 +111,6 @@ type User interface {
CountUsersByRoleAndSiteOrPartner(ctx context.Context, roleID int, siteID *int64) (int, error)
}
type Branch interface {
CreateBranch(ctx context.Context, branch *entity.BranchDB) (*entity.BranchDB, error)
UpdateBranch(ctx context.Context, branch *entity.BranchDB) (*entity.BranchDB, error)
GetBranchByID(ctx context.Context, id int64) (*entity.BranchDB, error)
GetAllBranches(ctx context.Context, req entity.BranchSearch) (entity.BranchList, int, error)
DeleteBranch(ctx context.Context, id int64) error
}
type Studio interface {
CreateStudio(ctx context.Context, studio *entity.StudioDB) (*entity.StudioDB, error)
UpdateStudio(ctx context.Context, studio *entity.StudioDB) (*entity.StudioDB, error)

View File

@ -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
}

View File

@ -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)

View File

@ -15,13 +15,11 @@ import (
type UserService struct {
repo repository.User
branchRepo repository.Branch
}
func NewUserService(repo repository.User, branchRepo repository.Branch) *UserService {
func NewUserService(repo repository.User) *UserService {
return &UserService{
repo: repo,
branchRepo: branchRepo,
}
}