[FEAT][API] Create an anonymization report from batch job identifiers.
- Dominant language
- Go
- Stars
- 6
- Forks
- 0
- PR merge metrics
- No merged PRs in 30d
Description
## 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
```go
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
- [Reports.create_report_from_batch](https://github.com/octopize/avatar-python/blob/0.6.2/avatars/api.py#L1081)
- [ReportFromBatchCreate](https://github.com/octopize/avatar-python/blob/0.6.2/avatars/api.py#L1081)
- [Report](https://github.com/octopize/avatar-python/blob/0.6.2/avatars/api.py#L1081)
## Automated Issue Details
Dear visitor,
This issue has been automatically generated from the Octopize project [avatar-python](https://github.com/octopize/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
Contributor guide
Research direction
Start by locating the Go server's createReportFromBatch handler and report service, then compare the linked Reports.create_report_from_batch and ReportFromBatchCreate implementation in avatar-python. The endpoint is done when POST /reports/from_batch accepts the three batch job identifiers, creates the report using worst privacy_metrics and mean signal_metrics, and returns the documented JSON fields.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- go
- Domain
- api, backend
- Issue type
- Feature
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 38/100