Implement deletion of budgets, categories, and transactions

This commit is contained in:
William Brawner 2024-04-20 21:14:48 -06:00
parent ef1deaf19b
commit 689dbc39e2
7 changed files with 74 additions and 11 deletions

View file

@ -181,6 +181,15 @@ fun Application.budgetWebRoutes(
)
}
}
route("/delete") {
post {
val user = userService.user(requireSession().userId)
val budgetId = call.parameters.getOrFail("id")
budgetService.delete(budgetId = budgetId, userId = user.id)
call.respondRedirect("/")
}
}
}
}
}

View file

@ -209,6 +209,16 @@ fun Application.categoryWebRoutes(
}
}
}
route("/delete") {
post {
val user = userService.user(requireSession().userId)
val categoryId = call.parameters.getOrFail("id")
categoryService.delete(categoryId = categoryId, userId = user.id)
val budgetId = call.parameters.getOrFail("budgetId")
call.respondRedirect("/budgets/$budgetId")
}
}
}
}
}

View file

@ -254,6 +254,16 @@ fun Application.transactionWebRoutes(
}
}
}
route("/delete") {
post {
val user = userService.user(requireSession().userId)
val transactionId = call.parameters.getOrFail("id")
val urlBudgetId = call.parameters.getOrFail("budgetId")
transactionService.delete(transactionId = transactionId, userId = user.id)
call.respondRedirect("/budgets/${urlBudgetId}")
}
}
}
}
}
@ -313,4 +323,3 @@ private fun Parameters.toTransactionRequest() = TransactionRequest(
)
private fun Instant.toHtmlInputString() = truncatedTo(ChronoUnit.MINUTES).toString().substringBefore(":00Z")

View file

@ -10,6 +10,7 @@ html, body {
:root {
--color-accent: #004800;
--color-error: #a80000;
--color-on-accent: #FFFFFF;
--color-on-background: #000000;
--color-on-dim: #222222;
@ -23,6 +24,7 @@ html, body {
@media all and (prefers-color-scheme: dark) {
:root {
--color-accent: #baff33;
--color-error: #ff4040;
--color-on-accent: #000000;
--color-on-background: #FFFFFF;
--color-on-dim: #888888;
@ -144,6 +146,11 @@ header.row {
color: var(--color-accent);
}
.button-danger {
background-color: var(--color-error);
color: var(--color-on-accent);
}
.center {
align-items: center;
display: flex;
@ -225,6 +232,10 @@ a {
font-size: 0.9rem;
}
.error {
color: var(--color-error);
}
@media all and (max-width: 600px) {
.hide-small {
display: none;

View file

@ -5,11 +5,22 @@
<header class="row">
<a id="hamburger" href="#sidebar">☰</a>
<h1>{{title}}</h1>
<a href="/budgets/{{budget.id}}/transactions/new"
class="button button-secondary">
<!-- TODO: Hide text on small widths -->
<span aria-description="New Transaction">+</span> <span class="hide-small" aria-hidden="true">New Transaction</span>
</a>
<div class="row">
<a href="/budgets/{{budget.id}}/transactions/new"
class="button button-secondary">
<span aria-description="New Transaction">+</span> <span class="hide-small" aria-hidden="true">New Transaction</span>
</a>
<a href="/budgets/{{budget.id}}/edit"
class="button button-secondary" style="margin-right: 10px;">
<span aria-description="Edit Budget">✎</span> <span class="hide-small" aria-hidden="true">Edit Budget</span>
</a>
<form action="/budgets/{{budget.id}}/delete" method="post">
<!-- TODO: Show confirmation dialog before actually deleting -->
<button class="button button-danger" style="margin-right: 10px;">
<span aria-description="Delete Budget">🗑</span> <span class="hide-small" aria-hidden="true">Delete Budget</span>
</button>
</form>
</div>
</header>
<p>{{budget.description}}</p>
<div class="card">

View file

@ -7,16 +7,23 @@
<a id="hamburger" href="#sidebar">☰</a>
<h1>{{title}}</h1>
<div class="row">
<a href="/budgets/{{budget.id}}/categories/{{category.category.id}}/edit"
class="button button-secondary" style="margin-right: 10px;">
<!-- TODO: Hide text on small widths -->
<span aria-description="Edit Category">✎</span> <span aria-hidden="true">Edit Category</span>
</a>
<a href="/budgets/{{budget.id}}/transactions/new?categoryId={{category.category.id}}"
class="button button-secondary">
<!-- TODO: Hide text on small widths -->
<span aria-description="New Transaction">+</span> <span aria-hidden="true">New Transaction</span>
</a>
<a href="/budgets/{{budget.id}}/categories/{{category.category.id}}/edit"
class="button button-secondary" style="margin-right: 10px;">
<!-- TODO: Hide text on small widths -->
<span aria-description="Edit Category">✎</span> <span aria-hidden="true">Edit Category</span>
</a>
<form action="/budgets/{{budget.id}}/categories/{{category.category.id}}/delete" method="post">
<!-- TODO: Show confirmation dialog before actually deleting -->
<button class="button button-danger" style="margin-right: 10px;">
<span aria-description="Delete Category">🗑</span> <span class="hide-small"
aria-hidden="true">Delete Category</span>
</button>
</form>
</div>
</header>
<p>{{category.category.description}}</p>

View file

@ -36,6 +36,12 @@
<span class="body-large">{{createdBy.username}}</span>
</a>
</li>
<li class="list-item">
<form action="/budgets/{{budget.id}}/transactions/{{transaction.id}}/delete" method="post">
<input style="margin-bottom: 0; margin-right: 10px;" type="submit"
class="button button-danger" value="Delete"/>
</form>
</li>
</ul>
</div>
</div>