Handle new Payees

This commit is contained in:
Jan Bader 2022-02-15 09:02:01 +00:00
parent 368ac7f15d
commit a09511061f

View File

@ -35,8 +35,6 @@ func (h *Handler) newTransaction(c *gin.Context) {
return
}
fmt.Printf("%v\n", payload)
amount := postgres.Numeric{}
amount.Set(payload.Amount)
@ -46,13 +44,30 @@ func (h *Handler) newTransaction(c *gin.Context) {
return
}*/
payeeID := payload.Payee.ID
if !payeeID.Valid && payload.Payee.Name != "" {
newPayee := postgres.CreatePayeeParams{
Name: payload.Payee.Name,
BudgetID: payload.BudgetID,
}
payee, err := h.Service.CreatePayee(c.Request.Context(), newPayee)
if err != nil {
c.AbortWithError(http.StatusInternalServerError, fmt.Errorf("create payee: %w", err))
}
payeeID = uuid.NullUUID{
UUID: payee.ID,
Valid: true,
}
}
//if !transactionUUID.Valid {
new := postgres.CreateTransactionParams{
Memo: payload.Memo,
Date: time.Time(payload.Date),
Amount: amount,
AccountID: payload.AccountID,
PayeeID: payload.Payee.ID, //TODO handle new payee
PayeeID: payeeID, //TODO handle new payee
CategoryID: payload.Category.ID, //TODO handle new category
Status: postgres.TransactionStatus(payload.State),
}