feat: implement GetLineById method in InventoryRequestController and service, and update routes
Deploy Application / deploy (push) Successful in 20s Details

This commit is contained in:
Habib Fatkhul Rohman 2025-12-08 14:42:20 +07:00
parent a967158bac
commit 8317e10754
4 changed files with 47 additions and 0 deletions

View File

@ -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")

View File

@ -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 {

View File

@ -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)

View File

@ -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)