Skip to content

Commit

Permalink
deleting client procedure
Browse files Browse the repository at this point in the history
  • Loading branch information
henriquepw committed Nov 17, 2024
1 parent b9ee8d8 commit 3307bd0
Show file tree
Hide file tree
Showing 6 changed files with 66 additions and 5 deletions.
14 changes: 12 additions & 2 deletions static/css/input.css
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,19 @@
}

.btn-primary {
@apply flex items-center justify-center gap-1.5 h-9 px-3 rounded bg-accent-9;
@apply flex items-center justify-center gap-1.5 h-9 px-3 rounded;
@apply font-bold text-gray-12 text-center;
@apply transition-all hover:bg-accent-10 active:bg-accent-11 active:scale-95;
@apply transition-all active:scale-95;

@apply bg-accent-9 hover:bg-accent-10 active:bg-accent-11;
}

.btn-alert {
@apply flex items-center justify-center gap-1.5 h-9 px-3 rounded;
@apply font-bold text-gray-12 text-center;
@apply transition-all active:scale-95;

@apply bg-error-9 hover:bg-error-10 active:bg-error-11;
}

.input {
Expand Down
6 changes: 6 additions & 0 deletions web/db/client_procedures_store.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ type ClientProcedureStore interface {
Update(ctx context.Context, dto types.ClientProcedureUpdateDTO) error
List(ctx context.Context, clientID string) ([]types.ClientProcedure, error)
Get(ctx context.Context, procedureID string) (*types.ClientProcedure, error)
Delete(ctx context.Context, id string) error
}

type clientProcedureStore struct {
Expand Down Expand Up @@ -156,3 +157,8 @@ func (s *clientProcedureStore) Update(ctx context.Context, dto types.ClientProce

return error
}

func (s *clientProcedureStore) Delete(ctx context.Context, id string) error {
_, err := s.db.ExecContext(ctx, "DELETE FROM client_procedure WHERE id = ?", id)
return err
}
17 changes: 17 additions & 0 deletions web/handlers/client_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -198,3 +198,20 @@ func (h *ClientHandler) CreateClientProcedureAction(w http.ResponseWriter, r *ht
// pages.OobNewClient(*client),
)
}

func (h *ClientHandler) DeleteClientProcedureAction(w http.ResponseWriter, r *http.Request) {
id := r.PathValue("procedureId")
err := h.clientProcedureSVC.DeleteClientProcedure(r.Context(), id)
if err != nil {
httputil.RenderError(w, r, err, func(e errors.ServerError) templ.Component {
return pages.ClientProcessEditForm(e.Errors)
})
return
}

httputil.Render(
w, r, http.StatusOK,
pages.ClientProcessEditForm(nil),
pages.OobDeleteClientProcedure(id),
)
}
5 changes: 5 additions & 0 deletions web/services/client_procedure_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ type ClientProcedureService interface {
CreateClientProcedure(ctx context.Context, dto types.ClientProcedureCreateDTO) (*types.ClientProcedure, error)
EditClientProcedure(ctx context.Context, dto types.ClientProcedureUpdateDTO) (*types.ClientProcedure, error)
ListClientProcedures(ctx context.Context, clientID string) ([]types.ClientProcedure, error)
DeleteClientProcedure(ctx context.Context, id string) error
}

type clientProcedureService struct {
Expand Down Expand Up @@ -92,3 +93,7 @@ func (s *clientProcedureService) EditClientProcedure(ctx context.Context, dto ty

return p, nil
}

func (s *clientProcedureService) DeleteClientProcedure(ctx context.Context, id string) error {
return s.store.Delete(ctx, id)
}
28 changes: 25 additions & 3 deletions web/view/pages/client_detail_page.templ
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,10 @@ templ ClientProcessSection(id string, procedures []types.Procedure, clientProced
</section>
}

templ OobDeleteClientProcedure(id string) {
<template hx-swap-oob="outerHTML" id={ "client-procedure-" + id }></template>
}

templ OobUpdateClientProcedure(p types.ClientProcedure) {
<li
hx-swap-oob="outerHTML"
Expand Down Expand Up @@ -357,9 +361,27 @@ templ ClientProcessEditForm(errors map[string]string) {
XValue: "procedure?.description",
Error: errors["description"],
})
@ui.SubmitBtn("save", "Salvando...", "ml-auto") {
Salvar
}
<div class="flex justify-between">
<button
x-init="$watch('procedure', () => htmx.process($el))"
:hx-delete="`/clients/${clientId}/procedures/${procedure?.id}`"
hx-indicator="this"
class="btn-alert group"
type="button"
>
<div class="items-center gap-1.5 hidden group-[.htmx-request]:flex">
@ui.Icon("loader", "h-5 w-5 animate-spin")
Deletando...
</div>
<div class="flex gap-1.5 group-[.htmx-request]:hidden">
@ui.Icon("trash")
Deletar
</div>
</button>
@ui.SubmitBtn("save", "Salvando...", "ml-auto") {
Salvar
}
</div>
</form>
}

Expand Down
1 change: 1 addition & 0 deletions web/web.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ func (s *WebServer) Start() error {
server.HandleFunc("PUT /clients/{id}", clientHandler.EditClientAction)
server.HandleFunc("POST /clients/{id}/procedures", clientHandler.CreateClientProcedureAction)
server.HandleFunc("PUT /clients/{id}/procedures/{procedureId}", clientHandler.EditClientProcedureAction)
server.HandleFunc("DELETE /clients/{id}/procedures/{procedureId}", clientHandler.DeleteClientProcedureAction)

employeeStore := db.NewEmployeeStore(s.db)
employeeSvc := services.NewEmployeeService(employeeStore)
Expand Down

0 comments on commit 3307bd0

Please sign in to comment.