mirror of
https://gitlab.com/mbugroup/lti-api.git
synced 2026-05-24 15:25:43 +00:00
adjust
This commit is contained in:
@@ -312,10 +312,10 @@ func (u *ProjectflockController) LookupProjectFlockKandang(c *fiber.Ctx) error {
|
|||||||
mapped := warehouseDTO.ToWarehouseRelationDTO(*warehouse)
|
mapped := warehouseDTO.ToWarehouseRelationDTO(*warehouse)
|
||||||
dtoResult.Warehouse = &mapped
|
dtoResult.Warehouse = &mapped
|
||||||
}
|
}
|
||||||
if isTransition, isLaying, serr := u.ProjectflockService.GetProjectFlockKandangTransferStateAtDate(c, result.Id, recordDate); serr != nil {
|
if _, isLaying, serr := u.ProjectflockService.GetProjectFlockKandangTransferStateAtDate(c, result.Id, recordDate); serr != nil {
|
||||||
return serr
|
return serr
|
||||||
} else {
|
} else {
|
||||||
dtoResult.IsTransition = isTransition
|
dtoResult.IsTransition = false
|
||||||
dtoResult.IsLaying = isLaying
|
dtoResult.IsLaying = isLaying
|
||||||
}
|
}
|
||||||
applyCutOverLayingLookupOverride(&dtoResult)
|
applyCutOverLayingLookupOverride(&dtoResult)
|
||||||
|
|||||||
@@ -1737,9 +1737,6 @@ func (s *recordingService) resolveTransferSourceProjectFlockKandangID(ctx contex
|
|||||||
if transfer == nil || transfer.Id == 0 {
|
if transfer == nil || transfer.Id == 0 {
|
||||||
return 0, nil
|
return 0, nil
|
||||||
}
|
}
|
||||||
if transfer.SourceProjectFlockKandangId != nil && *transfer.SourceProjectFlockKandangId != 0 {
|
|
||||||
return *transfer.SourceProjectFlockKandangId, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
var row struct {
|
var row struct {
|
||||||
SourceProjectFlockKandangID uint `gorm:"column:source_project_flock_kandang_id"`
|
SourceProjectFlockKandangID uint `gorm:"column:source_project_flock_kandang_id"`
|
||||||
@@ -1754,12 +1751,21 @@ func (s *recordingService) resolveTransferSourceProjectFlockKandangID(ctx contex
|
|||||||
Limit(1).
|
Limit(1).
|
||||||
Take(&row).Error
|
Take(&row).Error
|
||||||
if errors.Is(err, gorm.ErrRecordNotFound) {
|
if errors.Is(err, gorm.ErrRecordNotFound) {
|
||||||
|
if transfer.SourceProjectFlockKandangId != nil && *transfer.SourceProjectFlockKandangId != 0 {
|
||||||
|
return *transfer.SourceProjectFlockKandangId, nil
|
||||||
|
}
|
||||||
return 0, nil
|
return 0, nil
|
||||||
}
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return 0, err
|
return 0, err
|
||||||
}
|
}
|
||||||
return row.SourceProjectFlockKandangID, nil
|
if row.SourceProjectFlockKandangID != 0 {
|
||||||
|
return row.SourceProjectFlockKandangID, nil
|
||||||
|
}
|
||||||
|
if transfer.SourceProjectFlockKandangId != nil && *transfer.SourceProjectFlockKandangId != 0 {
|
||||||
|
return *transfer.SourceProjectFlockKandangId, nil
|
||||||
|
}
|
||||||
|
return 0, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *recordingService) getEarliestChickInDateByProjectFlockKandangID(ctx context.Context, projectFlockKandangID uint) (*time.Time, error) {
|
func (s *recordingService) getEarliestChickInDateByProjectFlockKandangID(ctx context.Context, projectFlockKandangID uint) (*time.Time, error) {
|
||||||
|
|||||||
@@ -148,6 +148,53 @@ func TestShouldNormalizeEggRequestsOnUpdateNormalizesFarmLevelEggs(t *testing.T)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestResolveTransferSourceProjectFlockKandangIDPrefersTransferResourceSource(t *testing.T) {
|
||||||
|
db := setupTransferSourceResolutionTestDB(t)
|
||||||
|
repo := repository.NewRecordingRepository(db)
|
||||||
|
svc := &recordingService{Repository: repo}
|
||||||
|
|
||||||
|
transfer := &entity.LayingTransfer{
|
||||||
|
Id: 77,
|
||||||
|
SourceProjectFlockKandangId: uintPtrForTest(999),
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := db.Exec(`INSERT INTO laying_transfer_sources (id, laying_transfer_id, source_project_flock_kandang_id, deleted_at) VALUES (1, 77, 123, NULL)`).Error; err != nil {
|
||||||
|
t.Fatalf("failed seeding laying_transfer_sources: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
got, err := svc.resolveTransferSourceProjectFlockKandangID(context.Background(), transfer)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("expected no error, got %v", err)
|
||||||
|
}
|
||||||
|
if got != 123 {
|
||||||
|
t.Fatalf("expected resource source project_flock_kandang_id=123, got %d", got)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestResolveTransferSourceProjectFlockKandangIDFallsBackToTransferHeader(t *testing.T) {
|
||||||
|
db := setupTransferSourceResolutionTestDB(t)
|
||||||
|
repo := repository.NewRecordingRepository(db)
|
||||||
|
svc := &recordingService{Repository: repo}
|
||||||
|
|
||||||
|
transfer := &entity.LayingTransfer{
|
||||||
|
Id: 78,
|
||||||
|
SourceProjectFlockKandangId: uintPtrForTest(456),
|
||||||
|
}
|
||||||
|
|
||||||
|
got, err := svc.resolveTransferSourceProjectFlockKandangID(context.Background(), transfer)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("expected no error, got %v", err)
|
||||||
|
}
|
||||||
|
if got != 456 {
|
||||||
|
t.Fatalf("expected fallback source project_flock_kandang_id=456, got %d", got)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func uintPtrForTest(value uint) *uint {
|
||||||
|
v := value
|
||||||
|
return &v
|
||||||
|
}
|
||||||
|
|
||||||
func setupRecordingServiceTestDB(t *testing.T) *gorm.DB {
|
func setupRecordingServiceTestDB(t *testing.T) *gorm.DB {
|
||||||
t.Helper()
|
t.Helper()
|
||||||
|
|
||||||
@@ -193,3 +240,23 @@ func setupRecordingServiceTestDB(t *testing.T) *gorm.DB {
|
|||||||
|
|
||||||
return db
|
return db
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func setupTransferSourceResolutionTestDB(t *testing.T) *gorm.DB {
|
||||||
|
t.Helper()
|
||||||
|
|
||||||
|
db, err := gorm.Open(sqlite.Open("file:"+t.Name()+"?mode=memory&cache=private"), &gorm.Config{})
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("failed opening sqlite db: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := db.Exec(`CREATE TABLE laying_transfer_sources (
|
||||||
|
id INTEGER PRIMARY KEY,
|
||||||
|
laying_transfer_id INTEGER NOT NULL,
|
||||||
|
source_project_flock_kandang_id INTEGER NOT NULL,
|
||||||
|
deleted_at TIMESTAMP NULL
|
||||||
|
)`).Error; err != nil {
|
||||||
|
t.Fatalf("failed creating laying_transfer_sources schema: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
return db
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user