feat(BE-115,116,117): implement chickin CRUD, approve logic, and stock availabilit

This commit is contained in:
aguhh18
2025-10-20 06:01:16 +07:00
parent 68a670a2bd
commit 83c3e61113
34 changed files with 558 additions and 199 deletions
@@ -15,6 +15,7 @@ type KandangRepository interface {
PicExists(ctx context.Context, areaId uint) (bool, error)
NameExists(ctx context.Context, name string, excludeID *uint) (bool, error)
ProjectFlockExists(ctx context.Context, projectFlockID uint) (bool, error)
GetFirstByProjectFlockID(ctx context.Context, projectFlockID uint) (*entity.Kandang, error)
HasActiveKandangForProjectFlock(ctx context.Context, projectFlockID uint, excludeID *uint) (bool, error)
}
@@ -69,3 +70,14 @@ func (r *KandangRepositoryImpl) HasActiveKandangForProjectFlock(ctx context.Cont
}
return count > 0, nil
}
func (r *KandangRepositoryImpl) GetFirstByProjectFlockID(ctx context.Context, projectFlockID uint) (*entity.Kandang, error) {
kandang := new(entity.Kandang)
err := r.db.WithContext(ctx).
Where("project_flock_id = ?", projectFlockID).
First(kandang).Error
if err != nil {
return nil, err
}
return kandang, nil
}