Skip to content

[FEAT][API] Create an anonymization report from batch job identifiers. #83

@youen

Description

@youen

Description

The report will be generated with the worst privacy_metrics and the mean signal_metrics.

Request

Method

POST

URL

/reports/from_batch

Request Parameters

Parameter Description Required Example
avatarization_batch_job_id Avatarization Batch Job Id Yes 1b2b39b9-b2db-4b96-a2a5-bb7a1e272505
privacy_batch_job_id Privacy Batch Job Id Yes 8f72e6de-e2f5-4b6b-8f56-f168f162b2f3
signal_batch_job_id Signal Batch Job Id Yes 8f72e6de-e2f5-4b6b-8f56-f168f162b2f3

Request Body

JSON

Result

Result parameters

Parameter Description
id Id
user_id User Id
job_id Job Id
created_at Created At
download_url Download Url

Result Body

JSON

Example Curl Request

Request

curl -X POST \
  http://localhost:8080/reports/from_batch \
  -H 'Content-Type: application/json' \
  -d '{
    "avatarization_batch_job_id": "1b2b39b9-b2db-4b96-a2a5-bb7a1e272505",
    "privacy_batch_job_id": "8f72e6de-e2f5-4b6b-8f56-f168f162b2f3",
    "signal_batch_job_id": "8f72e6de-e2f5-4b6b-8f56-f168f162b2f3"
}'

Curl Response

{
  "id": "1b2b39b9-b2db-4b96-a2a5-bb7a1e272505",
  "user_id": "8f72e6de-e2f5-4b6b-8f56-f168f162b2f3",
  "job_id": "8f72e6de-e2f5-4b6b-8f56-f168f162b2f3",
  "created_at": "2023-03-08T15:31:25.336Z",
  "download_url": "https://example.com/api/v1/reports/1b2b39b9-b2db-4b96-a2a5-bb7a1e272505/download"
}

Go server

Struct

type CreateReportFromBatchRequest struct {
    AvatarizationBatchJobID   uuid.UUID `json:"avatarization_batch_job_id"`
    PrivacyBatchJobID        uuid.UUID `json:"privacy_batch_job_id"`
    SignalBatchJobID         uuid.UUID `json:"signal_batch_job_id"`
}

type CreateReportFromBatchResponse 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"`
}

Handler

func (h *handler) createReportFromBatch(w http.ResponseWriter, r *http.Request) {
    var req CreateReportFromBatchRequest
    if err := json.NewDecoder(r.Body).Decode(&req); err != nil {
        http.Error(w, err.Error(), http.StatusBadRequest)
        return
    }

    report, err := h.service.CreateReportFromBatch(r.Context(), &req)
    if err != nil {
        http.Error(w, err.Error(), http.StatusInternalServerError)
        return
    }

    resp := CreateReportFromBatchResponse{
        ID:                      report.ID,
        UserID:                  report.UserID,
        JobID:                   report.JobID,
        CreatedAt:               report.CreatedAt,
        DownloadURL:            report.DownloadURL,
    }

    if err := json.NewEncoder(w).Encode(resp); err != nil {
        http.Error(w, err.Error(), http.StatusInternalServerError)
        return
    }
}
```_job_id"`
	SignalBatchJobID       UUID `json:"signal_batch_job_id"`
}

Handler

func (s *Server) createReportFromBatch(w http.ResponseWriter, r *http.Request) {
	ctx := r.Context()

	var req ReportFromBatchCreateRequest
	if err := json.NewDecoder(r.Body).Decode(&req); err != nil {
		http.Error(w, err.Error(), http.StatusBadRequest)
		return
	}

	report, err := s.reportService.CreateFromBatch(ctx, req.AvatarizationBatchJobID, req.PrivacyBatchJobID, req.SignalBatchJobID)
	if err != nil {
		http.Error(w, err.Error(), http.StatusInternalServerError)
		return
	}

	if err := json.NewEncoder(w).Encode(report); err != nil {
		http.Error(w, err.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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions