Improve Backend
This commit is contained in:
@ -30,10 +30,13 @@ func (h *Handler) filteredTransactions(c *gin.Context) {
|
||||
}
|
||||
|
||||
params := postgres.GetFilteredTransactionsParams{
|
||||
BudgetID: budgetUUID,
|
||||
CategoryID: uuid.NullUUID{},
|
||||
FilterCategory: true,
|
||||
BudgetID: budgetUUID,
|
||||
}
|
||||
params.CategoryID, params.FilterCategory = parseEmptyUUID(request.CategoryID)
|
||||
accountID, filterAccount := parseEmptyUUID(request.AccountID)
|
||||
params.AccountID, params.FilterAccount = accountID.UUID, filterAccount
|
||||
params.PayeeID, params.FilterPayee = parseEmptyUUID(request.PayeeID)
|
||||
|
||||
transactions, err := h.Service.GetFilteredTransactions(c.Request.Context(), params)
|
||||
if err != nil {
|
||||
c.AbortWithError(http.StatusInternalServerError, err)
|
||||
@ -43,6 +46,19 @@ func (h *Handler) filteredTransactions(c *gin.Context) {
|
||||
c.JSON(http.StatusOK, TransactionsResponse{nil, transactions})
|
||||
}
|
||||
|
||||
func parseEmptyUUID(value string) (uuid.NullUUID, bool) {
|
||||
if value == "" {
|
||||
return uuid.NullUUID{}, false
|
||||
}
|
||||
|
||||
val, err := uuid.Parse(value)
|
||||
if err != nil {
|
||||
return uuid.NullUUID{}, false
|
||||
}
|
||||
|
||||
return uuid.NullUUID{val, true}, true
|
||||
}
|
||||
|
||||
func (h *Handler) problematicTransactions(c *gin.Context) {
|
||||
budgetID := c.Param("budgetid")
|
||||
budgetUUID, err := uuid.Parse(budgetID)
|
||||
|
Reference in New Issue
Block a user