feat: add GetLinesByReturnId method to InventoryReturnController and service for retrieving return lines
Deploy Application / deploy (push) Successful in 30s
Details
Deploy Application / deploy (push) Successful in 30s
Details
This commit is contained in:
parent
3dd7e60827
commit
b9c987a04b
|
|
@ -17,6 +17,7 @@ type InventoryReturnController interface {
|
|||
Delete(ctx *gin.Context)
|
||||
GetById(ctx *gin.Context)
|
||||
GetAll(ctx *gin.Context)
|
||||
GetLinesByReturnId(ctx *gin.Context)
|
||||
CreateLine(ctx *gin.Context)
|
||||
UpdateLine(ctx *gin.Context)
|
||||
DeleteLine(ctx *gin.Context)
|
||||
|
|
@ -26,6 +27,18 @@ type inventoryReturnController struct {
|
|||
returnService service.InventoryReturnService
|
||||
}
|
||||
|
||||
func (c *inventoryReturnController) GetLinesByReturnId(ctx *gin.Context) {
|
||||
returnId := ctx.Param("id")
|
||||
lines, err := c.returnService.GetLinesByReturnId(ctx, returnId)
|
||||
if err != nil {
|
||||
res := utils.BuildResponseFailed(dto.MESSAGE_FAILED_GET_INVENTORY_RETURN_LINE, err.Error(), nil)
|
||||
ctx.JSON(http.StatusInternalServerError, res)
|
||||
return
|
||||
}
|
||||
res := utils.BuildResponseSuccess(dto.MESSAGE_SUCCESS_GET_INVENTORY_RETURN_LINE, lines)
|
||||
ctx.JSON(http.StatusOK, res)
|
||||
}
|
||||
|
||||
// DeleteLine implements InventoryReturnController.
|
||||
func (c *inventoryReturnController) DeleteLine(ctx *gin.Context) {
|
||||
id := ctx.Param("id")
|
||||
|
|
|
|||
|
|
@ -23,6 +23,8 @@ const (
|
|||
MESSAGE_SUCCESS_DELETE_INVENTORY_RETURN = "success delete inventory return"
|
||||
MESSAGE_SUCCESS_DELETE_INVENTORY_RETURN_LINE = "success delete inventory return line"
|
||||
MESSAGE_FAILED_GET_DATA_FROM_BODY = "failed get data from body"
|
||||
MESSAGE_FAILED_GET_INVENTORY_RETURN_LINE = "failed get inventory return line"
|
||||
MESSAGE_SUCCESS_GET_INVENTORY_RETURN_LINE = "success get inventory return line"
|
||||
)
|
||||
|
||||
type InventoryReturnCreateRequest struct {
|
||||
|
|
@ -61,14 +63,13 @@ type InventoryReturnLineUpdateRequest struct {
|
|||
}
|
||||
|
||||
type InventoryReturnResponse struct {
|
||||
ID string `json:"id"`
|
||||
DocumentNumber string `json:"document_number"`
|
||||
DocumentDate string `json:"document_date"`
|
||||
Notes string `json:"notes"`
|
||||
Status string `json:"status"`
|
||||
InvIssue InvReturnInvIssue `json:"inv_issue"`
|
||||
Client pkgdto.IdNameResponse `json:"client"`
|
||||
ReturnLines []InventoryReturnLineResponse `json:"return_lines,omitempty"`
|
||||
ID string `json:"id"`
|
||||
DocumentNumber string `json:"document_number"`
|
||||
DocumentDate string `json:"document_date"`
|
||||
Notes string `json:"notes"`
|
||||
Status string `json:"status"`
|
||||
InvIssue InvReturnInvIssue `json:"inv_issue"`
|
||||
Client pkgdto.IdNameResponse `json:"client"`
|
||||
}
|
||||
|
||||
type InvReturnInvIssue struct {
|
||||
|
|
@ -97,10 +98,10 @@ type InvReturnProduct struct {
|
|||
|
||||
// Helper untuk mapping entity ke response
|
||||
func ToInventoryReturnResponse(entity entities.TInventoryReturnEntity) InventoryReturnResponse {
|
||||
lines := make([]InventoryReturnLineResponse, 0, len(entity.ReturnLines))
|
||||
for _, line := range entity.ReturnLines {
|
||||
lines = append(lines, ToInventoryReturnLineResponse(line))
|
||||
}
|
||||
// lines := make([]InventoryReturnLineResponse, 0, len(entity.ReturnLines))
|
||||
// for _, line := range entity.ReturnLines {
|
||||
// lines = append(lines, ToInventoryReturnLineResponse(line))
|
||||
// }
|
||||
|
||||
client := pkgdto.IdNameResponse{}
|
||||
if entity.Client.ID != uuid.Nil {
|
||||
|
|
@ -135,7 +136,6 @@ func ToInventoryReturnResponse(entity entities.TInventoryReturnEntity) Inventory
|
|||
Status: entity.Status,
|
||||
InvIssue: invIssue,
|
||||
Client: client,
|
||||
ReturnLines: lines,
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -175,3 +175,11 @@ func ToInventoryReturnLineResponse(line entities.TInventoryReturnLineEntity) Inv
|
|||
Client: client,
|
||||
}
|
||||
}
|
||||
|
||||
func ToInventoryReturnLineResponses(linesEntity []entities.TInventoryReturnLineEntity) []InventoryReturnLineResponse {
|
||||
lines := make([]InventoryReturnLineResponse, 0, len(linesEntity))
|
||||
for _, line := range linesEntity {
|
||||
lines = append(lines, ToInventoryReturnLineResponse(line))
|
||||
}
|
||||
return lines
|
||||
}
|
||||
|
|
|
|||
|
|
@ -20,6 +20,7 @@ func RegisterRoutes(server *gin.Engine, injector *do.Injector) {
|
|||
returnRoutes.PUT(":id", middlewares.Authenticate(jwtService), returnController.Update)
|
||||
returnRoutes.DELETE(":id", middlewares.Authenticate(jwtService), returnController.Delete)
|
||||
returnRoutes.GET("", middlewares.Authenticate(jwtService), returnController.GetAll)
|
||||
returnRoutes.GET(":id/lines", middlewares.Authenticate(jwtService), returnController.GetLinesByReturnId)
|
||||
returnRoutes.POST(":id/lines", middlewares.Authenticate(jwtService), returnController.CreateLine)
|
||||
returnRoutes.PUT("lines/:id", middlewares.Authenticate(jwtService), returnController.UpdateLine)
|
||||
returnRoutes.DELETE("lines/:id", middlewares.Authenticate(jwtService), returnController.DeleteLine)
|
||||
|
|
|
|||
|
|
@ -19,6 +19,7 @@ type InventoryReturnService interface {
|
|||
Create(ctx context.Context, req dtodomain.InventoryReturnCreateRequest) (dtodomain.InventoryReturnResponse, error)
|
||||
GetById(ctx context.Context, id string) (dtodomain.InventoryReturnResponse, error)
|
||||
GetAll(ctx context.Context, filter query.InventoryReturnFilter) ([]dtodomain.InventoryReturnResponse, int64, error)
|
||||
GetLinesByReturnId(ctx context.Context, returnId string) ([]dtodomain.InventoryReturnLineResponse, error)
|
||||
Update(ctx context.Context, req dtodomain.InventoryReturnUpdateRequest, id string) (dtodomain.InventoryReturnResponse, error)
|
||||
Delete(ctx context.Context, id string) error
|
||||
CreateLine(ctx context.Context, returnId string, req dtodomain.InventoryReturnLineCreateRequest) (dtodomain.InventoryReturnLineResponse, error)
|
||||
|
|
@ -34,6 +35,15 @@ type inventoryReturnService struct {
|
|||
productRepo productrepository.ProductRepository
|
||||
}
|
||||
|
||||
// GetLinesByReturnId implements InventoryReturnService.
|
||||
func (s *inventoryReturnService) GetLinesByReturnId(ctx context.Context, returnId string) ([]dtodomain.InventoryReturnLineResponse, error) {
|
||||
lines, err := s.returnLineRepo.GetAllByReturnId(ctx, returnId)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return dtodomain.ToInventoryReturnLineResponses(lines), nil
|
||||
}
|
||||
|
||||
// DeleteLine implements InventoryReturnService.
|
||||
func (s *inventoryReturnService) DeleteLine(ctx context.Context, lineId string) error {
|
||||
return s.returnLineRepo.Delete(ctx, nil, lineId)
|
||||
|
|
|
|||
Loading…
Reference in New Issue