feat: change email, export my data, delete account (with data anonymization)
This commit is contained in:
1 parent
bb191c389a
commit
10a66cd979
123 files changed
+10789
-76
No files matched your search
@@ -0,0 +1,44 @@
|
||||
package user
|
||||
|
||||
import (
|
||||
"RenewCMS/api/pkg/apperr"
|
||||
"RenewCMS/api/pkg/claims"
|
||||
"RenewCMS/internal/infrastructure/useCases"
|
||||
"context"
|
||||
"errors"
|
||||
"net/http"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
type ExportHandler struct {
|
||||
ExportUseCase *useCases.ExportUserDataUseCase
|
||||
}
|
||||
|
||||
func NewExportHandler(export *useCases.ExportUserDataUseCase) *ExportHandler {
|
||||
return &ExportHandler{ExportUseCase: export}
|
||||
}
|
||||
|
||||
func (h *ExportHandler) Export(w http.ResponseWriter, r *http.Request) {
|
||||
userId, ok := claims.UserId(r)
|
||||
if !ok {
|
||||
http.Error(w, apperr.UnauthorizedErrorMessage, http.StatusUnauthorized)
|
||||
return
|
||||
}
|
||||
|
||||
archive, err := h.ExportUseCase.Export(r.Context(), userId)
|
||||
if errors.Is(err, context.Canceled) || errors.Is(err, context.DeadlineExceeded) {
|
||||
http.Error(w, "Service unavailable", http.StatusServiceUnavailable)
|
||||
return
|
||||
}
|
||||
if err != nil {
|
||||
http.Error(w, "Internal server error", http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
w.Header().Set("Content-Type", "application/zip")
|
||||
w.Header().Set("Cache-Control", "no-store")
|
||||
w.Header().Set("Content-Disposition", "attachment; filename=\""+archive.Filename+"\"")
|
||||
w.Header().Set("Content-Length", strconv.Itoa(len(archive.Content)))
|
||||
w.WriteHeader(http.StatusOK)
|
||||
_, _ = w.Write(archive.Content)
|
||||
}
|
||||
Reference in new issue
Block a user