feat(expense): starting expense handle

This commit is contained in:
2021-11-24 01:07:19 +01:00
parent 917c3a4318
commit 82d86fb33f
4 changed files with 83 additions and 4 deletions

View File

@@ -1,8 +1,11 @@
package expense
import (
"net/http"
"nos-comptes/handler"
"nos-comptes/internal/storage/dao/postgresql"
"nos-comptes/internal/storage/model"
"nos-comptes/internal/utils"
"github.com/gin-gonic/gin"
)
@@ -21,8 +24,23 @@ func (c *Context) DeleteExpense(context *gin.Context) {
}
func (c *Context) GetAllExpenses(context *gin.Context) {
func (c *Context) GetAllExpenses(gc *gin.Context) {
accountId := gc.Param("accountId")
accounts, err := c.service.GetAllExpensesOfAnAccount(accountId)
if e, ok := err.(*model.APIError); ok {
utils.GetLoggerFromCtx(gc).WithError(err).WithField("type", e.Type).Error("error GetAllExpenses: get expenses")
utils.JSONErrorWithMessage(gc.Writer, *e, e.Description)
} else if err != nil {
utils.GetLoggerFromCtx(gc).WithError(err).Error("error while get expenses")
utils.JSONError(gc.Writer, model.ErrInternalServer)
return
}
if len(accounts) == 0 {
utils.JSON(gc.Writer, http.StatusNoContent, nil)
} else {
utils.JSON(gc.Writer, http.StatusOK, accounts)
}
}
func (c *Context) GetAnExpenses(context *gin.Context) {