tender single document download
This commit is contained in:
@@ -453,12 +453,14 @@ func (h *TenderHandler) GetDocuments(c echo.Context) error {
|
||||
return response.Success(c, documents, "Tender documents retrieved successfully")
|
||||
}
|
||||
|
||||
// DownloadDocuments downloads all scraped documents for a tender
|
||||
// DownloadDocuments downloads scraped documents for a tender
|
||||
// @Summary Download scraped documents for a tender
|
||||
// @Description Stream all scraped tender documents from storage as a ZIP archive
|
||||
// @Description Stream all scraped tender documents as a ZIP archive, or pass filename to download a single document
|
||||
// @Tags Tenders
|
||||
// @Produce application/zip
|
||||
// @Produce application/octet-stream
|
||||
// @Param id path string true "Tender ID"
|
||||
// @Param filename query string false "Document filename (from GET /documents); when set, returns that file instead of a ZIP"
|
||||
// @Success 200 {file} file
|
||||
// @Failure 400 {object} response.APIResponse
|
||||
// @Failure 404 {object} response.APIResponse
|
||||
@@ -470,6 +472,10 @@ func (h *TenderHandler) DownloadDocuments(c echo.Context) error {
|
||||
return response.BadRequest(c, "Tender ID is required", "ID parameter cannot be empty")
|
||||
}
|
||||
|
||||
if filename := strings.TrimSpace(c.QueryParam("filename")); filename != "" {
|
||||
return h.streamDocumentDownload(c, id, filename)
|
||||
}
|
||||
|
||||
download, err := h.service.DownloadDocuments(c.Request().Context(), id)
|
||||
if err != nil {
|
||||
if errors.Is(err, ErrTenderDocumentNotFound) {
|
||||
@@ -493,6 +499,30 @@ func (h *TenderHandler) DownloadDocuments(c echo.Context) error {
|
||||
return c.Stream(http.StatusOK, download.ContentType, download.Reader)
|
||||
}
|
||||
|
||||
func (h *TenderHandler) streamDocumentDownload(c echo.Context, tenderID, filename string) error {
|
||||
download, err := h.service.DownloadDocument(c.Request().Context(), tenderID, filename)
|
||||
if err != nil {
|
||||
if errors.Is(err, ErrTenderDocumentNotFound) {
|
||||
return response.NotFound(c, "Tender document not found")
|
||||
}
|
||||
if errors.Is(err, ErrTenderDocumentStorageUnavailable) {
|
||||
return response.InternalServerError(c, "Tender document storage is unavailable")
|
||||
}
|
||||
return response.InternalServerError(c, "Failed to download tender document")
|
||||
}
|
||||
defer download.Reader.Close()
|
||||
|
||||
headers := c.Response().Header()
|
||||
headers.Set(echo.HeaderContentDisposition, mime.FormatMediaType("attachment", map[string]string{
|
||||
"filename": download.Filename,
|
||||
}))
|
||||
if download.Size > 0 {
|
||||
headers.Set(echo.HeaderContentLength, strconv.FormatInt(download.Size, 10))
|
||||
}
|
||||
|
||||
return c.Stream(http.StatusOK, download.ContentType, download.Reader)
|
||||
}
|
||||
|
||||
// GetAISummary retrieves the AI-generated overall summary for a tender
|
||||
// @Summary Get AI-generated tender summary
|
||||
// @Description Retrieve the AI-generated overall summary for a tender from the AI pipeline storage
|
||||
|
||||
Reference in New Issue
Block a user