mirror of
https://gitlab.com/mbugroup/lti-api.git
synced 2026-05-23 23:05:44 +00:00
feat(BE): finance (payment, initial_balance, injection). fix(BE): kandang capacity
This commit is contained in:
@@ -0,0 +1,51 @@
|
||||
package repository
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"gitlab.com/mbugroup/lti-api.git/internal/common/repository"
|
||||
entity "gitlab.com/mbugroup/lti-api.git/internal/entities"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
type InitialRepository interface {
|
||||
repository.BaseRepository[entity.Payment]
|
||||
BankExists(ctx context.Context, bankId uint) (bool, error)
|
||||
CustomerExists(ctx context.Context, customerId uint) (bool, error)
|
||||
SupplierExists(ctx context.Context, supplierId uint) (bool, error)
|
||||
NextPaymentSequence(ctx context.Context) (int64, error)
|
||||
}
|
||||
|
||||
type InitialRepositoryImpl struct {
|
||||
*repository.BaseRepositoryImpl[entity.Payment]
|
||||
db *gorm.DB
|
||||
}
|
||||
|
||||
func NewInitialRepository(db *gorm.DB) InitialRepository {
|
||||
return &InitialRepositoryImpl{
|
||||
BaseRepositoryImpl: repository.NewBaseRepository[entity.Payment](db),
|
||||
db: db,
|
||||
}
|
||||
}
|
||||
|
||||
func (r *InitialRepositoryImpl) BankExists(ctx context.Context, bankId uint) (bool, error) {
|
||||
return repository.Exists[entity.Bank](ctx, r.db, bankId)
|
||||
}
|
||||
|
||||
func (r *InitialRepositoryImpl) CustomerExists(ctx context.Context, customerId uint) (bool, error) {
|
||||
return repository.Exists[entity.Customer](ctx, r.db, customerId)
|
||||
}
|
||||
|
||||
func (r *InitialRepositoryImpl) SupplierExists(ctx context.Context, supplierId uint) (bool, error) {
|
||||
return repository.Exists[entity.Supplier](ctx, r.db, supplierId)
|
||||
}
|
||||
|
||||
func (r *InitialRepositoryImpl) NextPaymentSequence(ctx context.Context) (int64, error) {
|
||||
var next int64
|
||||
if err := r.db.WithContext(ctx).
|
||||
Raw("SELECT nextval('payments_code_seq')").
|
||||
Scan(&next).Error; err != nil {
|
||||
return 0, err
|
||||
}
|
||||
return next, nil
|
||||
}
|
||||
Reference in New Issue
Block a user