Skip to content

Commit

Permalink
wip: show account
Browse files Browse the repository at this point in the history
  • Loading branch information
katallaxie committed May 24, 2024
1 parent 7d05078 commit 118735d
Show file tree
Hide file tree
Showing 10 changed files with 127 additions and 11 deletions.
1 change: 1 addition & 0 deletions cmd/web/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ func (s *WebSrv) Start(ctx context.Context, ready server.ReadyFunc, run server.R
app.Get("/accounts", handlers.ListAccounts())
app.Get("/accounts/new", handlers.NewAccount())
app.Post("/accounts/create", handlers.CreateAccount())
app.Get("/accounts/:id", handlers.ShowAccount())

// Users handler
app.Get("/users", handlers.ListUsers())
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 @@ -83,3 +83,8 @@ func (h *handlers) ListUsers() fiber.Handler {
func (h *handlers) CreateAccount() fiber.Handler {
return htmx.NewHxControllerHandler(accounts.NewCreateController(h.db))
}

// ShowAccount ...
func (h *handlers) ShowAccount() fiber.Handler {
return htmx.NewHxControllerHandler(accounts.NewShowAccountController(h.db))
}
9 changes: 0 additions & 9 deletions internal/web/controllers/accounts/create.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package accounts

import (
"fmt"

"github.com/go-playground/validator/v10"
"github.com/google/uuid"
"github.com/nats-io/jwt"
Expand Down Expand Up @@ -50,13 +48,6 @@ func (l *CreateControllerImpl) Prepare() error {
return nil
}

// Error ...
func (l *CreateControllerImpl) Error(err error) error {
fmt.Println(err)

return err
}

// Post ...
func (l *CreateControllerImpl) Post() error {
account := models.Account{
Expand Down
File renamed without changes.
119 changes: 119 additions & 0 deletions internal/web/controllers/accounts/show.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
package accounts

import (
"fmt"

"github.com/google/uuid"
htmx "github.com/zeiss/fiber-htmx"
"github.com/zeiss/fiber-htmx/components/buttons"
"github.com/zeiss/fiber-htmx/components/cards"
"github.com/zeiss/typhoon/internal/api/models"
"github.com/zeiss/typhoon/internal/utils"
"github.com/zeiss/typhoon/internal/web/components"
"github.com/zeiss/typhoon/internal/web/ports"
)

// ShowAccountControllerImpl ...
type ShowAccountControllerImpl struct {
ID uuid.UUID `json:"name" form:"name" validate:"required:uuid"`

ports.Accounts
htmx.DefaultController
}

// NewShowAccountController ...
func NewShowAccountController(db ports.Accounts) *ShowAccountControllerImpl {
return &ShowAccountControllerImpl{
Accounts: db,
DefaultController: htmx.DefaultController{},
}
}

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

acc := models.Account{ID: l.ID}

err = l.GetAccount(l.Context(), &acc)
if err != nil {
return err
}

return htmx.RenderComp(
l.Ctx(),
components.Page(
components.PageProps{},
components.Layout(
components.LayoutProps{},
cards.CardBordered(
cards.CardProps{},
cards.Body(
cards.BodyProps{},
cards.Title(
cards.TitleProps{},
htmx.Text("Overview"),
),
htmx.Div(
htmx.H1(
htmx.Text(acc.Name),
),
htmx.P(
htmx.Text(utils.PtrStr(acc.Description)),
),
htmx.Div(
htmx.ClassNames{
"flex": true,
"flex-col": true,
"py-2": true,
},
htmx.H4(
htmx.ClassNames{
"text-gray-500": true,
},
htmx.Text("Created at"),
),
htmx.H3(
htmx.Text(
acc.CreatedAt.Format("2006-01-02 15:04:05"),
),
),
),
htmx.Div(
htmx.ClassNames{
"flex": true,
"flex-col": true,
"py-2": true,
},
htmx.H4(
htmx.ClassNames{
"text-gray-500": true,
},
htmx.Text("Updated at"),
),
htmx.H3(
htmx.Text(
acc.UpdatedAt.Format("2006-01-02 15:04:05"),
),
),
),
),
cards.Actions(
cards.ActionsProps{},
buttons.Outline(
buttons.ButtonProps{},
htmx.HxDelete(fmt.Sprintf("/account/%s", acc.ID)),
htmx.HxConfirm("Are you sure you want to delete this lens?"),
htmx.Text("Delete"),
),
),
),
),
),
),
)

}
File renamed without changes.
File renamed without changes.
File renamed without changes.
4 changes: 2 additions & 2 deletions internal/web/ports/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ type Handlers interface {
NewAccount() fiber.Handler
// CreateAccount ...
CreateAccount() fiber.Handler
// // ShowAccount ...
// ShowAccount() fiber.Handler
// ShowAccount ...
ShowAccount() fiber.Handler
// // DeleteAccount ...
// DeleteAccount() fiber.Handler
// ListUsers ...
Expand Down

0 comments on commit 118735d

Please sign in to comment.