Remove unneeded assignment
This commit is contained in:
parent
746680a4d7
commit
be821bc90a
@ -1,6 +1,7 @@
|
|||||||
package http
|
package http
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
"git.javil.eu/jacob1123/budgeteer"
|
"git.javil.eu/jacob1123/budgeteer"
|
||||||
@ -48,17 +49,29 @@ func (h *Handler) allAccounts(c *gin.Context) {
|
|||||||
c.HTML(http.StatusOK, "account.html", d)
|
c.HTML(http.StatusOK, "account.html", d)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type newBudgetInformation struct {
|
||||||
|
Name string `json:"name"`
|
||||||
|
}
|
||||||
|
|
||||||
func (h *Handler) newBudget(c *gin.Context) {
|
func (h *Handler) newBudget(c *gin.Context) {
|
||||||
budgetName, succ := c.GetPostForm("name")
|
var newBudget newBudgetInformation
|
||||||
if !succ {
|
err := c.BindJSON(&newBudget)
|
||||||
c.AbortWithStatus(http.StatusNotAcceptable)
|
if err != nil {
|
||||||
|
c.AbortWithError(http.StatusNotAcceptable, err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if newBudget.Name == "" {
|
||||||
|
c.AbortWithError(http.StatusNotAcceptable, fmt.Errorf("Budget name is needed"))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
userID := c.MustGet("token").(budgeteer.Token).GetID()
|
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 {
|
if err != nil {
|
||||||
c.AbortWithError(http.StatusInternalServerError, err)
|
c.AbortWithError(http.StatusInternalServerError, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
c.JSON(http.StatusOK, budget)
|
||||||
}
|
}
|
||||||
|
@ -1,18 +1,20 @@
|
|||||||
<script>
|
<script>
|
||||||
|
import NewBudget from '@/dialogs/NewBudget.vue';
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
mounted () {
|
mounted() {
|
||||||
this.$store.dispatch("fetchDashboard");
|
this.$store.dispatch("fetchDashboard");
|
||||||
}
|
},
|
||||||
|
components: { NewBudget }
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
<div v-for="budget in $store.getters.Budgets" class="budget-item">
|
<v-card cols="12" md="6" v-for="budget in $store.getters.Budgets" class="budget-item">
|
||||||
<router-link v-bind:to="'/budget/'+budget.ID">{{budget.Name}}</router-link>
|
<v-card-title class="text-h5 grey lighten-2">
|
||||||
<span class="time"></span>
|
<router-link v-bind:to="'/budget/'+budget.ID">{{budget.Name}}</router-link>
|
||||||
</div>
|
</v-card-title>
|
||||||
<div class="budget-item">
|
<v-card-text><span class="time"></span></v-card-text>
|
||||||
<button type="button" class="btn btn-primary" data-bs-toggle="modal" data-bs-target="#newbudgetmodal">New Budget</button>
|
</v-card>
|
||||||
<span class="time"></span>
|
<NewBudget />
|
||||||
</div>
|
|
||||||
</template>
|
</template>
|
@ -32,7 +32,7 @@ const budget = {
|
|||||||
})
|
})
|
||||||
.then(x => x.json())
|
.then(x => x.json())
|
||||||
.then(x => commit("setAccounts", x.Accounts));
|
.then(x => commit("setAccounts", x.Accounts));
|
||||||
}
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -7,7 +7,10 @@ const dashboard = {
|
|||||||
},
|
},
|
||||||
mutations: {
|
mutations: {
|
||||||
setBudgets (state, budgets) {
|
setBudgets (state, budgets) {
|
||||||
state.Budgets = budgets;
|
state.Budgets = budgets;
|
||||||
|
},
|
||||||
|
addBudget(state, budget) {
|
||||||
|
state.Budgets.push(budget);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
getters: {
|
getters: {
|
||||||
@ -24,6 +27,17 @@ const dashboard = {
|
|||||||
})
|
})
|
||||||
.then(x => x.json())
|
.then(x => x.json())
|
||||||
.then(x => commit("setBudgets", x.Budgets));
|
.then(x => commit("setBudgets", x.Budgets));
|
||||||
|
},
|
||||||
|
newBudget ({state, commit, rootState}, budgetName) {
|
||||||
|
fetch("/api/v1/budget/new", {
|
||||||
|
method: "POST",
|
||||||
|
body: JSON.stringify({name: budgetName}),
|
||||||
|
headers: {
|
||||||
|
'Authorization': 'Bearer ' + rootState.Session.Token
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.then(x => x.json())
|
||||||
|
.then(x => commit("addBudget", x.Budget));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user