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 an anonymization report without avatarization job. #84

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

Comments

@youen
Copy link
Collaborator

youen commented Mar 31, 2024

Description

This API allows you to create an anonymization report without avatarization job.

Request

Method

POST

URL

/reports/from_data

Request Parameters

Parameter Description Required Example
dataset_id The ID of the dataset to create the report for. Yes 9107ea2b-45d7-42b7-a12d-8f696b80a6a8
avatars_dataset_id The ID of the avatars dataset to use for the report. Yes 12345678-9abc-def0-1234-56789abcdef
privacy_job_id The ID of the privacy job to use for the report. Yes 12345678-9abc-def0-1234-56789abcdef
signal_job_id The ID of the signal job to use for the report. Yes 12345678-9abc-def0-1234-56789abcdef

Request Body

{
  "dataset_id": "9107ea2b-45d7-42b7-a12d-8f696b80a6a8",
  "avatars_dataset_id": "12345678-9abc-def0-1234-56789abcdef",
  "privacy_job_id": "12345678-9abc-def0-1234-56789abcdef",
  "signal_job_id": "12345678-9abc-def0-1234-56789abcdef"
}

Result

Result parameters

Parameter Description Example
id The ID of the report. 12345678-9abc-def0-1234-56789abcdef
user_id The ID of the user who created the report. 12345678-9abc-def0-1234-56789abcdef
job_id The ID of the job that created the report. 12345678-9abc-def0-1234-56789abcdef
created_at The date and time when the report was created. 2023-01-01T00:00:00Z
download_url The URL to download the report. https://example.com/reports/12345678-9abc-def0-1234-56789abcdef.csv

Result Body

{
  "id": "12345678-9abc-def0-1234-56789abcdef",
  "user_id": "12345678-9abc-def0-1234-56789abcdef",
  "job_id": "12345678-9abc-def0-1234-56789abcdef",
  "created_at": "2023-01-01T00:00:00Z",
  "download_url": "https://example.com/reports/12345678-9abc-def0-1234-56789abcdef.csv"
}

Example Curl Request

Request

curl -X POST \
-H "Content-Type: application/json" \
-d '{
  "dataset_id": "9107ea2b-45d7-42b7-a12d-8f696b80a6a8",
  "avatars_dataset_id": "12345678-9abc-def0-1234-56789abcdef",
  "privacy_job_id": "12345678-9abc-def0-1234-56789abcdef",
  "signal_job_id": "12345678-9abc-def0-1234-56789abcdef"
}' \
http://localhost:8080/reports/from_data

Curl Response

{
  "id": "12345678-9abc-def0-1234-56789abcdef",
  "user_id": "12345678-9abc-def0-1234-56789abcdef",
  "job_id": "12345678-9abc-def0-1234-56789abcdef",
  "created_at": "2023-01-01T00:00:00Z",
  "download_url": "https://example.com/reports/12345678-9abc-def0-1234-56789abcdef.csv"
}

Go server

Struct

type ReportFromDataCreateRequest struct {
  DatasetID         string `json:"dataset_id"`
  AvatarsDatasetID  string `json:"avatars_dataset_id"`
  PrivacyJobID      string `json:"privacy_job_id"`
  SignalJobID       string `json:"signal_job_id"`
}

Handler

func (s *Server) CreateReportFromData(w http.ResponseWriter, r *http.Request) {
  var req ReportFromDataCreateRequest
  if err := json.NewDecoder(r.Body).Decode(&req); err != nil {
    http.Error(w, err.Error(), http.StatusBadRequest)
    return
  }

  report, err := s.service.CreateReportFromData(req.DatasetID, req.AvatarsDatasetID, req.PrivacyJobID, req.SignalJobID)
  if err != nil {
    http.Error(w, err.Error(), http.StatusInternalServerError)
    return
  }

  w.Header().Set("Content-Type", "application/json")
  if err := json.NewEncoder(w).Encode(report); err != nil {
    http.Error(w, err.Error(), http.StatusInternalServerError)
    return
  }
}
``` validate:"required"`
	AvatarsDatasetID uuid.UUID `json:"avatars_dataset_id" validate:"required"`
	PrivacyJobID    uuid.UUID `json:"privacy_job_id" validate:"required"`
	SignalJobID     uuid.UUID `json:"signal_job_id" validate:"required"`
}

type CreateReportFromDataResponse struct {
	ID              uuid.UUID      `json:"id"`
	UserID          uuid.UUID      `json:"user_id"`
	JobID           uuid.UUID      `json:"job_id"`
	CreatedAt       *time.Time     `json:"created_at"`
	DownloadURL    *string        `json:"download_url"`
	ReportRequest  *ReportRequest `json:"report_request"`
	ReportMetadata *ReportMetadata `json:"report_metadata"`
}

Handler

func (s *Server) createReportFromData(ctx context.Context, w http.ResponseWriter, r *http.Request) error {
	var req CreateReportFromDataRequest

	if err := json.NewDecoder(r.Body).Decode(&req); err != nil {
		return err
	}

	if err := s.validator.Struct(req); err != nil {
		return err
	}

	reportID, err := s.service.CreateReportFromData(ctx, req.DatasetID, req.AvatarsDatasetID, req.PrivacyJobID, req.SignalJobID)
	if err != nil {
		return err
	}

	report, err := s.service.GetReport(ctx, reportID)
	if err != nil {
		return err
	}

	resp := CreateReportFromDataResponse{
		ID:              report.ID,
		UserID:          report.UserID,
		JobID:           report.JobID,
		CreatedAt:       report.CreatedAt,
		DownloadURL:    report.DownloadURL,
		ReportRequest:  report.ReportRequest,
		ReportMetadata: report.ReportMetadata,
	}

	return json.NewEncoder(w).Encode(resp)
}

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