List and download tender documents - worker auto translation to english job

This commit is contained in:
Mazyar
2026-05-10 02:14:53 +03:30
parent 567e20b19c
commit e136f0eaa7
11 changed files with 652 additions and 2 deletions
+69
View File
@@ -1,6 +1,10 @@
package tender
import (
"errors"
"mime"
"net/http"
"strconv"
"time"
"tm/pkg/logger"
"tm/pkg/response"
@@ -361,6 +365,71 @@ func (h *TenderHandler) GetDocumentSummaries(c echo.Context) error {
return response.Success(c, summaries, "Document summaries retrieved successfully")
}
// GetDocuments retrieves scraped documents for a tender
// @Summary Get scraped documents for a tender
// @Description Retrieve scraped document metadata for a specific tender
// @Tags Tenders
// @Produce json
// @Param id path string true "Tender ID"
// @Success 200 {object} response.APIResponse{data=TenderDocumentsResponse}
// @Failure 400 {object} response.APIResponse
// @Failure 404 {object} response.APIResponse
// @Failure 500 {object} response.APIResponse
// @Router /api/v1/tenders/{id}/documents [get]
func (h *TenderHandler) GetDocuments(c echo.Context) error {
id := c.Param("id")
if id == "" {
return response.BadRequest(c, "Tender ID is required", "ID parameter cannot be empty")
}
documents, err := h.service.GetDocuments(c.Request().Context(), id)
if err != nil {
return response.NotFound(c, "Tender documents not found")
}
return response.Success(c, documents, "Tender documents retrieved successfully")
}
// DownloadDocuments downloads all scraped documents for a tender
// @Summary Download scraped documents for a tender
// @Description Stream all scraped tender documents from storage as a ZIP archive
// @Tags Tenders
// @Produce application/zip
// @Param id path string true "Tender ID"
// @Success 200 {file} file
// @Failure 400 {object} response.APIResponse
// @Failure 404 {object} response.APIResponse
// @Failure 500 {object} response.APIResponse
// @Router /api/v1/tenders/{id}/documents/download [get]
func (h *TenderHandler) DownloadDocuments(c echo.Context) error {
id := c.Param("id")
if id == "" {
return response.BadRequest(c, "Tender ID is required", "ID parameter cannot be empty")
}
download, err := h.service.DownloadDocuments(c.Request().Context(), id)
if err != nil {
if errors.Is(err, ErrTenderDocumentNotFound) {
return response.NotFound(c, "Tender documents not found")
}
if errors.Is(err, ErrTenderDocumentStorageUnavailable) {
return response.InternalServerError(c, "Tender document storage is unavailable")
}
return response.InternalServerError(c, "Failed to download tender documents")
}
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