Convert frontend to Vue #3
| @@ -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}) | ||||
| } | ||||
|   | ||||
| @@ -1,6 +1,7 @@ | ||||
| package http | ||||
|  | ||||
| import ( | ||||
| 	"fmt" | ||||
| 	"net/http" | ||||
|  | ||||
| 	"git.javil.eu/jacob1123/budgeteer/postgres" | ||||
| @@ -17,8 +18,7 @@ func (h *Handler) getImportantData(c *gin.Context) { | ||||
| 	budgetID := c.Param("budgetid") | ||||
| 	budgetUUID, err := uuid.Parse(budgetID) | ||||
| 	if err != nil { | ||||
| 		c.Redirect(http.StatusTemporaryRedirect, "/login") | ||||
| 		c.Abort() | ||||
| 		c.AbortWithError(http.StatusBadRequest, fmt.Errorf("budgetid missing from URL")) | ||||
| 		return | ||||
| 	} | ||||
|  | ||||
|   | ||||
| @@ -73,6 +73,7 @@ func (h *Handler) Serve() { | ||||
| 	authenticated := api.Group("") | ||||
| 	authenticated.Use(h.verifyLoginWithForbidden) | ||||
| 	authenticated.GET("/dashboard", h.dashboard) | ||||
| 	authenticated.GET("/account/:accountid/transactions", h.transactionsForAccount) | ||||
|  | ||||
| 	withBudget2 := authenticated.Group("") | ||||
| 	withBudget2.Use(h.getImportantData) | ||||
|   | ||||
| @@ -14,6 +14,9 @@ const budget = { | ||||
|         }, | ||||
|         setCurrentAccount(state, account) { | ||||
|             state.CurrentAccount = account; | ||||
|         }, | ||||
|         setTransactions(state, transactions){ | ||||
|             state.Transactions = transactions; | ||||
|         } | ||||
|     }, | ||||
|     getters: { | ||||
| @@ -44,7 +47,7 @@ const budget = { | ||||
|             return commit("setAccounts", response.Accounts); | ||||
|         }, | ||||
|         async fetchAccount ({state, commit, rootState}, accountid) { | ||||
|             const result = await fetch("/api/v1/account/" + accountid, { | ||||
|             const result = await fetch("/api/v1/account/" + accountid + "/transactions", { | ||||
|                 headers: { | ||||
|                     'Authorization': 'Bearer ' + rootState.Session.Token | ||||
|                 } | ||||
|   | ||||
		Reference in New Issue
	
	Block a user