mirror of
https://gitlab.com/mbugroup/lti-api.git
synced 2026-05-23 23:05:44 +00:00
FIX[BE]: name duplicate flock,projectflock category change,menerapkan dto seperti warehouse di projectflock
This commit is contained in:
@@ -5,7 +5,6 @@ import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
commonRepo "gitlab.com/mbugroup/lti-api.git/internal/common/repository"
|
||||
common "gitlab.com/mbugroup/lti-api.git/internal/common/service"
|
||||
@@ -242,7 +241,7 @@ func (s *projectflockService) CreateOne(c *fiber.Ctx, req *validation.Create) (*
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if err := s.attachKandangs(c.Context(), tx, createBody.Id, kandangIDs, createBody.CreatedBy); err != nil {
|
||||
if err := s.attachKandangs(c.Context(), tx, createBody.Id, kandangIDs); err != nil {
|
||||
tx.Rollback()
|
||||
s.Log.Errorf("Failed to attach kandangs to projectflock %d: %+v", createBody.Id, err)
|
||||
return nil, err
|
||||
@@ -395,7 +394,7 @@ func (s projectflockService) UpdateOne(c *fiber.Ctx, req *validation.Update, id
|
||||
}
|
||||
|
||||
if len(toAttach) > 0 {
|
||||
if err := s.attachKandangs(c.Context(), tx, id, toAttach, existing.CreatedBy); err != nil {
|
||||
if err := s.attachKandangs(c.Context(), tx, id, toAttach); err != nil {
|
||||
tx.Rollback()
|
||||
s.Log.Errorf("Failed to attach kandangs to projectflock %d: %+v", id, err)
|
||||
return nil, err
|
||||
@@ -533,7 +532,7 @@ func (s projectflockService) buildOrderExpressions(sortBy, sortOrder string) []s
|
||||
}
|
||||
}
|
||||
|
||||
func (s projectflockService) attachKandangs(ctx context.Context, tx *gorm.DB, projectFlockID uint, kandangIDs []uint, createdBy uint) error {
|
||||
func (s projectflockService) attachKandangs(ctx context.Context, tx *gorm.DB, projectFlockID uint, kandangIDs []uint) error {
|
||||
if len(kandangIDs) == 0 {
|
||||
return nil
|
||||
}
|
||||
@@ -553,7 +552,6 @@ func (s projectflockService) attachKandangs(ctx context.Context, tx *gorm.DB, pr
|
||||
records[i] = &entity.ProjectFlockKandang{
|
||||
ProjectFlockId: projectFlockID,
|
||||
KandangId: id,
|
||||
CreatedBy: createdBy,
|
||||
}
|
||||
}
|
||||
if err := pivotRepo.CreateMany(ctx, records); err != nil {
|
||||
@@ -578,7 +576,7 @@ func (s projectflockService) detachKandangs(ctx context.Context, tx *gorm.DB, pr
|
||||
return fiber.NewError(fiber.StatusInternalServerError, "Failed to update kandangs")
|
||||
}
|
||||
|
||||
if err := s.pivotRepoWithTx(tx).MarkDetached(ctx, projectFlockID, kandangIDs, time.Now()); err != nil {
|
||||
if err := s.pivotRepoWithTx(tx).DeleteMany(ctx, projectFlockID, kandangIDs); err != nil {
|
||||
return fiber.NewError(fiber.StatusInternalServerError, "Failed to persist project flock history")
|
||||
}
|
||||
return nil
|
||||
|
||||
Reference in New Issue
Block a user