Skip to content

Commit

Permalink
wip: delete operator
Browse files Browse the repository at this point in the history
  • Loading branch information
katallaxie committed May 23, 2024
1 parent f1d964f commit 4af7a1c
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 2 deletions.
1 change: 1 addition & 0 deletions cmd/web/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ func (s *WebSrv) Start(ctx context.Context, ready server.ReadyFunc, run server.R
app.Get("/operators/new", handlers.NewOperator())
app.Post("/operators/new", handlers.CreateOperator())
app.Get("/operators/:id", handlers.ShowOperator())
app.Delete("/operators/:id", handlers.DeleteOperator())

err = app.Listen(s.cfg.Flags.Addr)
if err != nil {
Expand Down
5 changes: 5 additions & 0 deletions internal/web/adapters/handlers/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,3 +56,8 @@ func (h *handlers) CreateOperator() fiber.Handler {
func (h *handlers) ShowOperator() fiber.Handler {
return htmx.NewHxControllerHandler(operators.NewShowOperatorController(h.db))
}

// DeleteOperator ...
func (h *handlers) DeleteOperator() fiber.Handler {
return htmx.NewHxControllerHandler(operators.NewDeleteOperatorController(h.db))
}
43 changes: 43 additions & 0 deletions internal/web/controllers/operators/delete_operator_controller.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package operators

import (
"github.com/google/uuid"
htmx "github.com/zeiss/fiber-htmx"
"github.com/zeiss/typhoon/internal/api/models"
"github.com/zeiss/typhoon/internal/web/ports"
)

var _ = htmx.Controller(&DeleteOperatorController{})

// DeleteOperatorsController ...
type DeleteOperatorController struct {
ID uuid.UUID `json:"name" form:"name" validate:"required:uuid"`
ports.Operators
htmx.DefaultController
}

// NewDeleteOperatorController ...
func NewDeleteOperatorController(db ports.Operators) *DeleteOperatorController {
return &DeleteOperatorController{
Operators: db,
DefaultController: htmx.DefaultController{},
}
}

// Delete ...
func (l *DeleteOperatorController) Delete() error {
err := l.BindParams(l)
if err != nil {
return err
}

op := models.Operator{ID: l.ID}
err = l.DeleteOperator(l.Context(), &op)
if err != nil {
return err
}

htmx.HxRedirect(l.Ctx(), "/operators")

return nil
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package operators

import (
"fmt"

"github.com/google/uuid"
htmx "github.com/zeiss/fiber-htmx"
"github.com/zeiss/fiber-htmx/components/buttons"
Expand Down Expand Up @@ -100,9 +102,9 @@ func (l *ShowOperatorControllerImpl) Get() error {
),
cards.Actions(
cards.ActionsProps{},
buttons.OutlinePrimary(
buttons.Outline(
buttons.ButtonProps{},
htmx.HxDelete(""),
htmx.HxDelete(fmt.Sprintf("/operators/%s", op.ID)),
htmx.HxConfirm("Are you sure you want to delete this lens?"),
htmx.Text("Delete"),
),
Expand Down
2 changes: 2 additions & 0 deletions internal/web/ports/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,6 @@ type Handlers interface {
CreateOperator() fiber.Handler
// ShowOperator ...
ShowOperator() fiber.Handler
// DeleteOperator ...
DeleteOperator() fiber.Handler
}

0 comments on commit 4af7a1c

Please sign in to comment.