Update Tranaction

This commit is contained in:
aditya.siregar
2024-07-31 23:54:17 +07:00
parent 4c1a819365
commit a4bad0c088
9 changed files with 186 additions and 21 deletions
@@ -18,6 +18,7 @@ func (h *TransactionHandler) Route(group *gin.RouterGroup, jwt gin.HandlerFunc)
route := group.Group("/transaction")
route.GET("/search", jwt, h.Search)
route.POST("/approval", jwt, h.Approval)
}
func New(service services.Transaction) *TransactionHandler {
@@ -63,6 +64,36 @@ func (h *TransactionHandler) Search(c *gin.Context) {
})
}
func (h *TransactionHandler) Approval(c *gin.Context) {
var req request.ApprovalRequest
if err := c.ShouldBindJSON(&req); err != nil {
response.ErrorWrapper(c, errors.ErrorBadRequest)
return
}
ctx := request.GetMyContext(c)
if !ctx.IsAdmin() {
response.ErrorWrapper(c, errors.ErrorBadRequest)
return
}
if err := req.Validate(); err != nil {
response.ErrorWrapper(c, errors.NewError(errors.ErrorBadRequest.ErrorType(), err.Error()))
return
}
err := h.service.Approval(ctx, req.ToEntity())
if err != nil {
response.ErrorWrapper(c, err)
return
}
c.JSON(http.StatusOK, response.BaseResponse{
Success: true,
Status: http.StatusOK,
})
}
func (h *TransactionHandler) ToTransactionListResponse(transactions []*entity.TransactionList, totalCount, limit, offset int) response.TransactionListResponse {
responseItems := make([]response.TransactionListItem, len(transactions))
for i, transaction := range transactions {