From 8317e107545d59c87f35deff78753cdca25bc5ee Mon Sep 17 00:00:00 2001 From: Habib Fatkhul Rohman Date: Mon, 8 Dec 2025 14:42:20 +0700 Subject: [PATCH] feat: implement GetLineById method in InventoryRequestController and service, and update routes --- .../inventory_request_controller.go | 14 ++++++++++++ .../dto/inventory_request_dto.go | 22 +++++++++++++++++++ modules/inventory_request/routes.go | 1 + .../service/inventory_request_service.go | 10 +++++++++ 4 files changed, 47 insertions(+) diff --git a/modules/inventory_request/controller/inventory_request_controller.go b/modules/inventory_request/controller/inventory_request_controller.go index 19dc876..add1c08 100644 --- a/modules/inventory_request/controller/inventory_request_controller.go +++ b/modules/inventory_request/controller/inventory_request_controller.go @@ -20,6 +20,7 @@ type InventoryRequestController interface { GetById(ctx *gin.Context) GetAll(ctx *gin.Context) GetLinesByRequestId(ctx *gin.Context) + GetLineById(ctx *gin.Context) CreateLine(ctx *gin.Context) UpdateLine(ctx *gin.Context) DeleteLine(ctx *gin.Context) @@ -30,6 +31,19 @@ type inventoryRequestController struct { db *gorm.DB } +// GetLineById implements InventoryRequestController. +func (c *inventoryRequestController) GetLineById(ctx *gin.Context) { + id := ctx.Param("id") + line, err := c.requestService.GetLineById(ctx, id) + if err != nil { + res := utils.BuildResponseFailed(dto.MESSAGE_FAILED_GET_INVENTORY_REQUEST_LINE, err.Error(), nil) + ctx.JSON(http.StatusInternalServerError, res) + return + } + res := utils.BuildResponseSuccess(dto.MESSAGE_SUCCESS_GET_INVENTORY_REQUEST_LINE, line) + ctx.JSON(http.StatusOK, res) +} + // GetLinesByRequestId implements InventoryRequestController. func (c *inventoryRequestController) GetLinesByRequestId(ctx *gin.Context) { id := ctx.Param("id") diff --git a/modules/inventory_request/dto/inventory_request_dto.go b/modules/inventory_request/dto/inventory_request_dto.go index 63d6213..314596d 100644 --- a/modules/inventory_request/dto/inventory_request_dto.go +++ b/modules/inventory_request/dto/inventory_request_dto.go @@ -172,6 +172,28 @@ func ToInventoryRequestResponse(e entities.TInventoryRequestEntity) InventoryReq } } +func ToInventoryRequestLineResponse(e entities.TInventoryRequestLineEntity) InventoryRequestLineResponse { + product := InventoryRequestLineProductResponse{} + if e.Product.ID != uuid.Nil { + product = InventoryRequestLineProductResponse{ + ID: e.Product.ID.String(), + Name: e.Product.Name, + RefNumber: e.Product.RefNumber, + Uom: pkgdto.IdNameResponse{ + ID: e.Product.Uom.ID.String(), + Name: e.Product.Uom.Name, + }, + } + } + return InventoryRequestLineResponse{ + ID: e.ID.String(), + Quantity: e.Quantity, + // CurrentStock: e.CurrentStock, + Product: product, + ClientID: e.ClientID.String(), + } +} + func ToInventoryRequestLineResponses(linesEntity []entities.TInventoryRequestLineEntity) []InventoryRequestLineResponse { lines := make([]InventoryRequestLineResponse, 0) for _, line := range linesEntity { diff --git a/modules/inventory_request/routes.go b/modules/inventory_request/routes.go index a0c2e3f..8bdac67 100644 --- a/modules/inventory_request/routes.go +++ b/modules/inventory_request/routes.go @@ -21,6 +21,7 @@ func RegisterRoutes(server *gin.Engine, injector *do.Injector) { requestRoutes.DELETE(":id", middlewares.Authenticate(jwtService), requestController.Delete) requestRoutes.GET("", middlewares.Authenticate(jwtService), requestController.GetAll) requestRoutes.GET(":id/lines", middlewares.Authenticate(jwtService), requestController.GetLinesByRequestId) + requestRoutes.GET("lines/:id", middlewares.Authenticate(jwtService), requestController.GetLineById) requestRoutes.POST(":id/lines", middlewares.Authenticate(jwtService), requestController.CreateLine) requestRoutes.PUT("lines/:id", middlewares.Authenticate(jwtService), requestController.UpdateLine) requestRoutes.DELETE("lines/:id", middlewares.Authenticate(jwtService), requestController.DeleteLine) diff --git a/modules/inventory_request/service/inventory_request_service.go b/modules/inventory_request/service/inventory_request_service.go index 442fbb9..1c6595a 100644 --- a/modules/inventory_request/service/inventory_request_service.go +++ b/modules/inventory_request/service/inventory_request_service.go @@ -23,6 +23,7 @@ type InventoryRequestService interface { Update(ctx context.Context, req dtodomain.InventoryRequestUpdateRequest, id string) (dtodomain.InventoryRequestResponse, error) Delete(ctx context.Context, id string) error GetLinesByRequestId(ctx context.Context, requestId string) ([]dtodomain.InventoryRequestLineResponse, error) + GetLineById(ctx context.Context, lineId string) (dtodomain.InventoryRequestLineResponse, error) CreateLine(ctx context.Context, requestId string, req dtodomain.InventoryRequestLineCreateRequest) (dtodomain.InventoryRequestLineResponse, error) UpdateLine(ctx context.Context, lineId string, req dtodomain.InventoryRequestLineUpdateRequest) (dtodomain.InventoryRequestLineResponse, error) DeleteLine(ctx context.Context, lineId string) error @@ -36,6 +37,15 @@ type inventoryRequestService struct { log *logrus.Logger } +// GetLineById implements InventoryRequestService. +func (s *inventoryRequestService) GetLineById(ctx context.Context, lineId string) (dtodomain.InventoryRequestLineResponse, error) { + line, err := s.requestLineRepo.GetById(ctx, nil, lineId) + if err != nil { + return dtodomain.InventoryRequestLineResponse{}, err + } + return dtodomain.ToInventoryRequestLineResponse(line), nil +} + // GetLinesByRequestId implements InventoryRequestService. func (s *inventoryRequestService) GetLinesByRequestId(ctx context.Context, requestId string) ([]dtodomain.InventoryRequestLineResponse, error) { lines, err := s.requestLineRepo.GetAllByRequestId(ctx, requestId)