mirror of
https://gitlab.com/mbugroup/lti-api.git
synced 2026-05-25 15:55:44 +00:00
FIX[BE]: adjust response on proudctwarehouses
This commit is contained in:
@@ -8,6 +8,7 @@ import (
|
||||
KandangRepo "gitlab.com/mbugroup/lti-api.git/internal/modules/master/kandangs/repositories"
|
||||
rWarehouse "gitlab.com/mbugroup/lti-api.git/internal/modules/master/warehouses/repositories"
|
||||
repository "gitlab.com/mbugroup/lti-api.git/internal/modules/production/chickins/repositories"
|
||||
rProjectFlockKandang "gitlab.com/mbugroup/lti-api.git/internal/modules/production/project_flocks/repositories"
|
||||
|
||||
validation "gitlab.com/mbugroup/lti-api.git/internal/modules/production/chickins/validations"
|
||||
rProjectFlock "gitlab.com/mbugroup/lti-api.git/internal/modules/production/project_flocks/repositories"
|
||||
@@ -30,34 +31,41 @@ type ChickinService interface {
|
||||
}
|
||||
|
||||
type chickinService struct {
|
||||
Log *logrus.Logger
|
||||
Validate *validator.Validate
|
||||
Repository repository.ProjectChickinRepository
|
||||
KandangRepo KandangRepo.KandangRepository
|
||||
WarehouseRepo rWarehouse.WarehouseRepository
|
||||
ProductWarehouseRepo rProductWarehouse.ProductWarehouseRepository
|
||||
ProjectFlockRepo rProjectFlock.ProjectflockRepository
|
||||
AuditLogRepo AuditLogRepo.AuditLogRepository
|
||||
Log *logrus.Logger
|
||||
Validate *validator.Validate
|
||||
Repository repository.ProjectChickinRepository
|
||||
KandangRepo KandangRepo.KandangRepository
|
||||
WarehouseRepo rWarehouse.WarehouseRepository
|
||||
ProductWarehouseRepo rProductWarehouse.ProductWarehouseRepository
|
||||
ProjectFlockRepo rProjectFlock.ProjectflockRepository
|
||||
AuditLogRepo AuditLogRepo.AuditLogRepository
|
||||
ProjectflockKandangRepo rProjectFlockKandang.ProjectFlockKandangRepository
|
||||
}
|
||||
|
||||
func NewChickinService(repo repository.ProjectChickinRepository, kandangRepo KandangRepo.KandangRepository, warehouseRepo rWarehouse.WarehouseRepository, productWarehouseRepo rProductWarehouse.ProductWarehouseRepository, projectFlockRepo rProjectFlock.ProjectflockRepository, auditLogRepo AuditLogRepo.AuditLogRepository, validate *validator.Validate) ChickinService {
|
||||
func NewChickinService(repo repository.ProjectChickinRepository, kandangRepo KandangRepo.KandangRepository, warehouseRepo rWarehouse.WarehouseRepository, productWarehouseRepo rProductWarehouse.ProductWarehouseRepository, projectFlockRepo rProjectFlock.ProjectflockRepository, auditLogRepo AuditLogRepo.AuditLogRepository, projectflockkandangRepo rProjectFlockKandang.ProjectFlockKandangRepository, validate *validator.Validate) ChickinService {
|
||||
return &chickinService{
|
||||
Log: utils.Log,
|
||||
Validate: validate,
|
||||
Repository: repo,
|
||||
KandangRepo: kandangRepo,
|
||||
WarehouseRepo: warehouseRepo,
|
||||
ProductWarehouseRepo: productWarehouseRepo,
|
||||
ProjectFlockRepo: projectFlockRepo,
|
||||
AuditLogRepo: auditLogRepo,
|
||||
Log: utils.Log,
|
||||
Validate: validate,
|
||||
Repository: repo,
|
||||
KandangRepo: kandangRepo,
|
||||
WarehouseRepo: warehouseRepo,
|
||||
ProductWarehouseRepo: productWarehouseRepo,
|
||||
ProjectFlockRepo: projectFlockRepo,
|
||||
AuditLogRepo: auditLogRepo,
|
||||
ProjectflockKandangRepo: projectflockkandangRepo,
|
||||
}
|
||||
}
|
||||
|
||||
func (s chickinService) withRelations(db *gorm.DB) *gorm.DB {
|
||||
return db.
|
||||
Preload("CreatedUser").
|
||||
Preload("ProjectFlock").
|
||||
Preload("ProjectFlock.ProductCategory")
|
||||
Preload("ProjectFlockKandang.Kandang").
|
||||
Preload("ProjectFlockKandang.ProjectFlock").
|
||||
Preload("ProjectFlockKandang.ProjectFlock.Flock").
|
||||
Preload("ProjectFlockKandang.ProjectFlock.ProductCategory").
|
||||
Preload("ProjectFlockKandang.ProjectFlock.Area").
|
||||
Preload("ProjectFlockKandang.ProjectFlock.Fcr").
|
||||
Preload("ProjectFlockKandang.ProjectFlock.Location")
|
||||
|
||||
}
|
||||
|
||||
@@ -101,25 +109,27 @@ func (s *chickinService) CreateOne(c *fiber.Ctx, req *validation.Create) (*entit
|
||||
}
|
||||
|
||||
// ambil salah satu kandang dari project_floc_id dari kandang repository
|
||||
kandang, err := s.KandangRepo.GetFirstByProjectFlockID(c.Context(), 1)
|
||||
projectflockkandang, err := s.ProjectflockKandangRepo.GetByID(c.Context(), 1)
|
||||
if err != nil {
|
||||
s.Log.Errorf("Failed to get kandang: %+v", err)
|
||||
s.Log.Errorf("Failed to get projectflock kandang: %+v", err)
|
||||
return nil, err
|
||||
}
|
||||
// ambil warehouse dari kandangid
|
||||
warehouse, err := s.WarehouseRepo.GetByKandangID(c.Context(), kandang.Id)
|
||||
warehouse, err := s.WarehouseRepo.GetByKandangID(c.Context(), projectflockkandang.KandangId)
|
||||
if err != nil {
|
||||
s.Log.Errorf("Failed to get warehouse: %+v", err)
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// getprojectflock id with relation
|
||||
projectFlock, err := s.ProjectFlockRepo.GetByID(
|
||||
c.Context(),
|
||||
req.ProjectFlockId,
|
||||
projectflockkandang.ProjectFlockId,
|
||||
func(db *gorm.DB) *gorm.DB {
|
||||
return db.Preload("ProductCategory")
|
||||
},
|
||||
)
|
||||
|
||||
if err != nil {
|
||||
s.Log.Errorf("Failed to get project flock: %+v", err)
|
||||
return nil, fiber.NewError(fiber.StatusNotFound, "Project Flock not found")
|
||||
@@ -153,11 +163,11 @@ func (s *chickinService) CreateOne(c *fiber.Ctx, req *validation.Create) (*entit
|
||||
}
|
||||
|
||||
newChickin := &entity.ProjectChickin{
|
||||
ProjectFlocId: req.ProjectFlockId,
|
||||
ChickInDate: chickinDate,
|
||||
Quantity: productWarehouse.Quantity,
|
||||
Note: "",
|
||||
CreatedBy: 1, //todo: ganti dengan
|
||||
ProjectFlocKandangId: projectflockkandang.ProjectFlockId,
|
||||
ChickInDate: chickinDate,
|
||||
Quantity: productWarehouse.Quantity,
|
||||
Note: "",
|
||||
CreatedBy: 1, //todo: ganti dengan
|
||||
}
|
||||
|
||||
err = s.Repository.CreateOne(c.Context(), newChickin, nil)
|
||||
@@ -183,7 +193,7 @@ func (s *chickinService) CreateOne(c *fiber.Ctx, req *validation.Create) (*entit
|
||||
stockAvailability := &entity.StockAvailability{
|
||||
EntityType: entity.EntityTypeProjectFlockKandang,
|
||||
ReservedQuantity: productWarehouse.Quantity,
|
||||
EntityId: req.ProjectFlockId, //todo: nanti pakek projct flock kandang id
|
||||
EntityId: projectflockkandang.Id,
|
||||
ProductId: productWarehouse.ProductId,
|
||||
}
|
||||
|
||||
@@ -218,7 +228,8 @@ func (s *chickinService) CreateOne(c *fiber.Ctx, req *validation.Create) (*entit
|
||||
}
|
||||
|
||||
}
|
||||
return nil, nil
|
||||
|
||||
return s.GetOne(c, newChickin.Id)
|
||||
}
|
||||
|
||||
func (s chickinService) UpdateOne(c *fiber.Ctx, req *validation.Update, id uint) (*entity.ProjectChickin, error) {
|
||||
@@ -276,7 +287,7 @@ func (s *chickinService) Approve(c *fiber.Ctx, id uint) error {
|
||||
// get stock avaibility untuk di update
|
||||
var stockAvailability entity.StockAvailability
|
||||
err = s.ProductWarehouseRepo.DB().WithContext(c.Context()).
|
||||
Where("entity_type = ? AND entity_id = ? ", entity.EntityTypeProjectFlockKandang, chickin.ProjectFlocId).
|
||||
Where("entity_type = ? AND entity_id = ? ", entity.EntityTypeProjectFlockKandang, chickin.ProjectFlocKandangId).
|
||||
First(&stockAvailability).Error
|
||||
if err != nil {
|
||||
s.Log.Errorf("Failed to get stock availability: %+v", err)
|
||||
@@ -288,7 +299,5 @@ func (s *chickinService) Approve(c *fiber.Ctx, id uint) error {
|
||||
newReservedQuantity = 0
|
||||
}
|
||||
|
||||
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user