mirror of
https://gitlab.com/mbugroup/lti-api.git
synced 2026-05-24 07:15:43 +00:00
feat(BE-281): unfinished uniformity and create project flock triger productwarehouse and add new filtering lookup
This commit is contained in:
@@ -17,6 +17,7 @@ type RecordingRepository interface {
|
||||
repository.BaseRepository[entity.Recording]
|
||||
|
||||
WithRelations(db *gorm.DB) *gorm.DB
|
||||
GetLatestByProjectFlockKandangID(ctx context.Context, projectFlockKandangId uint) (*entity.Recording, error)
|
||||
GenerateNextDay(tx *gorm.DB, projectFlockKandangId uint) (int, error)
|
||||
|
||||
CreateBodyWeights(tx *gorm.DB, bodyWeights []entity.RecordingBW) error
|
||||
@@ -81,6 +82,27 @@ func (r *RecordingRepositoryImpl) WithRelations(db *gorm.DB) *gorm.DB {
|
||||
Preload("Eggs.ProductWarehouse.Warehouse")
|
||||
}
|
||||
|
||||
func (r *RecordingRepositoryImpl) GetLatestByProjectFlockKandangID(ctx context.Context, projectFlockKandangId uint) (*entity.Recording, error) {
|
||||
if projectFlockKandangId == 0 {
|
||||
return nil, errors.New("project_flock_kandang_id is required")
|
||||
}
|
||||
|
||||
var record entity.Recording
|
||||
err := r.DB().WithContext(ctx).
|
||||
Where("project_flock_kandangs_id = ?", projectFlockKandangId).
|
||||
Order("record_datetime DESC").
|
||||
Order("created_at DESC").
|
||||
Limit(1).
|
||||
Find(&record).Error
|
||||
if errors.Is(err, gorm.ErrRecordNotFound) || record.Id == 0 {
|
||||
return nil, nil
|
||||
}
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &record, nil
|
||||
}
|
||||
|
||||
func (r *RecordingRepositoryImpl) GenerateNextDay(tx *gorm.DB, projectFlockKandangId uint) (int, error) {
|
||||
var days []int
|
||||
if err := tx.Model(&entity.Recording{}).
|
||||
|
||||
Reference in New Issue
Block a user