mirror of
https://github.com/eduardolat/pgbackweb.git
synced 2026-05-14 15:38:25 -05:00
Add delete functionality for databases in dashboard
This commit is contained in:
@@ -0,0 +1,38 @@
|
||||
package databases
|
||||
|
||||
import (
|
||||
lucide "github.com/eduardolat/gomponents-lucide"
|
||||
"github.com/eduardolat/pgbackweb/internal/view/web/htmx"
|
||||
"github.com/google/uuid"
|
||||
"github.com/labstack/echo/v4"
|
||||
"github.com/maragudk/gomponents"
|
||||
"github.com/maragudk/gomponents/html"
|
||||
)
|
||||
|
||||
func (h *handlers) deleteDatabaseHandler(c echo.Context) error {
|
||||
ctx := c.Request().Context()
|
||||
|
||||
databaseID, err := uuid.Parse(c.Param("databaseID"))
|
||||
if err != nil {
|
||||
return htmx.RespondToastError(c, err.Error())
|
||||
}
|
||||
|
||||
if err = h.servs.DatabasesService.DeleteDatabase(ctx, databaseID); err != nil {
|
||||
return htmx.RespondToastError(c, err.Error())
|
||||
}
|
||||
|
||||
return htmx.RespondRefresh(c)
|
||||
}
|
||||
|
||||
func deleteDatabaseButton(databaseID uuid.UUID) gomponents.Node {
|
||||
return html.Div(
|
||||
html.Class("inline-block tooltip tooltip-right"),
|
||||
html.Data("tip", "Delete database"),
|
||||
html.Button(
|
||||
htmx.HxDelete("/dashboard/databases/"+databaseID.String()),
|
||||
htmx.HxConfirm("Are you sure you want to delete this database?"),
|
||||
html.Class("btn btn-error btn-square btn-sm btn-ghost"),
|
||||
lucide.Trash(),
|
||||
),
|
||||
)
|
||||
}
|
||||
@@ -52,7 +52,10 @@ func indexListDatabases(
|
||||
trs := []gomponents.Node{}
|
||||
for _, database := range databases {
|
||||
trs = append(trs, html.Tr(
|
||||
html.Td(),
|
||||
html.Td(
|
||||
html.Class("w-[40px]"),
|
||||
deleteDatabaseButton(database.ID),
|
||||
),
|
||||
html.Td(component.SpanText(database.Name)),
|
||||
html.Td(component.SpanText("PostgreSQL "+database.PgVersion)),
|
||||
html.Td(
|
||||
|
||||
@@ -23,4 +23,5 @@ func MountRouter(
|
||||
parent.GET("/list", h.indexListDatabasesHandler)
|
||||
parent.POST("", h.createDatabaseHandler)
|
||||
parent.POST("/test", h.testDatabaseHandler)
|
||||
parent.DELETE("/:databaseID", h.deleteDatabaseHandler)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user