45 lines
1.2 KiB
Go
45 lines
1.2 KiB
Go
package scraper
|
|
|
|
import (
|
|
"tm/pkg/response"
|
|
|
|
"github.com/labstack/echo/v4"
|
|
)
|
|
|
|
// Handler handles HTTP requests for scraper operations
|
|
type Handler struct {
|
|
service Service
|
|
}
|
|
|
|
// NewHandler creates a new scraper handler
|
|
func NewHandler(service Service) *Handler {
|
|
return &Handler{
|
|
service: service,
|
|
}
|
|
}
|
|
|
|
// ScrapeDocuments handles document scraping requests
|
|
// @Summary Scrape documents from external source
|
|
// @Description Scrapes documents from TendSign and uploads them to MinIO storage
|
|
// @Tags Admin-Scraper
|
|
// @Accept json
|
|
// @Produce json
|
|
// @Param request body ScrapeRequestForm true "Scraping request information"
|
|
// @Success 200 {object} response.Response{data=ScrapeResponse}
|
|
// @Failure 400 {object} response.Response
|
|
// @Failure 500 {object} response.Response
|
|
// @Router /admin/v1/scraper/download [post]
|
|
func (h *Handler) ScrapeDocuments(c echo.Context) error {
|
|
form, err := response.Parse[ScrapeRequestForm](c)
|
|
if err != nil {
|
|
return response.ValidationError(c, "Invalid request data", err.Error())
|
|
}
|
|
|
|
result, err := h.service.ScrapeDocuments(c.Request().Context(), form)
|
|
if err != nil {
|
|
return response.InternalServerError(c, "Failed to scrape documents")
|
|
}
|
|
|
|
return response.Success(c, result, "Documents scraped and uploaded successfully")
|
|
}
|