Skip to content

Commit

Permalink
start client detail page
Browse files Browse the repository at this point in the history
  • Loading branch information
henriquepw committed Sep 26, 2024
1 parent b2d8c11 commit 0f80400
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 4 deletions.
22 changes: 19 additions & 3 deletions database/client_store.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,11 +101,12 @@ func (s *clientStore) Get(ctx context.Context, id string) (*types.Client, error)
row := s.db.QueryRowContext(ctx, query, id)
var c types.Client

var brithday, createdAt, updatedAt string
err := row.Scan(
&c.ID,
&c.Name,
&c.CPF,
&c.Brithday,
&brithday,
&c.Instagram,
&c.Phone,
&c.Email,
Expand All @@ -116,13 +117,28 @@ func (s *clientStore) Get(ctx context.Context, id string) (*types.Client, error)
&c.Address.Street,
&c.Address.Number,
&c.Address.Complement,
&c.CreatedAt,
&c.UpdatedAt,
&createdAt,
&updatedAt,
)
if err != nil {
return nil, err
}

c.Brithday, err = time.Parse(time.RFC3339, brithday)
if err != nil {
return nil, err
}

c.CreatedAt, err = time.Parse(time.RFC3339, createdAt)
if err != nil {
return nil, err
}

c.UpdatedAt, err = time.Parse(time.RFC3339, updatedAt)
if err != nil {
return nil, err
}

return &c, nil
}

Expand Down
12 changes: 12 additions & 0 deletions web/handlers/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,3 +65,15 @@ func (h *ClientHandler) CreateClientAction(w http.ResponseWriter, r *http.Reques
pages.EmployeeCreateForm(types.EmployeeCreateDTO{}, nil),
)
}

func (h *ClientHandler) ClientDetailPage(w http.ResponseWriter, r *http.Request) {
client, err := h.svc.GetClientById(r.Context(), r.PathValue("id"))
if err != nil {
httputil.RenderError(w, r, err, nil)
return
}

httputil.RenderPage(w, r, func(b bool) templ.Component {
return pages.ClientDetailPage(b, *client)
})
}
2 changes: 2 additions & 0 deletions web/services/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package services
import (
"context"
"fmt"
"log"
"time"

"github.com/henriquepw/imperium-tattoo/database"
Expand Down Expand Up @@ -71,6 +72,7 @@ func (s *clientService) CreateClient(ctx context.Context, payload types.ClientCr
func (s *clientService) GetClientById(ctx context.Context, id string) (*types.Client, *errors.ServerError) {
c, err := s.store.Get(ctx, id)
if err != nil {
log.Println(err)
return nil, errors.NotFound("Cliente não encontrado")
}

Expand Down
12 changes: 12 additions & 0 deletions web/view/pages/client_detail_page.templ
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package pages

import (
"github.com/henriquepw/imperium-tattoo/web/types"
"github.com/henriquepw/imperium-tattoo/web/view/layout"
)

templ ClientDetailPage(boosted bool, client types.Client) {
@layout.Dashbaord(client.Name, boosted) {
TODO
}
}
4 changes: 3 additions & 1 deletion web/view/pages/clients_page.templ
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ import (
// }
templ clientRow(i types.Client) {
<td>
{ i.Name }
<a class="underline text-accent-11" href={ templ.SafeURL("/clients/" + i.ID) }>
{ i.Name }
</a>
</td>
<td>
{ i.Email }
Expand Down
1 change: 1 addition & 0 deletions web/web.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ func (s *WebServer) Start() error {
clientHandler := handlers.NewClientHandler(clientSVC)
server.HandleFunc("GET /clients", clientHandler.ClientsPage)
server.HandleFunc("POST /clients/create", clientHandler.CreateClientAction)
server.HandleFunc("GET /clients/{id}", clientHandler.ClientDetailPage)

employeeSvc := services.NewEmployeeService(database.NewEmployeeRepo(s.db))
employeeHandler := handlers.NewEmployeeHandler(employeeSvc)
Expand Down

0 comments on commit 0f80400

Please sign in to comment.