Implement API endpoint for transactions
This commit is contained in:
@ -52,3 +52,29 @@ func (h *Handler) account(c *gin.Context) {
|
||||
|
||||
c.HTML(http.StatusOK, "account.html", d)
|
||||
}
|
||||
|
||||
func (h *Handler) transactionsForAccount(c *gin.Context) {
|
||||
accountID := c.Param("accountid")
|
||||
accountUUID, err := uuid.Parse(accountID)
|
||||
if err != nil {
|
||||
c.AbortWithError(http.StatusBadRequest, err)
|
||||
return
|
||||
}
|
||||
|
||||
account, err := h.Service.GetAccount(c.Request.Context(), accountUUID)
|
||||
if err != nil {
|
||||
c.AbortWithError(http.StatusNotFound, err)
|
||||
return
|
||||
}
|
||||
|
||||
transactions, err := h.Service.GetTransactionsForAccount(c.Request.Context(), accountUUID)
|
||||
if err != nil {
|
||||
c.AbortWithError(http.StatusNotFound, err)
|
||||
return
|
||||
}
|
||||
|
||||
c.JSON(http.StatusOK, struct {
|
||||
Account postgres.Account
|
||||
Transactions []postgres.GetTransactionsForAccountRow
|
||||
}{account, transactions})
|
||||
}
|
||||
|
Reference in New Issue
Block a user