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
-91
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
}
-11
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)