Split routes into own files
This commit is contained in:
54
http/transaction.go
Normal file
54
http/transaction.go
Normal file
@ -0,0 +1,54 @@
|
||||
package http
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"time"
|
||||
|
||||
"git.javil.eu/jacob1123/budgeteer/postgres"
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/google/uuid"
|
||||
)
|
||||
|
||||
func (h *Handler) newTransaction(c *gin.Context) {
|
||||
transactionMemo, succ := c.GetPostForm("memo")
|
||||
if !succ {
|
||||
c.AbortWithStatus(http.StatusNotAcceptable)
|
||||
return
|
||||
}
|
||||
|
||||
transactionAccount, succ := c.GetPostForm("account_id")
|
||||
if !succ {
|
||||
c.AbortWithStatus(http.StatusNotAcceptable)
|
||||
return
|
||||
}
|
||||
|
||||
transactionAccountID, err := uuid.Parse(transactionAccount)
|
||||
if !succ {
|
||||
c.AbortWithStatus(http.StatusNotAcceptable)
|
||||
return
|
||||
}
|
||||
|
||||
transactionDate, succ := c.GetPostForm("date")
|
||||
if !succ {
|
||||
c.AbortWithStatus(http.StatusNotAcceptable)
|
||||
return
|
||||
}
|
||||
|
||||
transactionDateValue, err := time.Parse("2006-01-02", transactionDate)
|
||||
if err != nil {
|
||||
c.AbortWithStatus(http.StatusNotAcceptable)
|
||||
return
|
||||
}
|
||||
|
||||
new := postgres.CreateTransactionParams{
|
||||
Memo: transactionMemo,
|
||||
Date: transactionDateValue,
|
||||
Amount: postgres.Numeric{},
|
||||
AccountID: transactionAccountID,
|
||||
}
|
||||
_, err = h.Service.DB.CreateTransaction(c.Request.Context(), new)
|
||||
if err != nil {
|
||||
c.AbortWithError(http.StatusInternalServerError, err)
|
||||
return
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user