mirror of
https://gitlab.com/mbugroup/lti-api.git
synced 2026-05-25 07:45:44 +00:00
Feat[BE-261,265]: createing BOP and BOP realization(Unfinished)
This commit is contained in:
@@ -11,6 +11,8 @@ import (
|
||||
type ExpenseRepository interface {
|
||||
repository.BaseRepository[entity.Expense]
|
||||
IdExists(ctx context.Context, id uint64) (bool, error)
|
||||
GetNextSequence(ctx context.Context) (int, error)
|
||||
GetWithSupplier(ctx context.Context, id uint64) (*entity.Expense, error)
|
||||
}
|
||||
|
||||
type ExpenseRepositoryImpl struct {
|
||||
@@ -26,3 +28,24 @@ func NewExpenseRepository(db *gorm.DB) ExpenseRepository {
|
||||
func (r *ExpenseRepositoryImpl) IdExists(ctx context.Context, id uint64) (bool, error) {
|
||||
return repository.Exists[entity.Expense](ctx, r.DB(), uint(id))
|
||||
}
|
||||
|
||||
func (r *ExpenseRepositoryImpl) GetNextSequence(ctx context.Context) (int, error) {
|
||||
var sequence int
|
||||
err := r.DB().Raw("SELECT nextval('expenses_ref_seq')").Scan(&sequence).Error
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
return sequence, nil
|
||||
}
|
||||
|
||||
func (r *ExpenseRepositoryImpl) GetWithSupplier(ctx context.Context, id uint64) (*entity.Expense, error) {
|
||||
var expense entity.Expense
|
||||
err := r.DB().WithContext(ctx).
|
||||
Where("id = ?", id).
|
||||
Preload("Supplier").
|
||||
First(&expense).Error
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &expense, nil
|
||||
}
|
||||
|
||||
@@ -11,6 +11,8 @@ import (
|
||||
type ExpenseNonstockRepository interface {
|
||||
repository.BaseRepository[entity.ExpenseNonstock]
|
||||
IdExists(ctx context.Context, id uint64) (bool, error)
|
||||
GetByExpenseID(ctx context.Context, expenseID uint64, id uint64) (bool, error)
|
||||
GetWithRelations(ctx context.Context, id uint64) (*entity.ExpenseNonstock, error)
|
||||
}
|
||||
|
||||
type ExpenseNonstockRepositoryImpl struct {
|
||||
@@ -26,3 +28,28 @@ func NewExpenseNonstockRepository(db *gorm.DB) ExpenseNonstockRepository {
|
||||
func (r *ExpenseNonstockRepositoryImpl) IdExists(ctx context.Context, id uint64) (bool, error) {
|
||||
return repository.Exists[entity.ExpenseNonstock](ctx, r.DB(), uint(id))
|
||||
}
|
||||
|
||||
func (r *ExpenseNonstockRepositoryImpl) GetByExpenseID(ctx context.Context, expenseID uint64, id uint64) (bool, error) {
|
||||
var count int64
|
||||
err := r.DB().WithContext(ctx).Model(&entity.ExpenseNonstock{}).
|
||||
Where("id = ? AND expense_id = ?", id, expenseID).
|
||||
Count(&count).Error
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
return count > 0, nil
|
||||
}
|
||||
|
||||
func (r *ExpenseNonstockRepositoryImpl) GetWithRelations(ctx context.Context, id uint64) (*entity.ExpenseNonstock, error) {
|
||||
var expenseNonstock entity.ExpenseNonstock
|
||||
err := r.DB().WithContext(ctx).
|
||||
Where("id = ?", id).
|
||||
Preload("Nonstock", func(db *gorm.DB) *gorm.DB {
|
||||
return db.Preload("Suppliers")
|
||||
}).
|
||||
First(&expenseNonstock).Error
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &expenseNonstock, nil
|
||||
}
|
||||
|
||||
@@ -11,6 +11,7 @@ import (
|
||||
type ExpenseRealizationRepository interface {
|
||||
repository.BaseRepository[entity.ExpenseRealization]
|
||||
IdExists(ctx context.Context, id uint64) (bool, error)
|
||||
GetByExpenseNonstockID(ctx context.Context, expenseNonstockID uint64) (*entity.ExpenseRealization, error)
|
||||
}
|
||||
|
||||
type ExpenseRealizationRepositoryImpl struct {
|
||||
@@ -26,3 +27,14 @@ func NewExpenseRealizationRepository(db *gorm.DB) ExpenseRealizationRepository {
|
||||
func (r *ExpenseRealizationRepositoryImpl) IdExists(ctx context.Context, id uint64) (bool, error) {
|
||||
return repository.Exists[entity.ExpenseRealization](ctx, r.DB(), uint(id))
|
||||
}
|
||||
|
||||
func (r *ExpenseRealizationRepositoryImpl) GetByExpenseNonstockID(ctx context.Context, expenseNonstockID uint64) (*entity.ExpenseRealization, error) {
|
||||
var realization entity.ExpenseRealization
|
||||
err := r.DB().WithContext(ctx).
|
||||
Where("expense_nonstock_id = ?", expenseNonstockID).
|
||||
First(&realization).Error
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &realization, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user