diff --git a/.DS_Store b/.DS_Store index 4c14efd8..e39247fd 100644 Binary files a/.DS_Store and b/.DS_Store differ diff --git a/internal/database/migrations/20251229125951_adjustment_standart_production_projectflock.down.sql b/internal/database/migrations/20251229125951_adjustment_standart_production_projectflock.down.sql new file mode 100644 index 00000000..7433c93d --- /dev/null +++ b/internal/database/migrations/20251229125951_adjustment_standart_production_projectflock.down.sql @@ -0,0 +1,7 @@ +DROP INDEX IF EXISTS idx_project_flocks_production_standard_id; + +ALTER TABLE project_flocks + DROP CONSTRAINT IF EXISTS fk_project_flocks_production_standard_id; + +ALTER TABLE project_flocks + DROP COLUMN IF EXISTS production_standard_id; diff --git a/internal/database/migrations/20251229125951_adjustment_standart_production_projectflock.up.sql b/internal/database/migrations/20251229125951_adjustment_standart_production_projectflock.up.sql new file mode 100644 index 00000000..f513c447 --- /dev/null +++ b/internal/database/migrations/20251229125951_adjustment_standart_production_projectflock.up.sql @@ -0,0 +1,15 @@ +-- Add production_standard_id to project_flocks +ALTER TABLE project_flocks + ADD COLUMN IF NOT EXISTS production_standard_id BIGINT; + +DO $$ +BEGIN + IF EXISTS (SELECT 1 FROM pg_tables WHERE tablename = 'production_standards') THEN + ALTER TABLE project_flocks + ADD CONSTRAINT fk_project_flocks_production_standard_id + FOREIGN KEY (production_standard_id) REFERENCES production_standards (id) ON DELETE RESTRICT ON UPDATE CASCADE; + END IF; +END $$; + +CREATE INDEX IF NOT EXISTS idx_project_flocks_production_standard_id + ON project_flocks (production_standard_id); diff --git a/internal/database/seed/seeder.go b/internal/database/seed/seeder.go index bb4090bb..1e51109c 100644 --- a/internal/database/seed/seeder.go +++ b/internal/database/seed/seeder.go @@ -962,12 +962,12 @@ func seedTransferStock(tx *gorm.DB) error { { StockTransferId: transfer.Id, ProductId: 1, - Quantity: 10, + // Quantity: 10, }, { StockTransferId: transfer.Id, ProductId: 2, - Quantity: 5, + // Quantity: 5, }, } for i := range details { diff --git a/internal/entities/projectflock.go b/internal/entities/projectflock.go index 0a92b54b..7243c9c4 100644 --- a/internal/entities/projectflock.go +++ b/internal/entities/projectflock.go @@ -12,6 +12,7 @@ type ProjectFlock struct { AreaId uint `gorm:"not null"` Category string `gorm:"type:varchar(20);not null"` FcrId uint `gorm:"not null"` + ProductionStandardId uint `gorm:"column:production_standard_id"` LocationId uint `gorm:"not null"` CreatedBy uint `gorm:"not null"` CreatedAt time.Time `gorm:"autoCreateTime"` @@ -20,6 +21,7 @@ type ProjectFlock struct { Area Area `gorm:"foreignKey:AreaId;references:Id"` Fcr Fcr `gorm:"foreignKey:FcrId;references:Id"` + ProductionStandard ProductionStandard `gorm:"foreignKey:ProductionStandardId;references:Id"` Location Location `gorm:"foreignKey:LocationId;references:Id"` CreatedUser User `gorm:"foreignKey:CreatedBy;references:Id"` Kandangs []Kandang `gorm:"many2many:project_flock_kandangs;joinTableForeignKey:project_flock_id;joinTableReferences:kandang_id" json:"kandangs,omitempty"` diff --git a/internal/middleware/auth.go b/internal/middleware/auth.go index a08d431b..a831c25b 100644 --- a/internal/middleware/auth.go +++ b/internal/middleware/auth.go @@ -104,12 +104,11 @@ func AuthenticatedUser(c *fiber.Ctx) (*entity.User, bool) { } func ActorIDFromContext(c *fiber.Ctx) (uint, error) { - // user, ok := AuthenticatedUser(c) - // if !ok || user == nil || user.Id == 0 { - // return 0, fiber.NewError(fiber.StatusUnauthorized, "Please authenticate") - // } - // return user.Id, nil - return 1, nil + user, ok := AuthenticatedUser(c) + if !ok || user == nil || user.Id == 0 { + return 0, fiber.NewError(fiber.StatusUnauthorized, "Please authenticate") + } + return user.Id, nil } // AuthDetails returns the full authentication context (token, claims, user). diff --git a/internal/middleware/permissions.go b/internal/middleware/permissions.go index 7a21262c..f0056149 100644 --- a/internal/middleware/permissions.go +++ b/internal/middleware/permissions.go @@ -162,8 +162,32 @@ const ( P_WarehousesCreateOne = "lti.master.warehouses.create" P_WarehousesUpdateOne = "lti.master.warehouses.update" P_WarehousesDeleteOne = "lti.master.warehouses.delete" + + P_Production_Standart_GetAll = "lti.master.production_standards.list" + P_Production_Standart_CreateOne = "lti.master.production_standards.create" + P_Production_Standart_GetOne = "lti.master.production_standards.detail" + P_Production_Standart_UpdateOne = "lti.master.production_standards.update" + P_Production_Standart_DeleteOne = "lti.master.production_standards.delete" ) +// finance +const ( + P_Finances_Initial_Balances_CreateOne = "lti.finance.initial_balances.create" + P_Finances_Initial_Balances_GetOne = "lti.finance.initial_balances.detail" + P_Finances_Initial_Balances_UpdateOne = "lti.finance.initial_balances.update" + + P_Finances_Injections_CreateOne = "lti.finance.injections.create" + P_Finances_Injections_GetOne = "lti.finance.injections.detail" + P_Finances_Injections_UpdateOne = "lti.finance.injections.update" + + P_Finances_Payments_CreateOne = "lti.finance.payments.create" + P_Finances_Payments_UpdateOne = "lti.finance.payments.update" + P_Finances_Payments_GetOne = "lti.finance.payments.detail" + + P_Finances_Transaction_GetAll = "lti.finance.transactions.list" + P_Finances_Transaction_GetOne = "lti.finance.transactions.detail" + P_Finances_Transaction_DeleteOne = "lti.finance.transactions.delete" +) const ( P_ChickinsCreateOne = "lti.production.chickins.create" P_ChickinsGetOne = "lti.production.chickins.detail" diff --git a/internal/modules/finance/initials/route.go b/internal/modules/finance/initials/route.go index 21232493..b216fd23 100644 --- a/internal/modules/finance/initials/route.go +++ b/internal/modules/finance/initials/route.go @@ -1,7 +1,7 @@ package initials import ( - // m "gitlab.com/mbugroup/lti-api.git/internal/middleware" + m "gitlab.com/mbugroup/lti-api.git/internal/middleware" controller "gitlab.com/mbugroup/lti-api.git/internal/modules/finance/initials/controllers" initial "gitlab.com/mbugroup/lti-api.git/internal/modules/finance/initials/services" user "gitlab.com/mbugroup/lti-api.git/internal/modules/users/services" @@ -13,9 +13,9 @@ func InitialRoutes(v1 fiber.Router, u user.UserService, s initial.InitialService ctrl := controller.NewInitialController(s) route := v1.Group("/initial-balances") - // route.Use(m.Auth(u)) + route.Use(m.Auth(u)) - route.Post("/", ctrl.CreateOne) - route.Get("/:id", ctrl.GetOne) - route.Patch("/:id", ctrl.UpdateOne) + route.Post("/",m.RequirePermissions(m.P_Finances_Initial_Balances_CreateOne), ctrl.CreateOne) + route.Get("/:id",m.RequirePermissions(m.P_Finances_Initial_Balances_GetOne), ctrl.GetOne) + route.Patch("/:id",m.RequirePermissions(m.P_Finances_Initial_Balances_UpdateOne), ctrl.UpdateOne) } diff --git a/internal/modules/finance/injections/route.go b/internal/modules/finance/injections/route.go index cb66ccb7..25d1047f 100644 --- a/internal/modules/finance/injections/route.go +++ b/internal/modules/finance/injections/route.go @@ -1,7 +1,7 @@ package injections import ( - // m "gitlab.com/mbugroup/lti-api.git/internal/middleware" + m "gitlab.com/mbugroup/lti-api.git/internal/middleware" controller "gitlab.com/mbugroup/lti-api.git/internal/modules/finance/injections/controllers" injection "gitlab.com/mbugroup/lti-api.git/internal/modules/finance/injections/services" user "gitlab.com/mbugroup/lti-api.git/internal/modules/users/services" @@ -13,9 +13,9 @@ func InjectionRoutes(v1 fiber.Router, u user.UserService, s injection.InjectionS ctrl := controller.NewInjectionController(s) route := v1.Group("/injections") - // route.Use(m.Auth(u)) + route.Use(m.Auth(u)) - route.Post("/", ctrl.CreateOne) - route.Get("/:id", ctrl.GetOne) - route.Patch("/:id", ctrl.UpdateOne) + route.Post("/", m.RequirePermissions(m.P_Finances_Injections_CreateOne), ctrl.CreateOne) + route.Get("/:id", m.RequirePermissions(m.P_Finances_Injections_GetOne), ctrl.GetOne) + route.Patch("/:id", m.RequirePermissions(m.P_Finances_Injections_UpdateOne), ctrl.UpdateOne) } diff --git a/internal/modules/finance/payments/route.go b/internal/modules/finance/payments/route.go index 4b0e8bd2..c5147fc0 100644 --- a/internal/modules/finance/payments/route.go +++ b/internal/modules/finance/payments/route.go @@ -1,7 +1,7 @@ package payments import ( - // m "gitlab.com/mbugroup/lti-api.git/internal/middleware" + m "gitlab.com/mbugroup/lti-api.git/internal/middleware" controller "gitlab.com/mbugroup/lti-api.git/internal/modules/finance/payments/controllers" payment "gitlab.com/mbugroup/lti-api.git/internal/modules/finance/payments/services" user "gitlab.com/mbugroup/lti-api.git/internal/modules/users/services" @@ -13,9 +13,9 @@ func PaymentRoutes(v1 fiber.Router, u user.UserService, s payment.PaymentService ctrl := controller.NewPaymentController(s) route := v1.Group("/payments") - // route.Use(m.Auth(u)) + route.Use(m.Auth(u)) - route.Post("/", ctrl.CreateOne) - route.Get("/:id", ctrl.GetOne) - route.Patch("/:id", ctrl.UpdateOne) + route.Post("/",m.RequirePermissions(m.P_Finances_Payments_CreateOne), ctrl.CreateOne) + route.Get("/:id",m.RequirePermissions(m.P_Finances_Payments_GetOne), ctrl.GetOne) + route.Patch("/:id",m.RequirePermissions(m.P_Finances_Payments_UpdateOne), ctrl.UpdateOne) } diff --git a/internal/modules/finance/transactions/route.go b/internal/modules/finance/transactions/route.go index d21f5441..17baa9e8 100644 --- a/internal/modules/finance/transactions/route.go +++ b/internal/modules/finance/transactions/route.go @@ -1,7 +1,7 @@ package transactions import ( - // m "gitlab.com/mbugroup/lti-api.git/internal/middleware" + m "gitlab.com/mbugroup/lti-api.git/internal/middleware" controller "gitlab.com/mbugroup/lti-api.git/internal/modules/finance/transactions/controllers" transaction "gitlab.com/mbugroup/lti-api.git/internal/modules/finance/transactions/services" user "gitlab.com/mbugroup/lti-api.git/internal/modules/users/services" @@ -13,9 +13,9 @@ func TransactionRoutes(v1 fiber.Router, u user.UserService, s transaction.Transa ctrl := controller.NewTransactionController(s) route := v1.Group("/transactions") - // route.Use(m.Auth(u)) + route.Use(m.Auth(u)) - route.Get("/", ctrl.GetAll) - route.Get("/:id", ctrl.GetOne) - route.Delete("/:id", ctrl.DeleteOne) + route.Get("/",m.RequirePermissions(m.P_Finances_Transaction_GetAll), ctrl.GetAll) + route.Get("/:id",m.RequirePermissions(m.P_Finances_Transaction_GetOne), ctrl.GetOne) + route.Delete("/:id",m.RequirePermissions(m.P_Finances_Transaction_DeleteOne), ctrl.DeleteOne) } diff --git a/internal/modules/master/production-standards/controllers/production-standard.controller.go b/internal/modules/master/production-standards/controllers/production-standard.controller.go index 1635385d..d7794e41 100644 --- a/internal/modules/master/production-standards/controllers/production-standard.controller.go +++ b/internal/modules/master/production-standards/controllers/production-standard.controller.go @@ -40,7 +40,7 @@ func (u *ProductionStandardController) GetAll(c *fiber.Ctx) error { } return c.Status(fiber.StatusOK). - JSON(response.SuccessWithPaginate[dto.ProductionStandardListDTO]{ + JSON(response.SuccessWithPaginate[dto.ProductionStandardRelationDTO]{ Code: fiber.StatusOK, Status: "success", Message: "Get all productionStandards successfully", diff --git a/internal/modules/master/production-standards/dto/production-standard.dto.go b/internal/modules/master/production-standards/dto/production-standard.dto.go index 9544732a..0f55b5b3 100644 --- a/internal/modules/master/production-standards/dto/production-standard.dto.go +++ b/internal/modules/master/production-standards/dto/production-standard.dto.go @@ -7,7 +7,7 @@ import ( // === DTO Structs === -type ProductionStandardListDTO struct { +type ProductionStandardRelationDTO struct { Id uint `json:"id"` Name string `json:"name"` ProjectCategory string `json:"project_category"` @@ -15,7 +15,7 @@ type ProductionStandardListDTO struct { } type ProductionStandardDetailDTO struct { - ProductionStandardListDTO + ProductionStandardRelationDTO Details []WeeklyProductionStandardDTO `json:"details"` } @@ -43,14 +43,14 @@ type WeeklyProductionStandardDTO struct { // === Mapper Functions === -func ToProductionStandardListDTO(e entity.ProductionStandard) ProductionStandardListDTO { +func ToProductionStandardListDTO(e entity.ProductionStandard) ProductionStandardRelationDTO { var createdUser *userDTO.UserRelationDTO if e.CreatedUser.Id != 0 { mapped := userDTO.ToUserRelationDTO(e.CreatedUser) createdUser = &mapped } - return ProductionStandardListDTO{ + return ProductionStandardRelationDTO{ Id: e.Id, Name: e.Name, ProjectCategory: e.ProjectCategory, @@ -58,8 +58,16 @@ func ToProductionStandardListDTO(e entity.ProductionStandard) ProductionStandard } } -func ToProductionStandardListDTOs(e []entity.ProductionStandard) []ProductionStandardListDTO { - result := make([]ProductionStandardListDTO, len(e)) +func ToProductionStandardRelationDTO(e entity.ProductionStandard) ProductionStandardRelationDTO { + return ProductionStandardRelationDTO{ + Id: e.Id, + Name: e.Name, + ProjectCategory: e.ProjectCategory, + } +} + +func ToProductionStandardListDTOs(e []entity.ProductionStandard) []ProductionStandardRelationDTO { + result := make([]ProductionStandardRelationDTO, len(e)) for i, r := range e { result[i] = ToProductionStandardListDTO(r) } @@ -149,7 +157,7 @@ func ToProductionStandardDetailDTO( productionStandardDetails []entity.ProductionStandardDetail, ) ProductionStandardDetailDTO { return ProductionStandardDetailDTO{ - ProductionStandardListDTO: ToProductionStandardListDTO(standard), + ProductionStandardRelationDTO: ToProductionStandardRelationDTO(standard), Details: ToWeeklyProductionStandardDTOsWithDetails(growthDetails, productionStandardDetails), } } diff --git a/internal/modules/master/production-standards/route.go b/internal/modules/master/production-standards/route.go index d2035bea..e0296fd3 100644 --- a/internal/modules/master/production-standards/route.go +++ b/internal/modules/master/production-standards/route.go @@ -15,9 +15,9 @@ func ProductionStandardRoutes(v1 fiber.Router, u user.UserService, s productionS route := v1.Group("/production-standards") route.Use(m.Auth(u)) - route.Get("/", ctrl.GetAll) - route.Post("/", ctrl.CreateOne) - route.Get("/:id", ctrl.GetOne) - route.Patch("/:id", ctrl.UpdateOne) - route.Delete("/:id", ctrl.DeleteOne) + route.Get("/", m.RequirePermissions(m.P_Production_Standart_GetAll), ctrl.GetAll) + route.Post("/", m.RequirePermissions(m.P_Production_Standart_CreateOne), ctrl.CreateOne) + route.Get("/:id", m.RequirePermissions(m.P_Production_Standart_GetOne), ctrl.GetOne) + route.Patch("/:id", m.RequirePermissions(m.P_Production_Standart_UpdateOne), ctrl.UpdateOne) + route.Delete("/:id", m.RequirePermissions(m.P_Production_Standart_DeleteOne), ctrl.DeleteOne) } diff --git a/internal/modules/production/project-flock-kandangs/dto/project_flock_kandang.dto.go b/internal/modules/production/project-flock-kandangs/dto/project_flock_kandang.dto.go index 677f527b..a2ba8ad2 100644 --- a/internal/modules/production/project-flock-kandangs/dto/project_flock_kandang.dto.go +++ b/internal/modules/production/project-flock-kandangs/dto/project_flock_kandang.dto.go @@ -10,6 +10,7 @@ import ( fcrDTO "gitlab.com/mbugroup/lti-api.git/internal/modules/master/fcrs/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" + productionStandardDTO "gitlab.com/mbugroup/lti-api.git/internal/modules/master/production-standards/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" chickinDTO "gitlab.com/mbugroup/lti-api.git/internal/modules/production/chickins/dto" @@ -30,6 +31,7 @@ type ProjectFlockDTO struct { Area *areaDTO.AreaRelationDTO `json:"area,omitempty"` Category string `json:"category"` Fcr *fcrDTO.FcrRelationDTO `json:"fcr,omitempty"` + ProductionStandard *productionStandardDTO.ProductionStandardRelationDTO `json:"production_standard,omitempty"` Location *locationDTO.LocationRelationDTO `json:"location,omitempty"` CreatedUser *userDTO.UserRelationDTO `json:"created_user,omitempty"` CreatedAt time.Time `json:"created_at"` @@ -82,6 +84,7 @@ func toProjectFlockDTO(pf *projectFlockDTO.ProjectFlockListDTO) *ProjectFlockDTO Area: pf.Area, Category: pf.Category, Fcr: pf.Fcr, + ProductionStandard: pf.ProductionStandard, Location: pf.Location, CreatedUser: pf.CreatedUser, CreatedAt: pf.CreatedAt, diff --git a/internal/modules/production/project_flocks/dto/projectflock.dto.go b/internal/modules/production/project_flocks/dto/projectflock.dto.go index 0922b160..504d439c 100644 --- a/internal/modules/production/project_flocks/dto/projectflock.dto.go +++ b/internal/modules/production/project_flocks/dto/projectflock.dto.go @@ -10,6 +10,7 @@ import ( kandangDTO "gitlab.com/mbugroup/lti-api.git/internal/modules/master/kandangs/dto" locationDTO "gitlab.com/mbugroup/lti-api.git/internal/modules/master/locations/dto" nonstockDTO "gitlab.com/mbugroup/lti-api.git/internal/modules/master/nonstocks/dto" + productionStandardDTO "gitlab.com/mbugroup/lti-api.git/internal/modules/master/production-standards/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" @@ -28,6 +29,7 @@ type ProjectFlockListDTO struct { Area *areaDTO.AreaRelationDTO `json:"area,omitempty"` Category string `json:"category"` Fcr *fcrDTO.FcrRelationDTO `json:"fcr,omitempty"` + ProductionStandard *productionStandardDTO.ProductionStandardRelationDTO `json:"production_standard,omitempty"` Location *locationDTO.LocationRelationDTO `json:"location,omitempty"` Kandangs []KandangWithProjectFlockIdDTO `json:"kandangs,omitempty"` ProjectBudgets []ProjectBudgetDTO `json:"project_budgets,omitempty"` @@ -103,6 +105,12 @@ func ToProjectFlockListDTOWithPeriod(e entity.ProjectFlock, period int) ProjectF fcrSummary = &mapped } + var productionStandardSummary *productionStandardDTO.ProductionStandardRelationDTO + if e.ProductionStandard.Id != 0 { + mapped := productionStandardDTO.ToProductionStandardRelationDTO(e.ProductionStandard) + productionStandardSummary = &mapped + } + var locationSummary *locationDTO.LocationRelationDTO if e.Location.Id != 0 { mapped := locationDTO.ToLocationRelationDTO(e.Location) @@ -122,6 +130,7 @@ func ToProjectFlockListDTOWithPeriod(e entity.ProjectFlock, period int) ProjectF ProjectBudgets: ToProjectBudgetDTOs(e.Budgets), Category: e.Category, Fcr: fcrSummary, + ProductionStandard: productionStandardSummary, Location: locationSummary, CreatedAt: e.CreatedAt, UpdatedAt: e.UpdatedAt, diff --git a/internal/modules/production/project_flocks/dto/projectflock_kandang.dto.go b/internal/modules/production/project_flocks/dto/projectflock_kandang.dto.go index d5ed5a46..d1f0d40b 100644 --- a/internal/modules/production/project_flocks/dto/projectflock_kandang.dto.go +++ b/internal/modules/production/project_flocks/dto/projectflock_kandang.dto.go @@ -6,6 +6,7 @@ import ( fcrDTO "gitlab.com/mbugroup/lti-api.git/internal/modules/master/fcrs/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" + productionStandardDTO "gitlab.com/mbugroup/lti-api.git/internal/modules/master/production-standards/dto" userDTO "gitlab.com/mbugroup/lti-api.git/internal/modules/users/dto" ) @@ -19,6 +20,7 @@ type ProjectFlockWithPivotDTO struct { Area *areaDTO.AreaRelationDTO `json:"area,omitempty"` Category string `json:"category"` Fcr *fcrDTO.FcrRelationDTO `json:"fcr,omitempty"` + ProductionStandard *productionStandardDTO.ProductionStandardRelationDTO `json:"production_standard,omitempty"` Location *locationDTO.LocationRelationDTO `json:"location,omitempty"` Kandangs []KandangWithPivotDTO `json:"kandangs,omitempty"` CreatedUser *userDTO.UserRelationDTO `json:"created_user,omitempty"` @@ -61,6 +63,10 @@ func ToProjectFlockKandangDTO(e entity.ProjectFlockKandang) ProjectFlockKandangD mapped := fcrDTO.ToFcrRelationDTO(e.ProjectFlock.Fcr) pfLocal.Fcr = &mapped } + if e.ProjectFlock.ProductionStandard.Id != 0 { + mapped := productionStandardDTO.ToProductionStandardRelationDTO(e.ProjectFlock.ProductionStandard) + pfLocal.ProductionStandard = &mapped + } if e.ProjectFlock.Location.Id != 0 { mapped := locationDTO.ToLocationRelationDTO(e.ProjectFlock.Location) pfLocal.Location = &mapped diff --git a/internal/modules/production/project_flocks/repositories/projectflock.repository.go b/internal/modules/production/project_flocks/repositories/projectflock.repository.go index 4af5cbcd..6cd98a8f 100644 --- a/internal/modules/production/project_flocks/repositories/projectflock.repository.go +++ b/internal/modules/production/project_flocks/repositories/projectflock.repository.go @@ -22,6 +22,7 @@ type ProjectflockRepository interface { GetActiveByLocationID(ctx context.Context, locationID uint64) ([]entity.ProjectFlock, error) AreaExists(ctx context.Context, id uint) (bool, error) FcrExists(ctx context.Context, id uint) (bool, error) + ProductionStandardExists(ctx context.Context, id uint) (bool, error) LocationExists(ctx context.Context, id uint) (bool, error) } type KandangPeriodRow struct { @@ -52,6 +53,7 @@ func (r *ProjectflockRepositoryImpl) WithDefaultRelations() func(*gorm.DB) *gorm Preload("CreatedUser"). Preload("Area"). Preload("Fcr"). + Preload("ProductionStandard"). Preload("Location"). Preload("Kandangs"). Preload("KandangHistory"). @@ -118,12 +120,14 @@ func (r *ProjectflockRepositoryImpl) applySearchFilters(db *gorm.DB, rawSearch s return db. Joins("LEFT JOIN areas ON areas.id = project_flocks.area_id"). Joins("LEFT JOIN fcrs ON fcrs.id = project_flocks.fcr_id"). + Joins("LEFT JOIN production_standards ON production_standards.id = project_flocks.production_standard_id"). Joins("LEFT JOIN locations ON locations.id = project_flocks.location_id"). Joins("LEFT JOIN users AS created_users ON created_users.id = project_flocks.created_by"). Where(` LOWER(areas.name) LIKE ? OR LOWER(project_flocks.category) LIKE ? OR LOWER(fcrs.name) LIKE ? + OR LOWER(production_standards.name) LIKE ? OR LOWER(locations.name) LIKE ? OR LOWER(locations.address) LIKE ? OR LOWER(created_users.name) LIKE ? @@ -153,6 +157,7 @@ func (r *ProjectflockRepositoryImpl) applySearchFilters(db *gorm.DB, rawSearch s likeQuery, likeQuery, likeQuery, + likeQuery, ) } @@ -164,6 +169,10 @@ func (r *ProjectflockRepositoryImpl) FcrExists(ctx context.Context, id uint) (bo return repository.Exists[entity.Fcr](ctx, r.DB(), id) } +func (r *ProjectflockRepositoryImpl) ProductionStandardExists(ctx context.Context, id uint) (bool, error) { + return repository.Exists[entity.ProductionStandard](ctx, r.DB(), id) +} + func (r *ProjectflockRepositoryImpl) LocationExists(ctx context.Context, id uint) (bool, error) { return repository.Exists[entity.Location](ctx, r.DB(), id) } diff --git a/internal/modules/production/project_flocks/services/projectflock.service.go b/internal/modules/production/project_flocks/services/projectflock.service.go index 62e1d389..9431729f 100644 --- a/internal/modules/production/project_flocks/services/projectflock.service.go +++ b/internal/modules/production/project_flocks/services/projectflock.service.go @@ -249,6 +249,7 @@ func (s *projectflockService) CreateOne(c *fiber.Ctx, req *validation.Create) (* if err := commonSvc.EnsureRelations(c.Context(), commonSvc.RelationCheck{Name: "Area", ID: &req.AreaId, Exists: s.Repository.AreaExists}, commonSvc.RelationCheck{Name: "FCR", ID: &req.FcrId, Exists: s.Repository.FcrExists}, + commonSvc.RelationCheck{Name: "Production Standard", ID: &req.ProductionStandardId, Exists: s.Repository.ProductionStandardExists}, commonSvc.RelationCheck{Name: "Location", ID: &req.LocationId, Exists: s.Repository.LocationExists}, ); err != nil { return nil, err @@ -300,6 +301,7 @@ func (s *projectflockService) CreateOne(c *fiber.Ctx, req *validation.Create) (* AreaId: req.AreaId, Category: cat, FcrId: req.FcrId, + ProductionStandardId: req.ProductionStandardId, LocationId: req.LocationId, CreatedBy: actorID, } diff --git a/internal/modules/production/project_flocks/validations/projectflock.validation.go b/internal/modules/production/project_flocks/validations/projectflock.validation.go index 66045dc1..2e938041 100644 --- a/internal/modules/production/project_flocks/validations/projectflock.validation.go +++ b/internal/modules/production/project_flocks/validations/projectflock.validation.go @@ -5,6 +5,7 @@ type Create struct { AreaId uint `json:"area_id" validate:"required_strict,number,gt=0"` Category string `json:"category" validate:"required_strict"` FcrId uint `json:"fcr_id" validate:"required_strict,number,gt=0"` + ProductionStandardId uint `json:"production_standard_id" validate:"required_strict,number,gt=0"` LocationId uint `json:"location_id" validate:"required_strict,number,gt=0"` KandangIds []uint `json:"kandang_ids" validate:"required,min=1,dive,gt=0"` ProjectBudgets []ProjectBudget `json:"project_budgets" validate:"required,min=1,dive"`