Start migration to echo

This commit is contained in:
2022-08-20 22:08:41 +00:00
parent dd0f620b7a
commit b573553424
5 changed files with 101 additions and 69 deletions

View File

@@ -7,6 +7,7 @@ import (
"git.javil.eu/jacob1123/budgeteer/postgres"
"github.com/gin-gonic/gin"
"github.com/google/uuid"
"github.com/labstack/echo/v4"
)
type FilterTransactionsRequest struct {
@@ -17,7 +18,7 @@ type FilterTransactionsRequest struct {
ToDate time.Time `json:"to_date"`
}
func (h *Handler) filteredTransactions(c *gin.Context) {
func (h *Handler) filteredTransactions(c *echo.Context) {
budgetID := c.Param("budgetid")
budgetUUID, err := uuid.Parse(budgetID)
if err != nil {
@@ -81,27 +82,24 @@ func (h *Handler) problematicTransactions(c *gin.Context) {
c.JSON(http.StatusOK, TransactionsResponse{nil, transactions})
}
func (h *Handler) transactionsForAccount(c *gin.Context) {
func (h *Handler) transactionsForAccount(c echo.Context) error {
accountID := c.Param("accountid")
accountUUID, err := uuid.Parse(accountID)
if err != nil {
c.AbortWithError(http.StatusBadRequest, err)
return
return echo.NewHTTPError(http.StatusBadRequest, err)
}
account, err := h.Service.GetAccount(c.Request.Context(), accountUUID)
account, err := h.Service.GetAccount(c.Request().Context(), accountUUID)
if err != nil {
c.AbortWithError(http.StatusNotFound, err)
return
return echo.NewHTTPError(http.StatusNotFound, err)
}
transactions, err := h.Service.GetTransactionsForAccount(c.Request.Context(), accountUUID)
transactions, err := h.Service.GetTransactionsForAccount(c.Request().Context(), accountUUID)
if err != nil {
c.AbortWithError(http.StatusNotFound, err)
return
return echo.NewHTTPError(http.StatusNotFound, err)
}
c.JSON(http.StatusOK, TransactionsResponse{&account, transactions})
return c.JSON(http.StatusOK, TransactionsResponse{&account, transactions})
}
type TransactionsResponse struct {