FIX[BE]: fix logic on Chickin Laying not convert to layer but still Pullet, and inisiate laying transfer migration and base basic API

This commit is contained in:
aguhh18
2025-11-04 08:24:38 +07:00
parent c72db5bd18
commit 8220e34302
22 changed files with 587 additions and 163 deletions
@@ -1,6 +1,8 @@
package repository
import (
"context"
"gitlab.com/mbugroup/lti-api.git/internal/common/repository"
entity "gitlab.com/mbugroup/lti-api.git/internal/entities"
"gorm.io/gorm"
@@ -8,15 +10,29 @@ import (
type TransferLayingRepository interface {
repository.BaseRepository[entity.LayingTransfer]
GetByTransferNumber(ctx context.Context, transferNumber string) (*entity.LayingTransfer, error)
}
type TransferLayingRepositoryImpl struct {
*repository.BaseRepositoryImpl[entity.LayingTransfer]
db *gorm.DB
}
func NewTransferLayingRepository(db *gorm.DB) TransferLayingRepository {
return &TransferLayingRepositoryImpl{
BaseRepositoryImpl: repository.NewBaseRepository[entity.LayingTransfer](db),
db: db,
}
}
func (r *TransferLayingRepositoryImpl) GetByTransferNumber(ctx context.Context, transferNumber string) (*entity.LayingTransfer, error) {
var transfer entity.LayingTransfer
err := r.db.WithContext(ctx).
Where("transfer_number = ?", transferNumber).
Where("deleted_at IS NULL").
First(&transfer).Error
if err != nil {
return nil, err
}
return &transfer, nil
}
@@ -0,0 +1,38 @@
package repository
import (
"context"
"gitlab.com/mbugroup/lti-api.git/internal/common/repository"
entity "gitlab.com/mbugroup/lti-api.git/internal/entities"
"gorm.io/gorm"
)
type LayingTransferSourceRepository interface {
repository.BaseRepository[entity.LayingTransferSource]
GetByLayingTransferId(ctx context.Context, layingTransferId uint) ([]entity.LayingTransferSource, error)
}
type LayingTransferSourceRepositoryImpl struct {
*repository.BaseRepositoryImpl[entity.LayingTransferSource]
db *gorm.DB
}
func NewLayingTransferSourceRepository(db *gorm.DB) LayingTransferSourceRepository {
return &LayingTransferSourceRepositoryImpl{
BaseRepositoryImpl: repository.NewBaseRepository[entity.LayingTransferSource](db),
db: db,
}
}
func (r *LayingTransferSourceRepositoryImpl) GetByLayingTransferId(ctx context.Context, layingTransferId uint) ([]entity.LayingTransferSource, error) {
var sources []entity.LayingTransferSource
err := r.db.WithContext(ctx).
Where("laying_transfer_id = ?", layingTransferId).
Order("created_at DESC").
Find(&sources).Error
if err != nil {
return nil, err
}
return sources, nil
}
@@ -0,0 +1,38 @@
package repository
import (
"context"
"gitlab.com/mbugroup/lti-api.git/internal/common/repository"
entity "gitlab.com/mbugroup/lti-api.git/internal/entities"
"gorm.io/gorm"
)
type LayingTransferTargetRepository interface {
repository.BaseRepository[entity.LayingTransferTarget]
GetByLayingTransferId(ctx context.Context, layingTransferId uint) ([]entity.LayingTransferTarget, error)
}
type LayingTransferTargetRepositoryImpl struct {
*repository.BaseRepositoryImpl[entity.LayingTransferTarget]
db *gorm.DB
}
func NewLayingTransferTargetRepository(db *gorm.DB) LayingTransferTargetRepository {
return &LayingTransferTargetRepositoryImpl{
BaseRepositoryImpl: repository.NewBaseRepository[entity.LayingTransferTarget](db),
db: db,
}
}
func (r *LayingTransferTargetRepositoryImpl) GetByLayingTransferId(ctx context.Context, layingTransferId uint) ([]entity.LayingTransferTarget, error) {
var targets []entity.LayingTransferTarget
err := r.db.WithContext(ctx).
Where("laying_transfer_id = ?", layingTransferId).
Order("created_at DESC").
Find(&targets).Error
if err != nil {
return nil, err
}
return targets, nil
}