Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FEAT][API] Create Anonymization Report #82

Open
youen opened this issue Mar 31, 2024 · 0 comments
Open

[FEAT][API] Create Anonymization Report #82

youen opened this issue Mar 31, 2024 · 0 comments

Comments

@youen
Copy link
Collaborator

youen commented Mar 31, 2024

Description

This endpoint allows you to create an anonymization report.

Request

Method

POST

URL

/reports

Request Parameters

Parameter Description Required example
job_id Id of the job that the report pertains to. Yes 0c40b016-0758-4043-a680-560f47d5a921
report_type Type of the report. Can be "avatarization", "privacy", or "signal". Yes "avatarization"

Request Body

(none)

Result

Result parameters

Parameter Description
id Id of the report.
user_id Id of the user who created the report.
job_id Id of the job that the report pertains to.
created_at Date and time when the report was created.
download_url URL to download the report.

Result Body

(none)

Example Curl Request

curl -X POST \
  http://localhost:8080/reports \
  -H 'Content-Type: application/json' \
  -d '{
    "job_id": "0c40b016-0758-4043-a680-560f47d5a921",
    "report_type": "avatarization"
  }'

Curl Response

{
  "id": "0c40b016-0758-4043-a680-560f47d5a921",
  "user_id": "0c40b016-0758-4043-a680-560f47d5a921",
  "job_id": "0c40b016-0758-4043-a680-560f47d5a921",
  "created_at": "2023-02-28T16:34:12.345Z",
  "download_url": "https://example.com/reports/0c40b016-0758-4043-a680-560f47d5a921.pdf"
}

Go server

Struct

type ReportCreateRequest struct {
	JobID      string `json:"job_id"`
	ReportType string `json:"report_type"`
}

Handler

func (h *Handler) createReport(w http.ResponseWriter, r *http.Request) {
	var req ReportCreateRequest
	if err := json.NewDecoder(r.Body).Decode(&req); err != nil {
		http.Error(w, "Invalid request body", http.StatusBadRequest)
		return
	}

	report, err := h.service.CreateReport(r.Context(), req.JobID, req.ReportType)
	if err != nil {
		http.Error(w, "Failed to create report", http.StatusInternalServerError)
		return
	}

	if err := json.NewEncoder(w).Encode(report); err != nil {
		http.Error(w, "Failed to encode response", http.StatusInternalServerError)
		return
	}
}
``` validate request body
	// ... 
	// create a new report 
	report, err := createReport(ctx, req)
    if err != nil {
        http.Error(w, "Internal server error", http.StatusInternalServerError)
        return
    }
// encode the response body
	if err := json.NewEncoder(w).Encode(report); err != nil {
		log.Printf("Error encoding response body: %v", err) 
		http.Error(w, "Internal server error", http.StatusInternalServerError)
		return
 }
}

Links

Automated Issue Details

Dear visitor,

This issue has been automatically generated from the Octopize project avatar-python to make SIGO compatible. Please vote with a thumbs up or thumbs down to assess the quality of the automatic generation.

Best regards,
The SIGO Team

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant