5b7160fe44
Job Collector * createstructure * mostupdatevalidation * repocollectorupdate * updateoutline * updatevalidation * scriptupdate * cleanupdockerignore * update * collectorupdateapi
80 lines
2.1 KiB
Go
80 lines
2.1 KiB
Go
package queryservice
|
|
|
|
import (
|
|
"fmt"
|
|
"net/http"
|
|
"queryorchestration/internal/job/collector"
|
|
|
|
"github.com/google/uuid"
|
|
"github.com/labstack/echo/v4"
|
|
)
|
|
|
|
func (s *Controllers) GetJobCollectorByJobId(ctx echo.Context, jobId string) error {
|
|
uid, err := uuid.Parse(jobId)
|
|
if err != nil {
|
|
return echo.NewHTTPError(http.StatusBadRequest, "Invalid ID")
|
|
}
|
|
|
|
coll, err := s.svc.JobCollector.GetByJobID(ctx.Request().Context(), uid)
|
|
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.String(),
|
|
}
|
|
index++
|
|
}
|
|
|
|
return ctx.JSON(http.StatusOK, JobCollector{
|
|
JobId: coll.JobID.String(),
|
|
MinimumCleanerVersion: coll.MinCleanVersion,
|
|
MinimumTextVersion: coll.MinTextVersion,
|
|
ActiveVersion: coll.ActiveVersion,
|
|
LatestVersion: coll.LatestVersion,
|
|
Fields: fields,
|
|
})
|
|
}
|
|
|
|
func (s *Controllers) UpdateJobCollectorByJobId(ctx echo.Context, jobId string) error {
|
|
req := JobCollectorUpdate{}
|
|
if err := ctx.Bind(&req); err != nil {
|
|
return echo.NewHTTPError(http.StatusBadRequest, err)
|
|
}
|
|
|
|
uid, err := uuid.Parse(jobId)
|
|
if err != nil {
|
|
return echo.NewHTTPError(http.StatusBadRequest, "Invalid ID")
|
|
}
|
|
|
|
var fields *map[string]uuid.UUID
|
|
if req.Fields != nil {
|
|
fields := &map[string]uuid.UUID{}
|
|
for _, field := range *req.Fields {
|
|
queryId, err := uuid.Parse(field.QueryId)
|
|
if err != nil {
|
|
return echo.NewHTTPError(http.StatusBadRequest, "Invalid ID")
|
|
}
|
|
|
|
(*fields)[field.Name] = queryId
|
|
}
|
|
}
|
|
|
|
err = s.svc.JobCollector.UpdateByJobId(ctx.Request().Context(), &collector.UpdateParams{
|
|
JobID: uid,
|
|
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)
|
|
}
|