Implement Delete Budget
This commit is contained in:
parent
1be3b6930d
commit
95b1ac5943
@ -19,14 +19,20 @@ func (h *Handler) clearDatabase(c *gin.Context) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *Handler) clearBudget(c *gin.Context) {
|
func (h *Handler) deleteBudget(c *gin.Context) {
|
||||||
budgetID := c.Param("budgetid")
|
budgetID := c.Param("budgetid")
|
||||||
budgetUUID, err := uuid.Parse(budgetID)
|
budgetUUID, err := uuid.Parse(budgetID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.Redirect(http.StatusTemporaryRedirect, "/login")
|
c.AbortWithStatus(http.StatusBadRequest)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
h.clearBudgetData(c, budgetUUID)
|
||||||
|
|
||||||
|
h.Service.DeleteBudget(c.Request.Context(), budgetUUID)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (h *Handler) clearBudgetData(c *gin.Context, budgetUUID uuid.UUID) {
|
||||||
rows, err := h.Service.DeleteAllAssignments(c.Request.Context(), budgetUUID)
|
rows, err := h.Service.DeleteAllAssignments(c.Request.Context(), budgetUUID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.AbortWithError(http.StatusInternalServerError, err)
|
c.AbortWithError(http.StatusInternalServerError, err)
|
||||||
@ -44,6 +50,17 @@ func (h *Handler) clearBudget(c *gin.Context) {
|
|||||||
fmt.Printf("Deleted %d transactions\n", rows)
|
fmt.Printf("Deleted %d transactions\n", rows)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (h *Handler) clearBudget(c *gin.Context) {
|
||||||
|
budgetID := c.Param("budgetid")
|
||||||
|
budgetUUID, err := uuid.Parse(budgetID)
|
||||||
|
if err != nil {
|
||||||
|
c.AbortWithStatus(http.StatusBadRequest)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
h.clearBudgetData(c, budgetUUID)
|
||||||
|
}
|
||||||
|
|
||||||
func (h *Handler) cleanNegativeBudget(c *gin.Context) {
|
func (h *Handler) cleanNegativeBudget(c *gin.Context) {
|
||||||
/*budgetID := c.Param("budgetid")
|
/*budgetID := c.Param("budgetid")
|
||||||
budgetUUID, err := uuid.Parse(budgetID)
|
budgetUUID, err := uuid.Parse(budgetID)
|
||||||
|
@ -66,6 +66,7 @@ func (h *Handler) Serve() {
|
|||||||
authenticated.GET("/account/:accountid/transactions", h.transactionsForAccount)
|
authenticated.GET("/account/:accountid/transactions", h.transactionsForAccount)
|
||||||
authenticated.GET("/admin/clear-database", h.clearDatabase)
|
authenticated.GET("/admin/clear-database", h.clearDatabase)
|
||||||
authenticated.GET("/budget/:budgetid", h.budgeting)
|
authenticated.GET("/budget/:budgetid", h.budgeting)
|
||||||
|
authenticated.DELETE("/budget/:budgetid", h.deleteBudget)
|
||||||
authenticated.POST("/budget/:budgetid/import/ynab", h.importYNAB)
|
authenticated.POST("/budget/:budgetid/import/ynab", h.importYNAB)
|
||||||
authenticated.POST("/budget/:budgetid/settings/clear", h.clearBudget)
|
authenticated.POST("/budget/:budgetid/settings/clear", h.clearBudget)
|
||||||
|
|
||||||
|
@ -34,6 +34,15 @@ func (q *Queries) CreateBudget(ctx context.Context, arg CreateBudgetParams) (Bud
|
|||||||
return i, err
|
return i, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const deleteBudget = `-- name: DeleteBudget :exec
|
||||||
|
DELETE FROM budgets WHERE id = $1
|
||||||
|
`
|
||||||
|
|
||||||
|
func (q *Queries) DeleteBudget(ctx context.Context, id uuid.UUID) error {
|
||||||
|
_, err := q.db.ExecContext(ctx, deleteBudget, id)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
const getBudget = `-- name: GetBudget :one
|
const getBudget = `-- name: GetBudget :one
|
||||||
SELECT id, name, last_modification, income_category_id FROM budgets
|
SELECT id, name, last_modification, income_category_id FROM budgets
|
||||||
WHERE id = $1
|
WHERE id = $1
|
||||||
|
@ -32,3 +32,6 @@ FROM (
|
|||||||
INNER JOIN accounts ON accounts.id = transactions.account_id
|
INNER JOIN accounts ON accounts.id = transactions.account_id
|
||||||
WHERE accounts.budget_id = @budget_id
|
WHERE accounts.budget_id = @budget_id
|
||||||
) dates;
|
) dates;
|
||||||
|
|
||||||
|
-- name: DeleteBudget :exec
|
||||||
|
DELETE FROM budgets WHERE id = $1;
|
@ -23,6 +23,14 @@ export default {
|
|||||||
gotTransactions(e) {
|
gotTransactions(e) {
|
||||||
this.$data.transactionsFile = e.target.files[0];
|
this.$data.transactionsFile = e.target.files[0];
|
||||||
},
|
},
|
||||||
|
deleteBudget() {
|
||||||
|
fetch("/api/v1/budget/" + this.$store.getters.CurrentBudget.ID, {
|
||||||
|
method: "DELETE",
|
||||||
|
headers: {
|
||||||
|
'Authorization': 'Bearer ' + this.$store.state.Session.Token
|
||||||
|
},
|
||||||
|
})
|
||||||
|
},
|
||||||
clearBudget() {
|
clearBudget() {
|
||||||
fetch("/api/v1/budget/" + this.$store.getters.CurrentBudget.ID + "/settings/clear", {
|
fetch("/api/v1/budget/" + this.$store.getters.CurrentBudget.ID + "/settings/clear", {
|
||||||
method: "POST",
|
method: "POST",
|
||||||
@ -65,6 +73,23 @@ export default {
|
|||||||
</v-card-actions>
|
</v-card-actions>
|
||||||
</v-card>
|
</v-card>
|
||||||
</v-col>
|
</v-col>
|
||||||
|
<v-col cols="12" md="6" xl="3">
|
||||||
|
<v-card>
|
||||||
|
<v-card-header>
|
||||||
|
<v-card-header-text>
|
||||||
|
<v-card-title>
|
||||||
|
Delete Budget
|
||||||
|
</v-card-title>
|
||||||
|
<v-card-subtitle>
|
||||||
|
This deletes the whole bugdet including all transactions, assignments, accounts and categories. Not undoable!
|
||||||
|
</v-card-subtitle>
|
||||||
|
</v-card-header-text>
|
||||||
|
</v-card-header>
|
||||||
|
<v-card-actions class="justify-center">
|
||||||
|
<v-btn @click="deleteBudget" color="error">Delete budget</v-btn>
|
||||||
|
</v-card-actions>
|
||||||
|
</v-card>
|
||||||
|
</v-col>
|
||||||
<v-col cols="12" md="6" xl="3">
|
<v-col cols="12" md="6" xl="3">
|
||||||
<v-card>
|
<v-card>
|
||||||
<v-card-header>
|
<v-card-header>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user