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] Download a report #85

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

[FEAT][API] Download a report #85

youen opened this issue Mar 31, 2024 · 0 comments

Comments

@youen
Copy link
Collaborator

youen commented Mar 31, 2024

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

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

Handler

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