Files
query-orchestration/api/queryService/jobcollector.go
T

66 lines
1.8 KiB
Go
Raw Normal View History

2025-01-15 19:45:51 +00:00
package queryservice
import (
"fmt"
2025-01-15 19:45:51 +00:00
"net/http"
2025-01-23 14:56:20 +00:00
"queryorchestration/internal/job/collector"
2025-01-15 19:45:51 +00:00
"github.com/google/uuid"
2025-01-15 19:45:51 +00:00
"github.com/labstack/echo/v4"
"github.com/oapi-codegen/runtime/types"
2025-01-15 19:45:51 +00:00
)
func (s *Controllers) GetJobCollectorByJobId(ctx echo.Context, jobId types.UUID) error {
coll, err := s.svc.JobCollector.GetByJobID(ctx.Request().Context(), jobId)
if err != nil {
return echo.NewHTTPError(http.StatusNotFound, fmt.Sprintf("Unable to get collector: %s", err))
}
fields := make([]JobCollectorField, len(coll.Fields))
index := 0
for name, id := range coll.Fields {
fields[index] = JobCollectorField{
Name: name,
QueryId: id,
}
index++
}
return ctx.JSON(http.StatusOK, JobCollector{
JobId: coll.JobID,
MinimumCleanerVersion: coll.MinCleanVersion,
MinimumTextVersion: coll.MinTextVersion,
ActiveVersion: coll.ActiveVersion,
LatestVersion: coll.LatestVersion,
Fields: fields,
})
2025-01-15 19:45:51 +00:00
}
func (s *Controllers) UpdateJobCollectorByJobId(ctx echo.Context, jobId types.UUID) error {
2025-01-23 14:56:20 +00:00
req := JobCollectorUpdate{}
if err := ctx.Bind(&req); err != nil {
return echo.NewHTTPError(http.StatusBadRequest, err)
}
var fields *map[string]uuid.UUID
if req.Fields != nil {
fields := &map[string]uuid.UUID{}
for _, field := range *req.Fields {
(*fields)[field.Name] = field.QueryId
2025-01-23 14:56:20 +00:00
}
}
err := s.svc.JobCollector.UpdateByJobId(ctx.Request().Context(), &collector.UpdateParams{
JobID: jobId,
2025-01-23 14:56:20 +00:00
ActiveVersion: req.ActiveVersion,
MinCleanVersion: req.MinimumCleanerVersion,
MinTextVersion: req.MinimumTextVersion,
Fields: fields,
})
if err != nil {
return echo.NewHTTPError(http.StatusBadRequest, fmt.Sprintf("Unable to update query: %s", err))
}
return ctx.NoContent(http.StatusOK)
2025-01-15 19:45:51 +00:00
}