feat(budget): rename description to name
All checks were successful
Build and Push Docker Image / Build-And-Push-Docker-Image (push) Successful in 1m25s
All checks were successful
Build and Push Docker Image / Build-And-Push-Docker-Image (push) Successful in 1m25s
This commit is contained in:
@@ -27,9 +27,9 @@ func NewDbSqlite(db *sqlx.DB) *DbSqlite {
|
|||||||
|
|
||||||
func (db DbSqlite) Insert(ctx context.Context, budget Budget) (*Budget, error) {
|
func (db DbSqlite) Insert(ctx context.Context, budget Budget) (*Budget, error) {
|
||||||
r, err := db.db.ExecContext(ctx, `
|
r, err := db.db.ExecContext(ctx, `
|
||||||
INSERT INTO budget (id, user_id, description, value, created_at, created_by, updated_at, updated_by)
|
INSERT INTO budget (id, user_id, name, value, created_at, created_by, updated_at, updated_by)
|
||||||
VALUES (?, ?, ?, ?, ?, ?, ?, ?)`,
|
VALUES (?, ?, ?, ?, ?, ?, ?, ?)`,
|
||||||
budget.Id, budget.UserId, budget.Description, budget.Value, budget.CreatedAt, budget.CreatedBy, budget.UpdatedAt, budget.UpdatedBy,
|
budget.Id, budget.UserId, budget.Name, budget.Value, budget.CreatedAt, budget.CreatedBy, budget.UpdatedAt, budget.UpdatedBy,
|
||||||
)
|
)
|
||||||
err = core.TransformAndLogDbError(ctx, "budget", r, err)
|
err = core.TransformAndLogDbError(ctx, "budget", r, err)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -42,13 +42,13 @@ func (db DbSqlite) Insert(ctx context.Context, budget Budget) (*Budget, error) {
|
|||||||
func (db DbSqlite) Update(ctx context.Context, budget Budget) (*Budget, error) {
|
func (db DbSqlite) Update(ctx context.Context, budget Budget) (*Budget, error) {
|
||||||
_, err := db.db.ExecContext(ctx, `
|
_, err := db.db.ExecContext(ctx, `
|
||||||
UPDATE budget
|
UPDATE budget
|
||||||
SET description = ?,
|
SET name = ?,
|
||||||
value = ?,
|
value = ?,
|
||||||
updated_at = ?,
|
updated_at = ?,
|
||||||
updated_by = ?
|
updated_by = ?
|
||||||
WHERE user_id = ?
|
WHERE user_id = ?
|
||||||
AND id = ?`,
|
AND id = ?`,
|
||||||
budget.Description, budget.Value, budget.UpdatedAt, budget.UpdatedBy, budget.UserId, budget.Id)
|
budget.Name, budget.Value, budget.UpdatedAt, budget.UpdatedBy, budget.UserId, budget.Id)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
slog.ErrorContext(ctx, "SQL error UpdateUser", "err", err)
|
slog.ErrorContext(ctx, "SQL error UpdateUser", "err", err)
|
||||||
|
|||||||
@@ -50,7 +50,7 @@ func (h HandlerImpl) handlePage() http.HandlerFunc {
|
|||||||
|
|
||||||
budgets, err := h.s.GetAll(r.Context(), user)
|
budgets, err := h.s.GetAll(r.Context(), user)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
core.HandleError(w, r, err)
|
h.r.RenderLayout(r, w, core.ErrorComp(err), user)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -134,7 +134,7 @@ func (h HandlerImpl) handlePost() http.HandlerFunc {
|
|||||||
|
|
||||||
input := Budget{
|
input := Budget{
|
||||||
Id: id,
|
Id: id,
|
||||||
Description: r.FormValue("name"),
|
Name: r.FormValue("name"),
|
||||||
Value: value,
|
Value: value,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -63,7 +63,7 @@ func (s ServiceImpl) Update(ctx context.Context, user *auth_types.User, input Bu
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
budget.Description = input.Description
|
budget.Name = input.Name
|
||||||
budget.Value = input.Value
|
budget.Value = input.Value
|
||||||
|
|
||||||
if user.Id != budget.UserId {
|
if user.Id != budget.UserId {
|
||||||
@@ -107,7 +107,7 @@ func (s ServiceImpl) GetAll(ctx context.Context, user *auth_types.User) ([]Budge
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (s ServiceImpl) isBudgetValid(budget Budget) bool {
|
func (s ServiceImpl) isBudgetValid(budget Budget) bool {
|
||||||
err := core.ValidateString(budget.Description, "description")
|
err := core.ValidateString(budget.Name, "description")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -59,7 +59,7 @@ templ editNew() {
|
|||||||
|
|
||||||
templ edit(budget Budget) {
|
templ edit(budget Budget) {
|
||||||
<div class="flex flex-col h-full">
|
<div class="flex flex-col h-full">
|
||||||
@core.Breadcrumb([]string{"Home", "Budget", budget.Description}, []string{"/", "/budget", "/budget/" + budget.Id.String()})
|
@core.Breadcrumb([]string{"Home", "Budget", budget.Name}, []string{"/", "/budget", "/budget/" + budget.Id.String()})
|
||||||
<div class="flex justify-center items-center flex-1">
|
<div class="flex justify-center items-center flex-1">
|
||||||
<form
|
<form
|
||||||
hx-post={ "/budget/" + budget.Id.String() }
|
hx-post={ "/budget/" + budget.Id.String() }
|
||||||
@@ -70,7 +70,7 @@ templ edit(budget Budget) {
|
|||||||
autofocus
|
autofocus
|
||||||
name="name"
|
name="name"
|
||||||
type="text"
|
type="text"
|
||||||
value={ budget.Description }
|
value={ budget.Name }
|
||||||
class="bg-white input datetime col-span-3"
|
class="bg-white input datetime col-span-3"
|
||||||
/>
|
/>
|
||||||
<label for="value" class="text-sm text-gray-500">Value</label>
|
<label for="value" class="text-sm text-gray-500">Value</label>
|
||||||
@@ -80,15 +80,11 @@ templ edit(budget Budget) {
|
|||||||
value={ budget.Value / 100 }
|
value={ budget.Value / 100 }
|
||||||
class="bg-white input col-span-3"
|
class="bg-white input col-span-3"
|
||||||
/>
|
/>
|
||||||
<div class="flex gap-6 justify-end col-span-4">
|
<div class="flex flex-row-reverse gap-6 justify-end col-span-4">
|
||||||
<button
|
<button type="submit" class="col-start-4 p-2 px-4 decoration-yellow-400 decoration-[0.25rem] hover:bg-gray-200 rounded-lg hover:underline flex items-center gap-2 justify-center">
|
||||||
hx-delete={ "/budget/" + budget.Id.String() }
|
@svg.Save()
|
||||||
hx-confirm={ "Do you really want to delete '" + budget.Description + "'" }
|
|
||||||
class="col-start-4 p-2 px-4 decoration-yellow-400 decoration-[0.25rem] hover:bg-red-50 rounded-lg hover:underline flex items-center gap-2 justify-center"
|
|
||||||
>
|
|
||||||
@svg.Delete()
|
|
||||||
<span>
|
<span>
|
||||||
Delete
|
Save
|
||||||
</span>
|
</span>
|
||||||
</button>
|
</button>
|
||||||
<a href="/budget" class="col-start-3 p-2 px-4 decoration-yellow-400 decoration-[0.25rem] hover:bg-gray-200 rounded-lg hover:underline flex items-center gap-2 justify-center">
|
<a href="/budget" class="col-start-3 p-2 px-4 decoration-yellow-400 decoration-[0.25rem] hover:bg-gray-200 rounded-lg hover:underline flex items-center gap-2 justify-center">
|
||||||
@@ -99,10 +95,14 @@ templ edit(budget Budget) {
|
|||||||
Cancel
|
Cancel
|
||||||
</span>
|
</span>
|
||||||
</a>
|
</a>
|
||||||
<button type="submit" class="col-start-4 p-2 px-4 decoration-yellow-400 decoration-[0.25rem] hover:bg-gray-200 rounded-lg hover:underline flex items-center gap-2 justify-center">
|
<button
|
||||||
@svg.Save()
|
hx-delete={ "/budget/" + budget.Id.String() }
|
||||||
|
hx-confirm={ "Do you really want to delete '" + budget.Name + "'" }
|
||||||
|
class="col-start-4 p-2 px-4 decoration-yellow-400 decoration-[0.25rem] hover:bg-red-50 rounded-lg hover:underline flex items-center gap-2 justify-center"
|
||||||
|
>
|
||||||
|
@svg.Delete()
|
||||||
<span>
|
<span>
|
||||||
Save
|
Delete
|
||||||
</span>
|
</span>
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
@@ -126,7 +126,7 @@ templ newItem() {
|
|||||||
templ item(budget Budget) {
|
templ item(budget Budget) {
|
||||||
<a href={ "/budget/" + budget.Id.String() } class="p-5 w-64 h-64 flex gap-10 active:bg-gray-200 flex-col justify-center items-center hover:bg-gray-100 transition-all cursor-pointer rounded-lg bg-gray-50 border-1 border-gray-300">
|
<a href={ "/budget/" + budget.Id.String() } class="p-5 w-64 h-64 flex gap-10 active:bg-gray-200 flex-col justify-center items-center hover:bg-gray-100 transition-all cursor-pointer rounded-lg bg-gray-50 border-1 border-gray-300">
|
||||||
<span>
|
<span>
|
||||||
{ budget.Description }
|
{ budget.Name }
|
||||||
</span>
|
</span>
|
||||||
<span>
|
<span>
|
||||||
{ core.FormatEuros(budget.Value) }
|
{ core.FormatEuros(budget.Value) }
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ type Budget struct {
|
|||||||
Id uuid.UUID `db:"id"`
|
Id uuid.UUID `db:"id"`
|
||||||
UserId uuid.UUID `db:"user_id"`
|
UserId uuid.UUID `db:"user_id"`
|
||||||
|
|
||||||
Description string `db:"description"`
|
Name string `db:"name"`
|
||||||
Value int64 `db:"value"`
|
Value int64 `db:"value"`
|
||||||
|
|
||||||
CreatedAt time.Time `db:"created_at"`
|
CreatedAt time.Time `db:"created_at"`
|
||||||
|
|||||||
@@ -97,3 +97,9 @@ templ navigation(path string) {
|
|||||||
<a class={ layoutLinkClass(strings.HasPrefix(path, "/budget")) } href="/budget">Budget</a>
|
<a class={ layoutLinkClass(strings.HasPrefix(path, "/budget")) } href="/budget">Budget</a>
|
||||||
</nav>
|
</nav>
|
||||||
}
|
}
|
||||||
|
|
||||||
|
templ ErrorComp(err error) {
|
||||||
|
<div>
|
||||||
|
The following error occured: { err.Error() }
|
||||||
|
</div>
|
||||||
|
}
|
||||||
|
|||||||
1
migration/011_budget_rename_description.up.sql
Normal file
1
migration/011_budget_rename_description.up.sql
Normal file
@@ -0,0 +1 @@
|
|||||||
|
ALTER TABLE "budget" RENAME COLUMN description TO name;
|
||||||
Reference in New Issue
Block a user