mirror of
https://gitlab.com/mbugroup/lti-api.git
synced 2026-05-20 13:31:56 +00:00
Merge branch 'fix/merge-request-project-flock' into 'feat/BE/Sprint-5'
fix merging See merge request mbugroup/lti-api!68
This commit is contained in:
+6
-13
@@ -4,7 +4,6 @@ import (
|
||||
"math"
|
||||
"strconv"
|
||||
|
||||
flockDTO "gitlab.com/mbugroup/lti-api.git/internal/modules/master/flocks/dto"
|
||||
"gitlab.com/mbugroup/lti-api.git/internal/modules/production/project-flock-kandangs/dto"
|
||||
service "gitlab.com/mbugroup/lti-api.git/internal/modules/production/project-flock-kandangs/services"
|
||||
validation "gitlab.com/mbugroup/lti-api.git/internal/modules/production/project-flock-kandangs/validations"
|
||||
@@ -41,18 +40,14 @@ func (u *ProjectFlockKandangController) GetAll(c *fiber.Ctx) error {
|
||||
return fiber.NewError(fiber.StatusBadRequest, "page and limit must be greater than 0")
|
||||
}
|
||||
|
||||
results, totalResults, flockMap, err := u.ProjectFlockKandangService.GetAll(c, query)
|
||||
results, totalResults, err := u.ProjectFlockKandangService.GetAll(c, query)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
data := make([]dto.ProjectFlockKandangListDTO, 0)
|
||||
data := make([]dto.ProjectFlockKandangListDTO, 0, len(results))
|
||||
for _, result := range results {
|
||||
var flock *flockDTO.FlockRelationDTO
|
||||
if flockMap != nil {
|
||||
flock = flockMap[result.ProjectFlock.Id]
|
||||
}
|
||||
data = append(data, dto.ToProjectFlockKandangListDTOWithFlock(result, flock))
|
||||
data = append(data, dto.ToProjectFlockKandangListDTO(result))
|
||||
}
|
||||
|
||||
return c.Status(fiber.StatusOK).
|
||||
@@ -71,14 +66,12 @@ func (u *ProjectFlockKandangController) GetAll(c *fiber.Ctx) error {
|
||||
}
|
||||
|
||||
func (u *ProjectFlockKandangController) GetOne(c *fiber.Ctx) error {
|
||||
param := c.Params("id")
|
||||
|
||||
id, err := strconv.Atoi(param)
|
||||
id, err := strconv.Atoi(c.Params("id"))
|
||||
if err != nil {
|
||||
return fiber.NewError(fiber.StatusBadRequest, "Invalid Id")
|
||||
}
|
||||
|
||||
result, availableQtys, productWarehouses, flock, err := u.ProjectFlockKandangService.GetOne(c, uint(id))
|
||||
result, availableQtys, productWarehouses, err := u.ProjectFlockKandangService.GetOne(c, uint(id))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -88,6 +81,6 @@ func (u *ProjectFlockKandangController) GetOne(c *fiber.Ctx) error {
|
||||
Code: fiber.StatusOK,
|
||||
Status: "success",
|
||||
Message: "Get projectFlockKandang successfully",
|
||||
Data: dto.ToProjectFlockKandangDetailDTOWithAvailableQtyAndFlock(*result, availableQtys, productWarehouses, flock),
|
||||
Data: dto.ToProjectFlockKandangDetailDTOWithAvailableQty(*result, availableQtys, productWarehouses),
|
||||
})
|
||||
}
|
||||
|
||||
+34
-58
@@ -5,9 +5,10 @@ import (
|
||||
|
||||
entity "gitlab.com/mbugroup/lti-api.git/internal/entities"
|
||||
approvalDTO "gitlab.com/mbugroup/lti-api.git/internal/modules/approvals/dto"
|
||||
productWarehouseDTO "gitlab.com/mbugroup/lti-api.git/internal/modules/inventory/product-warehouses/dto"
|
||||
areaDTO "gitlab.com/mbugroup/lti-api.git/internal/modules/master/areas/dto"
|
||||
fcrDTO "gitlab.com/mbugroup/lti-api.git/internal/modules/master/fcrs/dto"
|
||||
flockDTO "gitlab.com/mbugroup/lti-api.git/internal/modules/master/flocks/dto"
|
||||
kandangDTO "gitlab.com/mbugroup/lti-api.git/internal/modules/master/kandangs/dto"
|
||||
locationDTO "gitlab.com/mbugroup/lti-api.git/internal/modules/master/locations/dto"
|
||||
productDTO "gitlab.com/mbugroup/lti-api.git/internal/modules/master/products/dto"
|
||||
warehouseDTO "gitlab.com/mbugroup/lti-api.git/internal/modules/master/warehouses/dto"
|
||||
@@ -25,10 +26,7 @@ type ProjectFlockKandangRelationDTO struct {
|
||||
}
|
||||
|
||||
type ProjectFlockDTO struct {
|
||||
Id uint `json:"id"`
|
||||
Name string `json:"flock_name,omitempty"`
|
||||
Period int `json:"period"`
|
||||
Flock *flockDTO.FlockRelationDTO `json:"flock,omitempty"`
|
||||
projectFlockDTO.ProjectFlockRelationDTO
|
||||
Area *areaDTO.AreaRelationDTO `json:"area,omitempty"`
|
||||
Category string `json:"category"`
|
||||
Fcr *fcrDTO.FcrRelationDTO `json:"fcr,omitempty"`
|
||||
@@ -38,14 +36,8 @@ type ProjectFlockDTO struct {
|
||||
UpdatedAt time.Time `json:"updated_at"`
|
||||
}
|
||||
|
||||
type KandangDTO struct {
|
||||
Id uint `json:"id"`
|
||||
Name string `json:"name"`
|
||||
Status string `json:"status"`
|
||||
}
|
||||
|
||||
type ProductWarehouseDTO struct {
|
||||
Id uint `json:"id"`
|
||||
productWarehouseDTO.ProductWarehouseRelationDTO
|
||||
Product *productDTO.ProductRelationDTO `json:"product,omitempty"`
|
||||
Warehouse *warehouseDTO.WarehouseRelationDTO `json:"warehouse,omitempty"`
|
||||
}
|
||||
@@ -58,7 +50,7 @@ type AvailableQtyDTO struct {
|
||||
type ProjectFlockKandangListDTO struct {
|
||||
ProjectFlockKandangRelationDTO
|
||||
ProjectFlock *ProjectFlockDTO `json:"project_flock,omitempty"`
|
||||
Kandang *KandangDTO `json:"kandang,omitempty"`
|
||||
Kandang *kandangDTO.KandangRelationDTO `json:"kandang,omitempty"`
|
||||
CreatedUser *userDTO.UserRelationDTO `json:"created_user,omitempty"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
Approval *approvalDTO.ApprovalRelationDTO `json:"approval,omitempty"`
|
||||
@@ -86,25 +78,18 @@ func toProjectFlockDTO(pf *projectFlockDTO.ProjectFlockListDTO) *ProjectFlockDTO
|
||||
}
|
||||
|
||||
return &ProjectFlockDTO{
|
||||
Id: pf.Id,
|
||||
Name: pf.FlockName,
|
||||
Period: pf.Period,
|
||||
Flock: pf.Flock,
|
||||
Area: pf.Area,
|
||||
Category: pf.Category,
|
||||
Fcr: pf.Fcr,
|
||||
Location: pf.Location,
|
||||
CreatedUser: pf.CreatedUser,
|
||||
CreatedAt: pf.CreatedAt,
|
||||
UpdatedAt: pf.UpdatedAt,
|
||||
ProjectFlockRelationDTO: pf.ProjectFlockRelationDTO,
|
||||
Area: pf.Area,
|
||||
Category: pf.Category,
|
||||
Fcr: pf.Fcr,
|
||||
Location: pf.Location,
|
||||
CreatedUser: pf.CreatedUser,
|
||||
CreatedAt: pf.CreatedAt,
|
||||
UpdatedAt: pf.UpdatedAt,
|
||||
}
|
||||
}
|
||||
|
||||
func ToProjectFlockKandangDetailDTOWithAvailableQty(e entity.ProjectFlockKandang, availableQtyMap map[uint]float64, productWarehouses []entity.ProductWarehouse) ProjectFlockKandangDetailDTO {
|
||||
return ToProjectFlockKandangDetailDTOWithAvailableQtyAndFlock(e, availableQtyMap, productWarehouses, nil)
|
||||
}
|
||||
|
||||
func ToProjectFlockKandangDetailDTOWithAvailableQtyAndFlock(e entity.ProjectFlockKandang, availableQtyMap map[uint]float64, productWarehouses []entity.ProductWarehouse, flock *flockDTO.FlockRelationDTO) ProjectFlockKandangDetailDTO {
|
||||
var projectFlockSummary *projectFlockDTO.ProjectFlockListDTO
|
||||
if e.ProjectFlock.Id != 0 {
|
||||
mapped := projectFlockDTO.ToProjectFlockListDTO(e.ProjectFlock)
|
||||
@@ -114,7 +99,7 @@ func ToProjectFlockKandangDetailDTOWithAvailableQtyAndFlock(e entity.ProjectFloc
|
||||
listDTO := ProjectFlockKandangListDTO{
|
||||
ProjectFlockKandangRelationDTO: ToProjectFlockKandangRelationDTO(e),
|
||||
ProjectFlock: toProjectFlockDTO(projectFlockSummary),
|
||||
Kandang: toKandangDTO(e.Kandang),
|
||||
Kandang: toKandangRelation(e.Kandang),
|
||||
CreatedAt: e.CreatedAt,
|
||||
CreatedUser: toCreatedUserDTO(e.ProjectFlock),
|
||||
Approval: toApprovalDTO(e),
|
||||
@@ -127,29 +112,15 @@ func ToProjectFlockKandangDetailDTOWithAvailableQtyAndFlock(e entity.ProjectFloc
|
||||
}
|
||||
}
|
||||
|
||||
func toKandangDTO(kandang entity.Kandang) *KandangDTO {
|
||||
func toKandangRelation(kandang entity.Kandang) *kandangDTO.KandangRelationDTO {
|
||||
if kandang.Id == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
return &KandangDTO{
|
||||
Id: kandang.Id,
|
||||
Name: kandang.Name,
|
||||
Status: kandang.Status,
|
||||
}
|
||||
mapped := kandangDTO.ToKandangRelationDTO(kandang)
|
||||
return &mapped
|
||||
}
|
||||
|
||||
// func toFlockDTO(flock *entity.Flock) *flockDTO.FlockRelationDTO {
|
||||
// if flock == nil || flock.Id == 0 {
|
||||
// return nil
|
||||
// }
|
||||
|
||||
// return &flockDTO.FlockRelationDTO{
|
||||
// Id: flock.Id,
|
||||
// Name: flock.Name,
|
||||
// }
|
||||
// }
|
||||
|
||||
func toApprovalDTO(e entity.ProjectFlockKandang) *approvalDTO.ApprovalRelationDTO {
|
||||
if e.LatestApproval != nil {
|
||||
mapped := approvalDTO.ToApprovalDTO(*e.LatestApproval)
|
||||
@@ -159,20 +130,16 @@ func toApprovalDTO(e entity.ProjectFlockKandang) *approvalDTO.ApprovalRelationDT
|
||||
}
|
||||
|
||||
func ToProjectFlockKandangListDTO(e entity.ProjectFlockKandang) ProjectFlockKandangListDTO {
|
||||
return ToProjectFlockKandangListDTOWithFlock(e, nil)
|
||||
}
|
||||
|
||||
func ToProjectFlockKandangListDTOWithFlock(e entity.ProjectFlockKandang, flock *flockDTO.FlockRelationDTO) ProjectFlockKandangListDTO {
|
||||
var projectFlockSummary *projectFlockDTO.ProjectFlockListDTO
|
||||
if e.ProjectFlock.Id != 0 {
|
||||
mapped := projectFlockDTO.ToProjectFlockListDTOWithFlock(e.ProjectFlock, flock)
|
||||
mapped := projectFlockDTO.ToProjectFlockListDTO(e.ProjectFlock)
|
||||
projectFlockSummary = &mapped
|
||||
}
|
||||
|
||||
return ProjectFlockKandangListDTO{
|
||||
ProjectFlockKandangRelationDTO: ToProjectFlockKandangRelationDTO(e),
|
||||
ProjectFlock: toProjectFlockDTO(projectFlockSummary),
|
||||
Kandang: toKandangDTO(e.Kandang),
|
||||
Kandang: toKandangRelation(e.Kandang),
|
||||
CreatedAt: e.CreatedAt,
|
||||
CreatedUser: toCreatedUserDTO(e.ProjectFlock),
|
||||
Approval: toApprovalDTO(e),
|
||||
@@ -255,14 +222,23 @@ func ToProductWarehouseDTO(pw *entity.ProductWarehouse) *ProductWarehouseDTO {
|
||||
return nil
|
||||
}
|
||||
|
||||
chickinPwDTO := chickinDTO.ToProductWarehouseDTO(pw)
|
||||
if chickinPwDTO == nil {
|
||||
return nil
|
||||
base := productWarehouseDTO.ToProductWarehouseRelationDTO(*pw)
|
||||
|
||||
var product *productDTO.ProductRelationDTO
|
||||
if pw.Product.Id != 0 {
|
||||
mapped := productDTO.ToProductRelationDTO(pw.Product)
|
||||
product = &mapped
|
||||
}
|
||||
|
||||
var warehouse *warehouseDTO.WarehouseRelationDTO
|
||||
if pw.Warehouse.Id != 0 {
|
||||
mapped := warehouseDTO.ToWarehouseRelationDTO(pw.Warehouse)
|
||||
warehouse = &mapped
|
||||
}
|
||||
|
||||
return &ProductWarehouseDTO{
|
||||
Id: chickinPwDTO.Id,
|
||||
Product: chickinPwDTO.Product,
|
||||
Warehouse: chickinPwDTO.Warehouse,
|
||||
ProductWarehouseRelationDTO: base,
|
||||
Product: product,
|
||||
Warehouse: warehouse,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,7 +13,6 @@ import (
|
||||
commonRepo "gitlab.com/mbugroup/lti-api.git/internal/common/repository"
|
||||
commonSvc "gitlab.com/mbugroup/lti-api.git/internal/common/service"
|
||||
rProductWarehouse "gitlab.com/mbugroup/lti-api.git/internal/modules/inventory/product-warehouses/repositories"
|
||||
rFlock "gitlab.com/mbugroup/lti-api.git/internal/modules/master/flocks/repositories"
|
||||
rWarehouse "gitlab.com/mbugroup/lti-api.git/internal/modules/master/warehouses/repositories"
|
||||
"gitlab.com/mbugroup/lti-api.git/internal/utils"
|
||||
|
||||
@@ -29,7 +28,6 @@ func (ProjectFlockKandangModule) RegisterRoutes(router fiber.Router, db *gorm.DB
|
||||
userRepo := rUser.NewUserRepository(db)
|
||||
warehouseRepo := rWarehouse.NewWarehouseRepository(db)
|
||||
productWarehouseRepo := rProductWarehouse.NewProductWarehouseRepository(db)
|
||||
flockRepo := rFlock.NewFlockRepository(db)
|
||||
|
||||
approvalRepo := commonRepo.NewApprovalRepository(db)
|
||||
approvalService := commonSvc.NewApprovalService(approvalRepo)
|
||||
@@ -38,7 +36,7 @@ func (ProjectFlockKandangModule) RegisterRoutes(router fiber.Router, db *gorm.DB
|
||||
panic(fmt.Sprintf("failed to register project flock kandang approval workflow: %v", err))
|
||||
}
|
||||
|
||||
projectFlockKandangService := sProjectFlockKandang.NewProjectFlockKandangService(projectFlockKandangRepo, approvalService, warehouseRepo, productWarehouseRepo, projectFlockPopulationRepo, flockRepo, validate)
|
||||
projectFlockKandangService := sProjectFlockKandang.NewProjectFlockKandangService(projectFlockKandangRepo, approvalService, warehouseRepo, productWarehouseRepo, projectFlockPopulationRepo, validate)
|
||||
userService := sUser.NewUserService(userRepo, validate)
|
||||
|
||||
ProjectFlockKandangRoutes(router, userService, projectFlockKandangService)
|
||||
|
||||
+11
-50
@@ -6,12 +6,9 @@ import (
|
||||
commonSvc "gitlab.com/mbugroup/lti-api.git/internal/common/service"
|
||||
entity "gitlab.com/mbugroup/lti-api.git/internal/entities"
|
||||
rProductWarehouse "gitlab.com/mbugroup/lti-api.git/internal/modules/inventory/product-warehouses/repositories"
|
||||
flockDTO "gitlab.com/mbugroup/lti-api.git/internal/modules/master/flocks/dto"
|
||||
flockRepository "gitlab.com/mbugroup/lti-api.git/internal/modules/master/flocks/repositories"
|
||||
rWarehouse "gitlab.com/mbugroup/lti-api.git/internal/modules/master/warehouses/repositories"
|
||||
validation "gitlab.com/mbugroup/lti-api.git/internal/modules/production/project-flock-kandangs/validations"
|
||||
repository "gitlab.com/mbugroup/lti-api.git/internal/modules/production/project_flocks/repositories"
|
||||
pfutils "gitlab.com/mbugroup/lti-api.git/internal/modules/production/project_flocks/utils"
|
||||
"gitlab.com/mbugroup/lti-api.git/internal/utils"
|
||||
|
||||
"github.com/go-playground/validator/v10"
|
||||
@@ -21,8 +18,8 @@ import (
|
||||
)
|
||||
|
||||
type ProjectFlockKandangService interface {
|
||||
GetAll(ctx *fiber.Ctx, params *validation.Query) ([]entity.ProjectFlockKandang, int64, map[uint]*flockDTO.FlockRelationDTO, error)
|
||||
GetOne(ctx *fiber.Ctx, id uint) (*entity.ProjectFlockKandang, map[uint]float64, []entity.ProductWarehouse, *flockDTO.FlockRelationDTO, error)
|
||||
GetAll(ctx *fiber.Ctx, params *validation.Query) ([]entity.ProjectFlockKandang, int64, error)
|
||||
GetOne(ctx *fiber.Ctx, id uint) (*entity.ProjectFlockKandang, map[uint]float64, []entity.ProductWarehouse, error)
|
||||
}
|
||||
|
||||
// Note: map[uint]float64 adalah mapping dari ProductWarehouse ID ke calculated available quantity
|
||||
@@ -35,10 +32,9 @@ type projectFlockKandangService struct {
|
||||
WarehouseRepo rWarehouse.WarehouseRepository
|
||||
ProductWarehouseRepo rProductWarehouse.ProductWarehouseRepository
|
||||
PopulationRepo repository.ProjectFlockPopulationRepository
|
||||
FlockRepo flockRepository.FlockRepository
|
||||
}
|
||||
|
||||
func NewProjectFlockKandangService(repo repository.ProjectFlockKandangRepository, approvalSvc commonSvc.ApprovalService, warehouseRepo rWarehouse.WarehouseRepository, productWarehouseRepo rProductWarehouse.ProductWarehouseRepository, populationRepo repository.ProjectFlockPopulationRepository, flockRepo flockRepository.FlockRepository, validate *validator.Validate) ProjectFlockKandangService {
|
||||
func NewProjectFlockKandangService(repo repository.ProjectFlockKandangRepository, approvalSvc commonSvc.ApprovalService, warehouseRepo rWarehouse.WarehouseRepository, productWarehouseRepo rProductWarehouse.ProductWarehouseRepository, populationRepo repository.ProjectFlockPopulationRepository, validate *validator.Validate) ProjectFlockKandangService {
|
||||
return &projectFlockKandangService{
|
||||
Log: utils.Log,
|
||||
Validate: validate,
|
||||
@@ -47,13 +43,12 @@ func NewProjectFlockKandangService(repo repository.ProjectFlockKandangRepository
|
||||
WarehouseRepo: warehouseRepo,
|
||||
ProductWarehouseRepo: productWarehouseRepo,
|
||||
PopulationRepo: populationRepo,
|
||||
FlockRepo: flockRepo,
|
||||
}
|
||||
}
|
||||
|
||||
func (s projectFlockKandangService) GetAll(c *fiber.Ctx, params *validation.Query) ([]entity.ProjectFlockKandang, int64, map[uint]*flockDTO.FlockRelationDTO, error) {
|
||||
func (s projectFlockKandangService) GetAll(c *fiber.Ctx, params *validation.Query) ([]entity.ProjectFlockKandang, int64, error) {
|
||||
if err := s.Validate.Struct(params); err != nil {
|
||||
return nil, 0, nil, err
|
||||
return nil, 0, err
|
||||
}
|
||||
|
||||
offset := (params.Page - 1) * params.Limit
|
||||
@@ -62,7 +57,7 @@ func (s projectFlockKandangService) GetAll(c *fiber.Ctx, params *validation.Quer
|
||||
|
||||
if err != nil {
|
||||
s.Log.Errorf("Failed to get projectFlockKandangs: %+v", err)
|
||||
return nil, 0, nil, err
|
||||
return nil, 0, err
|
||||
}
|
||||
|
||||
if s.ApprovalSvc != nil {
|
||||
@@ -85,35 +80,16 @@ func (s projectFlockKandangService) GetAll(c *fiber.Ctx, params *validation.Quer
|
||||
}
|
||||
}
|
||||
|
||||
flockMap := make(map[uint]*flockDTO.FlockRelationDTO)
|
||||
for i := range projectFlockKandangs {
|
||||
if projectFlockKandangs[i].ProjectFlock.Id != 0 {
|
||||
baseName := pfutils.DeriveBaseName(projectFlockKandangs[i].ProjectFlock.FlockName)
|
||||
if baseName != "" {
|
||||
flock, err := s.FlockRepo.GetByName(c.Context(), baseName)
|
||||
if err != nil && !errors.Is(err, gorm.ErrRecordNotFound) {
|
||||
s.Log.Warnf("Failed to fetch flock %q: %+v", baseName, err)
|
||||
} else if flock != nil {
|
||||
|
||||
flockMap[projectFlockKandangs[i].ProjectFlock.Id] = &flockDTO.FlockRelationDTO{
|
||||
Id: flock.Id,
|
||||
Name: flock.Name,
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return projectFlockKandangs, total, flockMap, nil
|
||||
return projectFlockKandangs, total, nil
|
||||
}
|
||||
|
||||
func (s projectFlockKandangService) GetOne(c *fiber.Ctx, id uint) (*entity.ProjectFlockKandang, map[uint]float64, []entity.ProductWarehouse, *flockDTO.FlockRelationDTO, error) {
|
||||
func (s projectFlockKandangService) GetOne(c *fiber.Ctx, id uint) (*entity.ProjectFlockKandang, map[uint]float64, []entity.ProductWarehouse, error) {
|
||||
projectFlockKandang, err := s.Repository.GetByID(c.Context(), id)
|
||||
if errors.Is(err, gorm.ErrRecordNotFound) {
|
||||
return nil, nil, nil, nil, fiber.NewError(fiber.StatusNotFound, "ProjectFlockKandang not found")
|
||||
return nil, nil, nil, fiber.NewError(fiber.StatusNotFound, "ProjectFlockKandang not found")
|
||||
}
|
||||
if err != nil {
|
||||
return nil, nil, nil, nil, err
|
||||
return nil, nil, nil, err
|
||||
}
|
||||
|
||||
if len(projectFlockKandang.Chickins) > 0 && s.ApprovalSvc != nil {
|
||||
@@ -147,23 +123,8 @@ func (s projectFlockKandangService) GetOne(c *fiber.Ctx, id uint) (*entity.Proje
|
||||
productWarehouses = []entity.ProductWarehouse{}
|
||||
}
|
||||
}
|
||||
var flockResult *flockDTO.FlockRelationDTO
|
||||
if projectFlockKandang.ProjectFlock.Id != 0 {
|
||||
baseName := pfutils.DeriveBaseName(projectFlockKandang.ProjectFlock.FlockName)
|
||||
if baseName != "" {
|
||||
flock, err := s.FlockRepo.GetByName(c.Context(), baseName)
|
||||
if err != nil && !errors.Is(err, gorm.ErrRecordNotFound) {
|
||||
s.Log.Warnf("Failed to fetch flock %q: %+v", baseName, err)
|
||||
} else if flock != nil {
|
||||
flockResult = &flockDTO.FlockRelationDTO{
|
||||
Id: flock.Id,
|
||||
Name: flock.Name,
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return projectFlockKandang, availableQtyMap, productWarehouses, flockResult, nil
|
||||
return projectFlockKandang, availableQtyMap, productWarehouses, nil
|
||||
}
|
||||
|
||||
func (s projectFlockKandangService) getAvailableQuantities(c *fiber.Ctx, projectFlockKandang *entity.ProjectFlockKandang) (map[uint]float64, error) {
|
||||
|
||||
@@ -7,7 +7,6 @@ import (
|
||||
approvalDTO "gitlab.com/mbugroup/lti-api.git/internal/modules/approvals/dto"
|
||||
areaDTO "gitlab.com/mbugroup/lti-api.git/internal/modules/master/areas/dto"
|
||||
fcrDTO "gitlab.com/mbugroup/lti-api.git/internal/modules/master/fcrs/dto"
|
||||
flockDTO "gitlab.com/mbugroup/lti-api.git/internal/modules/master/flocks/dto"
|
||||
kandangDTO "gitlab.com/mbugroup/lti-api.git/internal/modules/master/kandangs/dto"
|
||||
locationDTO "gitlab.com/mbugroup/lti-api.git/internal/modules/master/locations/dto"
|
||||
|
||||
@@ -25,7 +24,6 @@ type ProjectFlockRelationDTO struct {
|
||||
|
||||
type ProjectFlockListDTO struct {
|
||||
ProjectFlockRelationDTO
|
||||
Flock *flockDTO.FlockRelationDTO `json:"flock,omitempty"`
|
||||
Area *areaDTO.AreaRelationDTO `json:"area,omitempty"`
|
||||
Category string `json:"category"`
|
||||
Fcr *fcrDTO.FcrRelationDTO `json:"fcr,omitempty"`
|
||||
@@ -40,17 +38,13 @@ type ProjectFlockListDTO struct {
|
||||
type KandangWithProjectFlockIdDTO struct {
|
||||
kandangDTO.KandangRelationDTO
|
||||
ProjectFlockKandangId uint `json:"project_flock_kandang_id"`
|
||||
Period int `json:"period"`
|
||||
}
|
||||
|
||||
type ProjectFlockDetailDTO struct {
|
||||
ProjectFlockListDTO
|
||||
}
|
||||
|
||||
type FlockPeriodDTO struct {
|
||||
Flock flockDTO.FlockRelationDTO `json:"flock"`
|
||||
NextPeriod int `json:"next_period"`
|
||||
}
|
||||
|
||||
type KandangPeriodSummaryDTO struct {
|
||||
Id uint `json:"id"`
|
||||
Name string `json:"name"`
|
||||
@@ -69,16 +63,21 @@ func ToProjectFlockListDTOWithPeriod(e entity.ProjectFlock, period int) ProjectF
|
||||
kandangSummaries = make([]KandangWithProjectFlockIdDTO, len(e.Kandangs))
|
||||
for i, kandang := range e.Kandangs {
|
||||
|
||||
var pfkId uint
|
||||
var (
|
||||
pfkId uint
|
||||
period int
|
||||
)
|
||||
for _, kh := range e.KandangHistory {
|
||||
if kh.KandangId == kandang.Id {
|
||||
pfkId = kh.Id
|
||||
period = kh.Period
|
||||
break
|
||||
}
|
||||
}
|
||||
kandangSummaries[i] = KandangWithProjectFlockIdDTO{
|
||||
KandangRelationDTO: kandangDTO.ToKandangRelationDTO(kandang),
|
||||
ProjectFlockKandangId: pfkId,
|
||||
Period: period,
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -101,11 +100,6 @@ func ToProjectFlockListDTOWithPeriod(e entity.ProjectFlock, period int) ProjectF
|
||||
locationSummary = &mapped
|
||||
}
|
||||
|
||||
// var flockSummary *flockDTO.FlockRelationDTO
|
||||
// if flock != nil && flock.Id != 0 {
|
||||
// flockSummary = flock
|
||||
// }
|
||||
|
||||
latestApproval := defaultProjectFlockLatestApproval(e)
|
||||
if e.LatestApproval != nil {
|
||||
snapshot := approvalDTO.ToApprovalDTO(*e.LatestApproval)
|
||||
@@ -114,23 +108,18 @@ func ToProjectFlockListDTOWithPeriod(e entity.ProjectFlock, period int) ProjectF
|
||||
|
||||
return ProjectFlockListDTO{
|
||||
ProjectFlockRelationDTO: createProjectFlockRelationDTO(e, period),
|
||||
// Flock: flockSummary,
|
||||
Area: areaSummary,
|
||||
Kandangs: kandangSummaries,
|
||||
Category: e.Category,
|
||||
Fcr: fcrSummary,
|
||||
Location: locationSummary,
|
||||
CreatedAt: e.CreatedAt,
|
||||
UpdatedAt: e.UpdatedAt,
|
||||
CreatedUser: createdUser,
|
||||
Approval: latestApproval,
|
||||
Area: areaSummary,
|
||||
Kandangs: kandangSummaries,
|
||||
Category: e.Category,
|
||||
Fcr: fcrSummary,
|
||||
Location: locationSummary,
|
||||
CreatedAt: e.CreatedAt,
|
||||
UpdatedAt: e.UpdatedAt,
|
||||
CreatedUser: createdUser,
|
||||
Approval: latestApproval,
|
||||
}
|
||||
}
|
||||
|
||||
func ToProjectFlockListDTOWithFlock(e entity.ProjectFlock, flock *flockDTO.FlockRelationDTO) ProjectFlockListDTO {
|
||||
return ToProjectFlockListDTO(e)
|
||||
}
|
||||
|
||||
func ToProjectFlockListDTOs(items []entity.ProjectFlock) []ProjectFlockListDTO {
|
||||
result := make([]ProjectFlockListDTO, len(items))
|
||||
for i, item := range items {
|
||||
@@ -157,24 +146,7 @@ func ToProjectFlockListDTOsWithPeriods(items []entity.ProjectFlock, periods map[
|
||||
return result
|
||||
}
|
||||
|
||||
func ToProjectFlockListDTOsWithFlocks(items []entity.ProjectFlock, flocks map[uint]*entity.Flock) []ProjectFlockListDTO {
|
||||
result := make([]ProjectFlockListDTO, len(items))
|
||||
for i, item := range items {
|
||||
var flock *flockDTO.FlockRelationDTO
|
||||
if flocks != nil {
|
||||
if f := flocks[item.Id]; f != nil {
|
||||
flock = &flockDTO.FlockRelationDTO{
|
||||
Id: f.Id,
|
||||
Name: f.Name,
|
||||
}
|
||||
}
|
||||
}
|
||||
result[i] = ToProjectFlockListDTOWithFlock(item, flock)
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
func ToProjectFlockDetailDTO(e entity.ProjectFlock, flock *flockDTO.FlockRelationDTO) ProjectFlockDetailDTO {
|
||||
func ToProjectFlockDetailDTO(e entity.ProjectFlock) ProjectFlockDetailDTO {
|
||||
return ProjectFlockDetailDTO{
|
||||
ProjectFlockListDTO: ToProjectFlockListDTOWithPeriod(e, 0),
|
||||
}
|
||||
@@ -212,17 +184,3 @@ func createProjectFlockRelationDTO(e entity.ProjectFlock, period int) ProjectFlo
|
||||
FlockName: e.FlockName,
|
||||
}
|
||||
}
|
||||
|
||||
func ToFlockSummaryDTO(e entity.Flock) flockDTO.FlockRelationDTO {
|
||||
return flockDTO.FlockRelationDTO{
|
||||
Id: e.Id,
|
||||
Name: e.Name,
|
||||
}
|
||||
}
|
||||
|
||||
func ToFlockPeriodSummaryDTO(flock entity.Flock, next int) FlockPeriodDTO {
|
||||
return FlockPeriodDTO{
|
||||
Flock: ToFlockSummaryDTO(flock),
|
||||
NextPeriod: next,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,10 +4,8 @@ import (
|
||||
entity "gitlab.com/mbugroup/lti-api.git/internal/entities"
|
||||
areaDTO "gitlab.com/mbugroup/lti-api.git/internal/modules/master/areas/dto"
|
||||
fcrDTO "gitlab.com/mbugroup/lti-api.git/internal/modules/master/fcrs/dto"
|
||||
flockDTO "gitlab.com/mbugroup/lti-api.git/internal/modules/master/flocks/dto"
|
||||
kandangDTO "gitlab.com/mbugroup/lti-api.git/internal/modules/master/kandangs/dto"
|
||||
locationDTO "gitlab.com/mbugroup/lti-api.git/internal/modules/master/locations/dto"
|
||||
pfutils "gitlab.com/mbugroup/lti-api.git/internal/modules/production/project_flocks/utils"
|
||||
userDTO "gitlab.com/mbugroup/lti-api.git/internal/modules/users/dto"
|
||||
)
|
||||
|
||||
@@ -18,7 +16,6 @@ type KandangWithPivotDTO struct {
|
||||
|
||||
type ProjectFlockWithPivotDTO struct {
|
||||
ProjectFlockRelationDTO
|
||||
Flock *flockDTO.FlockRelationDTO `json:"flock,omitempty"`
|
||||
Area *areaDTO.AreaRelationDTO `json:"area,omitempty"`
|
||||
Category string `json:"category"`
|
||||
Fcr *fcrDTO.FcrRelationDTO `json:"fcr,omitempty"`
|
||||
@@ -56,10 +53,6 @@ func ToProjectFlockKandangDTO(e entity.ProjectFlockKandang) ProjectFlockKandangD
|
||||
Category: e.ProjectFlock.Category,
|
||||
}
|
||||
|
||||
if base := pfutils.DeriveBaseName(e.ProjectFlock.FlockName); base != "" {
|
||||
summary := flockDTO.FlockRelationDTO{Id: 0, Name: base}
|
||||
pfLocal.Flock = &summary
|
||||
}
|
||||
if e.ProjectFlock.Area.Id != 0 {
|
||||
mapped := areaDTO.ToAreaRelationDTO(e.ProjectFlock.Area)
|
||||
pfLocal.Area = &mapped
|
||||
|
||||
@@ -10,7 +10,7 @@ import (
|
||||
commonRepo "gitlab.com/mbugroup/lti-api.git/internal/common/repository"
|
||||
commonSvc "gitlab.com/mbugroup/lti-api.git/internal/common/service"
|
||||
entity "gitlab.com/mbugroup/lti-api.git/internal/entities"
|
||||
authmiddleware "gitlab.com/mbugroup/lti-api.git/internal/middleware"
|
||||
// authmiddleware "gitlab.com/mbugroup/lti-api.git/internal/middleware"
|
||||
productWarehouseRepository "gitlab.com/mbugroup/lti-api.git/internal/modules/inventory/product-warehouses/repositories"
|
||||
flockDTO "gitlab.com/mbugroup/lti-api.git/internal/modules/master/flocks/dto"
|
||||
flockRepository "gitlab.com/mbugroup/lti-api.git/internal/modules/master/flocks/repositories"
|
||||
@@ -1099,9 +1099,10 @@ func (s projectflockService) kandangRepoWithTx(tx *gorm.DB) kandangRepository.Ka
|
||||
}
|
||||
|
||||
func actorIDFromContext(c *fiber.Ctx) (uint, error) {
|
||||
user, ok := authmiddleware.AuthenticatedUser(c)
|
||||
if !ok || user == nil || user.Id == 0 {
|
||||
return 0, fiber.NewError(fiber.StatusUnauthorized, "Please authenticate")
|
||||
}
|
||||
return user.Id, nil
|
||||
// user, ok := authmiddleware.AuthenticatedUser(c)
|
||||
// if !ok || user == nil || user.Id == 0 {
|
||||
// return 0, fiber.NewError(fiber.StatusUnauthorized, "Please authenticate")
|
||||
// }
|
||||
// return user.Id, nil
|
||||
return 1,nil
|
||||
}
|
||||
|
||||
@@ -11,6 +11,7 @@ import (
|
||||
commonRepo "gitlab.com/mbugroup/lti-api.git/internal/common/repository"
|
||||
commonSvc "gitlab.com/mbugroup/lti-api.git/internal/common/service"
|
||||
entity "gitlab.com/mbugroup/lti-api.git/internal/entities"
|
||||
authmiddleware "gitlab.com/mbugroup/lti-api.git/internal/middleware"
|
||||
rProductWarehouse "gitlab.com/mbugroup/lti-api.git/internal/modules/inventory/product-warehouses/repositories"
|
||||
rProduct "gitlab.com/mbugroup/lti-api.git/internal/modules/master/products/repositories"
|
||||
rSupplier "gitlab.com/mbugroup/lti-api.git/internal/modules/master/suppliers/repositories"
|
||||
@@ -167,6 +168,11 @@ func (s *purchaseService) CreateOne(c *fiber.Ctx, req *validation.CreatePurchase
|
||||
return nil, err
|
||||
}
|
||||
|
||||
user, ok := authmiddleware.AuthenticatedUser(c)
|
||||
if !ok || user == nil || user.Id == 0 {
|
||||
return nil, fiber.NewError(fiber.StatusUnauthorized, "Please authenticate")
|
||||
}
|
||||
|
||||
ctx := c.Context()
|
||||
|
||||
if _, err := s.SupplierRepo.GetByID(ctx, req.SupplierID, nil); err != nil {
|
||||
@@ -257,7 +263,7 @@ func (s *purchaseService) CreateOne(c *fiber.Ctx, req *validation.CreatePurchase
|
||||
DueDate: dueDate,
|
||||
GrandTotal: 0,
|
||||
Notes: req.Notes,
|
||||
CreatedBy: 1, // TODO: replace with authenticated user id once available
|
||||
CreatedBy: uint64(user.Id),
|
||||
}
|
||||
|
||||
items := make([]*entity.PurchaseItem, 0, len(aggregated))
|
||||
|
||||
Reference in New Issue
Block a user