mirror of
https://gitlab.com/mbugroup/lti-api.git
synced 2026-05-24 15:25:43 +00:00
add restrict delete master data kandang group
This commit is contained in:
@@ -2,6 +2,7 @@ package repository
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
|
||||
"gorm.io/gorm"
|
||||
|
||||
@@ -14,6 +15,7 @@ type KandangGroupRepository interface {
|
||||
LocationExists(ctx context.Context, locationId uint) (bool, error)
|
||||
PicExists(ctx context.Context, picId uint) (bool, error)
|
||||
NameExists(ctx context.Context, name string, excludeID *uint) (bool, error)
|
||||
HasDailyChecklistRelation(ctx context.Context, kandangGroupId uint) (bool, error)
|
||||
}
|
||||
|
||||
type KandangGroupRepositoryImpl struct {
|
||||
@@ -39,3 +41,20 @@ func (r *KandangGroupRepositoryImpl) PicExists(ctx context.Context, picId uint)
|
||||
func (r *KandangGroupRepositoryImpl) NameExists(ctx context.Context, name string, excludeID *uint) (bool, error) {
|
||||
return repository.ExistsByName[entity.KandangGroup](ctx, r.db, name, excludeID)
|
||||
}
|
||||
|
||||
func (r *KandangGroupRepositoryImpl) HasDailyChecklistRelation(ctx context.Context, kandangGroupId uint) (bool, error) {
|
||||
var marker int
|
||||
err := r.db.WithContext(ctx).
|
||||
Model(&entity.DailyChecklist{}).
|
||||
Select("1").
|
||||
Where("kandang_id = ?", kandangGroupId).
|
||||
Limit(1).
|
||||
Take(&marker).Error
|
||||
if errors.Is(err, gorm.ErrRecordNotFound) {
|
||||
return false, nil
|
||||
}
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
return true, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user