CGI-FR / CGI-FR/SIGO

[FEAT][API] Download a report

Open
#85 0 comments 0 reactions 0 assignees View on GitHub
api octopize
Dominant language
Go
Stars
6
Forks
0
PR merge metrics
No merged PRs in 30d

Description

## Description
Allow to download a report
## Request

### Method
GET

### URL
/reports/:id/download
### Request Parameters
- id: the report ID, required

### Request Body
None

## Result
### Result parameters
None

### Result Body
The report file

## Example Curl Request

### Request
```
curl -X GET "http://localhost:8080/reports/:id/download"
```

### Curl Response
```
(file content)
```

## Go server

### Struct
```go
type DownloadReportRequest struct {
ID string `json:"id" format:"uuid"`
}
```

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

report, err := s.store.GetReport(req.ID)
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}

// Serve the report file
w.Header().Set("Content-Type", "application/octet-stream")
w.Header().Set("Content-Disposition", fmt.Sprintf("attachment; filename=%s.pdf", report.Name))
w.Write(report.Data)
}
```
}

w.Header().Set("Content-Type", "application/octet-stream")
w.Header().Set("Content-Disposition", fmt.Sprintf("attachment; filename=\"%s\"", report.Name))
if _, err := w.Write(report.Data); err != nil {
http.Error(w, "Internal server error", http.StatusInternalServerError)
return
}
}
```
## Links

- [Reports.download_report](https://github.com/octopize/avatar-python/blob/0.6.2/avatars/api.py#L1048)
- [Any](https://github.com/octopize/avatar-python/blob/0.6.2/avatars/api.py#L1048)

## 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

Open the contributing guide

Research direction

Start by reading the linked Reports.download_report implementation in avatars/api.py, then locate the Go server's report routes and handleDownloadReport entry point. The work is complete when GET /reports/:id/download retrieves the requested report and returns its file content with the documented download headers.

Written by the indexing model from the issue text.

Assessment

Tech stack
go
Domain
api, backend
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.