feat: add inventory return management with controller, service, and repository integration
Deploy Application / deploy (push) Successful in 24s
Details
Deploy Application / deploy (push) Successful in 24s
Details
This commit is contained in:
parent
3b5c5038fb
commit
a2e92cf738
|
|
@ -17,6 +17,7 @@ import (
|
|||
inventoryissue "github.com/Caknoooo/go-gin-clean-starter/modules/inventory_issue"
|
||||
inventoryreceipt "github.com/Caknoooo/go-gin-clean-starter/modules/inventory_receipt"
|
||||
inventoryrequest "github.com/Caknoooo/go-gin-clean-starter/modules/inventory_request"
|
||||
inventoryreturn "github.com/Caknoooo/go-gin-clean-starter/modules/inventory_return"
|
||||
maintenancegroup "github.com/Caknoooo/go-gin-clean-starter/modules/maintenance_group"
|
||||
"github.com/Caknoooo/go-gin-clean-starter/modules/menu"
|
||||
"github.com/Caknoooo/go-gin-clean-starter/modules/monitoring"
|
||||
|
|
@ -169,6 +170,7 @@ func main() {
|
|||
assignment.RegisterRoutes(server, injector)
|
||||
inventoryrequest.RegisterRoutes(server, injector)
|
||||
inventoryissue.RegisterRoutes(server, injector)
|
||||
inventoryreturn.RegisterRoutes(server, injector)
|
||||
|
||||
// register swagger route
|
||||
server.GET("/swagger/*any", ginSwagger.WrapHandler(swaggerFiles.Handler))
|
||||
|
|
|
|||
|
|
@ -4,10 +4,11 @@ import (
|
|||
"net/http"
|
||||
|
||||
"github.com/Caknoooo/go-gin-clean-starter/modules/inventory_return/dto"
|
||||
"github.com/Caknoooo/go-gin-clean-starter/modules/inventory_return/query"
|
||||
"github.com/Caknoooo/go-gin-clean-starter/modules/inventory_return/service"
|
||||
"github.com/Caknoooo/go-gin-clean-starter/pkg/utils"
|
||||
"github.com/gin-gonic/gin"
|
||||
"gorm.io/gorm"
|
||||
"github.com/samber/do"
|
||||
)
|
||||
|
||||
type InventoryReturnController interface {
|
||||
|
|
@ -23,7 +24,6 @@ type InventoryReturnController interface {
|
|||
|
||||
type inventoryReturnController struct {
|
||||
returnService service.InventoryReturnService
|
||||
db *gorm.DB
|
||||
}
|
||||
|
||||
// DeleteLine implements InventoryReturnController.
|
||||
|
|
@ -57,4 +57,121 @@ func (c *inventoryReturnController) UpdateLine(ctx *gin.Context) {
|
|||
ctx.JSON(http.StatusOK, res)
|
||||
}
|
||||
|
||||
// ...implementasi fungsi lain (Create, Update, Delete, GetById, GetAll, CreateLine) dengan pola yang sama...
|
||||
func (c *inventoryReturnController) Create(ctx *gin.Context) {
|
||||
var req dto.InventoryReturnCreateRequest
|
||||
if err := ctx.ShouldBindJSON(&req); err != nil {
|
||||
res := utils.BuildResponseFailed(dto.MESSAGE_FAILED_GET_DATA_FROM_BODY, err.Error(), nil)
|
||||
ctx.JSON(http.StatusBadRequest, res)
|
||||
return
|
||||
}
|
||||
created, err := c.returnService.Create(ctx, req)
|
||||
if err != nil {
|
||||
res := utils.BuildResponseFailed(dto.MESSAGE_FAILED_CREATE_INVENTORY_RETURN, err.Error(), nil)
|
||||
ctx.JSON(http.StatusInternalServerError, res)
|
||||
return
|
||||
}
|
||||
res := utils.BuildResponseSuccess(dto.MESSAGE_SUCCESS_CREATE_INVENTORY_RETURN, created)
|
||||
ctx.JSON(http.StatusOK, res)
|
||||
}
|
||||
|
||||
func (c *inventoryReturnController) Update(ctx *gin.Context) {
|
||||
id := ctx.Param("id")
|
||||
var req dto.InventoryReturnUpdateRequest
|
||||
if err := ctx.ShouldBindJSON(&req); err != nil {
|
||||
res := utils.BuildResponseFailed(dto.MESSAGE_FAILED_GET_DATA_FROM_BODY, err.Error(), nil)
|
||||
ctx.JSON(http.StatusBadRequest, res)
|
||||
return
|
||||
}
|
||||
updated, err := c.returnService.Update(ctx, req, id)
|
||||
if err != nil {
|
||||
res := utils.BuildResponseFailed(dto.MESSAGE_FAILED_UPDATE_INVENTORY_RETURN, err.Error(), nil)
|
||||
ctx.JSON(http.StatusInternalServerError, res)
|
||||
return
|
||||
}
|
||||
res := utils.BuildResponseSuccess(dto.MESSAGE_SUCCESS_UPDATE_INVENTORY_RETURN, updated)
|
||||
ctx.JSON(http.StatusOK, res)
|
||||
}
|
||||
|
||||
func (c *inventoryReturnController) Delete(ctx *gin.Context) {
|
||||
id := ctx.Param("id")
|
||||
if err := c.returnService.Delete(ctx, id); err != nil {
|
||||
res := utils.BuildResponseFailed(dto.MESSAGE_FAILED_DELETE_INVENTORY_RETURN, err.Error(), nil)
|
||||
ctx.JSON(http.StatusInternalServerError, res)
|
||||
return
|
||||
}
|
||||
res := utils.BuildResponseSuccess(dto.MESSAGE_SUCCESS_DELETE_INVENTORY_RETURN, nil)
|
||||
ctx.JSON(http.StatusOK, res)
|
||||
}
|
||||
|
||||
func (c *inventoryReturnController) GetById(ctx *gin.Context) {
|
||||
id := ctx.Param("id")
|
||||
result, err := c.returnService.GetById(ctx, id)
|
||||
if err != nil {
|
||||
res := utils.BuildResponseFailed(dto.MESSAGE_FAILED_GET_INVENTORY_RETURN, err.Error(), nil)
|
||||
ctx.JSON(http.StatusInternalServerError, res)
|
||||
return
|
||||
}
|
||||
res := utils.BuildResponseSuccess(dto.MESSAGE_SUCCESS_GET_INVENTORY_RETURN, result)
|
||||
ctx.JSON(http.StatusOK, res)
|
||||
}
|
||||
|
||||
func (c *inventoryReturnController) GetAll(ctx *gin.Context) {
|
||||
clientId := ctx.MustGet("client_id").(string)
|
||||
var filter query.InventoryReturnFilter
|
||||
filter.ClientID = clientId
|
||||
if err := ctx.ShouldBindQuery(&filter); err != nil {
|
||||
res := utils.BuildResponseFailed(dto.MESSAGE_FAILED_GET_INVENTORY_RETURN, err.Error(), nil)
|
||||
ctx.JSON(http.StatusBadRequest, res)
|
||||
return
|
||||
}
|
||||
getAll := ctx.Query("get_all")
|
||||
if getAll != "" {
|
||||
returns, _, err := c.returnService.GetAll(ctx, filter)
|
||||
if err != nil {
|
||||
res := utils.BuildResponseFailed(dto.MESSAGE_FAILED_GET_INVENTORY_RETURN, err.Error(), nil)
|
||||
ctx.JSON(http.StatusBadRequest, res)
|
||||
return
|
||||
}
|
||||
response := utils.BuildResponseSuccess(dto.MESSAGE_SUCCESS_GET_INVENTORY_RETURN, returns)
|
||||
ctx.JSON(http.StatusOK, response)
|
||||
return
|
||||
}
|
||||
perPage := utils.ParseInt(ctx.DefaultQuery("per_page", "10"))
|
||||
page := utils.ParseInt(ctx.DefaultQuery("page", "1"))
|
||||
filter.PerPage = perPage
|
||||
filter.Page = (page - 1) * perPage
|
||||
returns, total, err := c.returnService.GetAll(ctx, filter)
|
||||
if err != nil {
|
||||
res := utils.BuildResponseFailed(dto.MESSAGE_FAILED_GET_INVENTORY_RETURN, err.Error(), nil)
|
||||
ctx.JSON(http.StatusInternalServerError, res)
|
||||
return
|
||||
}
|
||||
paginationResponse := utils.BuildPaginationResponse(perPage, page, total)
|
||||
res := utils.BuildResponseSuccessWithPagination(http.StatusOK, dto.MESSAGE_SUCCESS_GET_INVENTORY_RETURN, returns, paginationResponse)
|
||||
ctx.JSON(http.StatusOK, res)
|
||||
}
|
||||
|
||||
func (c *inventoryReturnController) CreateLine(ctx *gin.Context) {
|
||||
returnId := ctx.Param("id")
|
||||
var req dto.InventoryReturnLineCreateRequest
|
||||
if err := ctx.ShouldBindJSON(&req); err != nil {
|
||||
res := utils.BuildResponseFailed(dto.MESSAGE_FAILED_GET_DATA_FROM_BODY, err.Error(), nil)
|
||||
ctx.JSON(http.StatusBadRequest, res)
|
||||
return
|
||||
}
|
||||
created, err := c.returnService.CreateLine(ctx, returnId, req)
|
||||
if err != nil {
|
||||
res := utils.BuildResponseFailed(dto.MESSAGE_FAILED_CREATE_INVENTORY_RETURN_LINE, err.Error(), nil)
|
||||
ctx.JSON(http.StatusInternalServerError, res)
|
||||
return
|
||||
}
|
||||
res := utils.BuildResponseSuccess(dto.MESSAGE_SUCCESS_CREATE_INVENTORY_RETURN_LINE, created)
|
||||
ctx.JSON(http.StatusOK, res)
|
||||
}
|
||||
|
||||
func NewInventoryReturnController(i *do.Injector, returnService service.InventoryReturnService) InventoryReturnController {
|
||||
// db := do.MustInvokeNamed[*gorm.DB](i, constants.DB)
|
||||
return &inventoryReturnController{
|
||||
returnService: returnService,
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -78,6 +78,11 @@ import (
|
|||
inventoryIssueRepo "github.com/Caknoooo/go-gin-clean-starter/modules/inventory_issue/repository"
|
||||
inventoryIssueService "github.com/Caknoooo/go-gin-clean-starter/modules/inventory_issue/service"
|
||||
|
||||
inventoryReturnController "github.com/Caknoooo/go-gin-clean-starter/modules/inventory_return/controller"
|
||||
inventoryReturnLineRepo "github.com/Caknoooo/go-gin-clean-starter/modules/inventory_return/repository"
|
||||
inventoryReturnRepo "github.com/Caknoooo/go-gin-clean-starter/modules/inventory_return/repository"
|
||||
inventoryReturnService "github.com/Caknoooo/go-gin-clean-starter/modules/inventory_return/service"
|
||||
|
||||
"github.com/Caknoooo/go-gin-clean-starter/modules/user/controller"
|
||||
"github.com/Caknoooo/go-gin-clean-starter/modules/user/repository"
|
||||
userService "github.com/Caknoooo/go-gin-clean-starter/modules/user/service"
|
||||
|
|
@ -135,6 +140,8 @@ func RegisterDependencies(injector *do.Injector) {
|
|||
inventoryRequestLineRepository := inventoryRequestLineRepo.NewInventoryRequestLineRepository(db)
|
||||
inventoryIssueRepository := inventoryIssueRepo.NewInventoryIssueRepository(db)
|
||||
inventoryIssueLineRepository := inventoryIssueLineRepo.NewInventoryIssueLineRepository(db)
|
||||
inventoryReturnRepository := inventoryReturnRepo.NewInventoryReturnRepository(db)
|
||||
inventoryReturnLineRepository := inventoryReturnLineRepo.NewInventoryReturnLineRepository(db)
|
||||
|
||||
// Service
|
||||
userServ := userService.NewUserService(userRepository, refreshTokenRepository, jwtService, db)
|
||||
|
|
@ -154,6 +161,7 @@ func RegisterDependencies(injector *do.Injector) {
|
|||
assignmentServ := assignmentService.NewAssignmentService(db, assignmentRepository, assignmentUserRepository)
|
||||
inventoryRequestServ := inventoryRequestService.NewInventoryRequestService(db, inventoryRequestRepository, inventoryRequestLineRepository)
|
||||
inventoryIssueServ := inventoryIssueService.NewInventoryIssueService(db, inventoryIssueRepository, inventoryIssueLineRepository)
|
||||
inventoryReturnServ := inventoryReturnService.NewInventoryReturnService(db, inventoryReturnRepository, inventoryReturnLineRepository, inventoryIssueLineRepository, productRepository)
|
||||
|
||||
// Controller
|
||||
do.Provide(
|
||||
|
|
@ -251,4 +259,9 @@ func RegisterDependencies(injector *do.Injector) {
|
|||
return inventoryIssueController.NewInventoryIssueController(i, inventoryIssueServ), nil
|
||||
},
|
||||
)
|
||||
do.Provide(
|
||||
injector, func(i *do.Injector) (inventoryReturnController.InventoryReturnController, error) {
|
||||
return inventoryReturnController.NewInventoryReturnController(i, inventoryReturnServ), nil
|
||||
},
|
||||
)
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue