mirror of
https://gitlab.com/mbugroup/lti-api.git
synced 2026-05-20 13:31:56 +00:00
refactor: unify GetOne method to return approval alongside transfer laying
This commit is contained in:
+1
-1
@@ -70,7 +70,7 @@ func (u *TransferLayingController) GetOne(c *fiber.Ctx) error {
|
|||||||
return fiber.NewError(fiber.StatusBadRequest, "Invalid Id")
|
return fiber.NewError(fiber.StatusBadRequest, "Invalid Id")
|
||||||
}
|
}
|
||||||
|
|
||||||
result, approval, err := u.TransferLayingService.GetOneWithApproval(c, uint(id))
|
result, approval, err := u.TransferLayingService.GetOne(c, uint(id))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -28,8 +28,7 @@ import (
|
|||||||
|
|
||||||
type TransferLayingService interface {
|
type TransferLayingService interface {
|
||||||
GetAll(ctx *fiber.Ctx, params *validation.Query) ([]entity.LayingTransfer, int64, error)
|
GetAll(ctx *fiber.Ctx, params *validation.Query) ([]entity.LayingTransfer, int64, error)
|
||||||
GetOne(ctx *fiber.Ctx, id uint) (*entity.LayingTransfer, error)
|
GetOne(ctx *fiber.Ctx, id uint) (*entity.LayingTransfer, *entity.Approval, error)
|
||||||
GetOneWithApproval(ctx *fiber.Ctx, id uint) (*entity.LayingTransfer, *entity.Approval, error)
|
|
||||||
CreateOne(ctx *fiber.Ctx, req *validation.Create) (*entity.LayingTransfer, error)
|
CreateOne(ctx *fiber.Ctx, req *validation.Create) (*entity.LayingTransfer, error)
|
||||||
UpdateOne(ctx *fiber.Ctx, req *validation.Update, id uint) (*entity.LayingTransfer, error)
|
UpdateOne(ctx *fiber.Ctx, req *validation.Update, id uint) (*entity.LayingTransfer, error)
|
||||||
DeleteOne(ctx *fiber.Ctx, id uint) error
|
DeleteOne(ctx *fiber.Ctx, id uint) error
|
||||||
@@ -156,14 +155,15 @@ func (s transferLayingService) GetAll(c *fiber.Ctx, params *validation.Query) ([
|
|||||||
return transferLayings, total, nil
|
return transferLayings, total, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s transferLayingService) GetOne(c *fiber.Ctx, id uint) (*entity.LayingTransfer, error) {
|
func (s transferLayingService) GetOne(c *fiber.Ctx, id uint) (*entity.LayingTransfer, *entity.Approval, error) {
|
||||||
transferLaying, err := s.Repository.GetByID(c.Context(), id, s.withRelations)
|
transferLaying, err := s.Repository.GetByID(c.Context(), id, s.withRelations)
|
||||||
|
|
||||||
if errors.Is(err, gorm.ErrRecordNotFound) {
|
if errors.Is(err, gorm.ErrRecordNotFound) {
|
||||||
return nil, fiber.NewError(fiber.StatusNotFound, "TransferLaying not found")
|
return nil, nil, fiber.NewError(fiber.StatusNotFound, "TransferLaying not found")
|
||||||
}
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
s.Log.Errorf("Failed get transferLaying by id: %+v", err)
|
s.Log.Errorf("Failed get transferLaying by id: %+v", err)
|
||||||
return nil, err
|
return nil, nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
approvalRepo := commonRepo.NewApprovalRepository(s.Repository.DB())
|
approvalRepo := commonRepo.NewApprovalRepository(s.Repository.DB())
|
||||||
@@ -174,15 +174,6 @@ func (s transferLayingService) GetOne(c *fiber.Ctx, id uint) (*entity.LayingTran
|
|||||||
transferLaying.LatestApproval = latestApproval
|
transferLaying.LatestApproval = latestApproval
|
||||||
}
|
}
|
||||||
|
|
||||||
return transferLaying, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s transferLayingService) GetOneWithApproval(c *fiber.Ctx, id uint) (*entity.LayingTransfer, *entity.Approval, error) {
|
|
||||||
transferLaying, err := s.GetOne(c, id)
|
|
||||||
if err != nil {
|
|
||||||
return nil, nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
return transferLaying, transferLaying.LatestApproval, nil
|
return transferLaying, transferLaying.LatestApproval, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -406,7 +397,12 @@ func (s *transferLayingService) CreateOne(c *fiber.Ctx, req *validation.Create)
|
|||||||
return nil, fiber.NewError(fiber.StatusInternalServerError, "Gagal membuat transfer laying")
|
return nil, fiber.NewError(fiber.StatusInternalServerError, "Gagal membuat transfer laying")
|
||||||
}
|
}
|
||||||
|
|
||||||
return s.GetOne(c, createBody.Id)
|
laying_transfer, _, err := s.GetOne(c, createBody.Id)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return laying_transfer, nil
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *transferLayingService) UpdateOne(c *fiber.Ctx, req *validation.Update, id uint) (*entity.LayingTransfer, error) {
|
func (s *transferLayingService) UpdateOne(c *fiber.Ctx, req *validation.Update, id uint) (*entity.LayingTransfer, error) {
|
||||||
@@ -582,7 +578,9 @@ func (s *transferLayingService) UpdateOne(c *fiber.Ctx, req *validation.Update,
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
return s.GetOne(c, id)
|
layingTransfer, _, err := s.GetOne(c, id)
|
||||||
|
|
||||||
|
return layingTransfer, err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s transferLayingService) DeleteOne(c *fiber.Ctx, id uint) error {
|
func (s transferLayingService) DeleteOne(c *fiber.Ctx, id uint) error {
|
||||||
@@ -773,7 +771,7 @@ func (s transferLayingService) Approval(c *fiber.Ctx, req *validation.Approve) (
|
|||||||
|
|
||||||
updated := make([]entity.LayingTransfer, 0, len(approvableIDs))
|
updated := make([]entity.LayingTransfer, 0, len(approvableIDs))
|
||||||
for _, approvableID := range approvableIDs {
|
for _, approvableID := range approvableIDs {
|
||||||
transfer, err := s.GetOne(c, approvableID)
|
transfer, _, err := s.GetOne(c, approvableID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user