Remove unneeded assignment
This commit is contained in:
@ -1,6 +1,7 @@
|
||||
package http
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
|
||||
"git.javil.eu/jacob1123/budgeteer"
|
||||
@ -48,17 +49,29 @@ func (h *Handler) allAccounts(c *gin.Context) {
|
||||
c.HTML(http.StatusOK, "account.html", d)
|
||||
}
|
||||
|
||||
type newBudgetInformation struct {
|
||||
Name string `json:"name"`
|
||||
}
|
||||
|
||||
func (h *Handler) newBudget(c *gin.Context) {
|
||||
budgetName, succ := c.GetPostForm("name")
|
||||
if !succ {
|
||||
c.AbortWithStatus(http.StatusNotAcceptable)
|
||||
var newBudget newBudgetInformation
|
||||
err := c.BindJSON(&newBudget)
|
||||
if err != nil {
|
||||
c.AbortWithError(http.StatusNotAcceptable, err)
|
||||
return
|
||||
}
|
||||
|
||||
if newBudget.Name == "" {
|
||||
c.AbortWithError(http.StatusNotAcceptable, fmt.Errorf("Budget name is needed"))
|
||||
return
|
||||
}
|
||||
|
||||
userID := c.MustGet("token").(budgeteer.Token).GetID()
|
||||
_, err := h.Service.NewBudget(c.Request.Context(), budgetName, userID)
|
||||
budget, err := h.Service.NewBudget(c.Request.Context(), newBudget.Name, userID)
|
||||
if err != nil {
|
||||
c.AbortWithError(http.StatusInternalServerError, err)
|
||||
return
|
||||
}
|
||||
|
||||
c.JSON(http.StatusOK, budget)
|
||||
}
|
||||
|
Reference in New Issue
Block a user