mirror of
https://gitlab.com/mbugroup/lti-api.git
synced 2026-05-20 13:31:56 +00:00
Merge branch 'development' of https://gitlab.com/mbugroup/lti-api into dev/ragil
This commit is contained in:
@@ -18,6 +18,8 @@ type NonstockRepository interface {
|
||||
SyncFlags(ctx context.Context, tx *gorm.DB, nonstockID uint, flags []string) error
|
||||
DeleteFlags(ctx context.Context, tx *gorm.DB, nonstockID uint) error
|
||||
GetFlags(ctx context.Context, nonstockID uint) ([]entity.Flag, error)
|
||||
IdExists(ctx context.Context, id uint) (bool, error)
|
||||
IsNonstockAssociatedWithSupplier(ctx context.Context, nonstockID uint, supplierID uint64) (bool, error)
|
||||
}
|
||||
|
||||
type NonstockRepositoryImpl struct {
|
||||
@@ -34,6 +36,10 @@ func (r *NonstockRepositoryImpl) NameExists(ctx context.Context, name string, ex
|
||||
return repository.ExistsByName[entity.Nonstock](ctx, r.DB(), name, excludeID)
|
||||
}
|
||||
|
||||
func (r *NonstockRepositoryImpl) IdExists(ctx context.Context, id uint) (bool, error) {
|
||||
return repository.Exists[entity.Nonstock](ctx, r.DB(), id)
|
||||
}
|
||||
|
||||
func (r *NonstockRepositoryImpl) SyncSuppliersDiff(ctx context.Context, tx *gorm.DB, nonstockID uint, supplierIDs []uint) error {
|
||||
db := tx
|
||||
if db == nil {
|
||||
@@ -170,3 +176,15 @@ func (r *NonstockRepositoryImpl) GetFlags(ctx context.Context, nonstockID uint)
|
||||
}
|
||||
return flags, nil
|
||||
}
|
||||
|
||||
func (r *NonstockRepositoryImpl) IsNonstockAssociatedWithSupplier(ctx context.Context, nonstockID uint, supplierID uint64) (bool, error) {
|
||||
var count int64
|
||||
if err := r.DB().WithContext(ctx).
|
||||
Model(&entity.NonstockSupplier{}).
|
||||
Where("nonstock_id = ? AND supplier_id = ?", nonstockID, supplierID).
|
||||
Count(&count).
|
||||
Error; err != nil {
|
||||
return false, err
|
||||
}
|
||||
return count > 0, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user