deleçao de contas web

This commit is contained in:
2026-10-30 23:25:38 -03:00
parent 61fde19133
commit f0560b1be4
16 changed files with 1250 additions and 10 deletions

View File

@@ -71,6 +71,7 @@ func NewHandler(db Pinger, svc *app.Service, cfg config.Config, logger *slog.Log
mux.Handle("GET /api/v1/accounts", a.auth(domain.RoleOwner, a.listAccounts))
mux.Handle("POST /api/v1/accounts", a.auth(domain.RoleOwner, a.createAccount))
mux.Handle("PATCH /api/v1/accounts/{id}", a.auth(domain.RoleOwner, a.updateAccount))
mux.Handle("DELETE /api/v1/accounts/{id}", a.auth(domain.RoleOwner, a.deleteAccount))
mux.Handle("POST /api/v1/accounts/{id}/reset-password", a.auth(domain.RoleOwner, a.resetPassword))
mux.HandleFunc("/", notFound)

View File

@@ -340,6 +340,22 @@ func (a *API) updateAccount(w http.ResponseWriter, r *http.Request) {
httpx.WriteJSON(w, http.StatusOK, toAccount(account))
}
func (a *API) deleteAccount(w http.ResponseWriter, r *http.Request) {
id, ok := pathID(w, r)
if !ok {
return
}
if id == sessionFrom(r).AccountID {
a.writeError(w, domain.InvalidState("você não pode excluir a própria conta"))
return
}
if err := a.svc.DeleteAccount(r.Context(), actorOf(r), id); err != nil {
a.writeError(w, err)
return
}
w.WriteHeader(http.StatusNoContent)
}
func (a *API) resetPassword(w http.ResponseWriter, r *http.Request) {
id, ok := pathID(w, r)
if !ok {