diff --git a/static/css/input.css b/static/css/input.css index ca751cd..c4c4b1f 100644 --- a/static/css/input.css +++ b/static/css/input.css @@ -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 { diff --git a/web/db/client_procedures_store.go b/web/db/client_procedures_store.go index 3017596..4ff5125 100644 --- a/web/db/client_procedures_store.go +++ b/web/db/client_procedures_store.go @@ -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 { @@ -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 +} diff --git a/web/handlers/client_handler.go b/web/handlers/client_handler.go index 3ee9b2b..bd81cbb 100644 --- a/web/handlers/client_handler.go +++ b/web/handlers/client_handler.go @@ -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), + ) +} diff --git a/web/services/client_procedure_service.go b/web/services/client_procedure_service.go index 71ad92d..c26c85b 100644 --- a/web/services/client_procedure_service.go +++ b/web/services/client_procedure_service.go @@ -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 { @@ -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) +} diff --git a/web/view/pages/client_detail_page.templ b/web/view/pages/client_detail_page.templ index 66145cf..e024c5e 100644 --- a/web/view/pages/client_detail_page.templ +++ b/web/view/pages/client_detail_page.templ @@ -266,6 +266,10 @@ templ ClientProcessSection(id string, procedures []types.Procedure, clientProced } +templ OobDeleteClientProcedure(id string) { + +} + templ OobUpdateClientProcedure(p types.ClientProcedure) {
  • + + @ui.SubmitBtn("save", "Salvando...", "ml-auto") { + Salvar + } + } diff --git a/web/web.go b/web/web.go index 80c3e97..9b5467f 100644 --- a/web/web.go +++ b/web/web.go @@ -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)