3d434eedb8
Job Status Get and DB tidy up * initalquery * tests * shorttests * testing queries * job * solvedthequery * updatingdb * fixingtests * repotests * shorttests * docker * testspassed
58 lines
1.4 KiB
Go
58 lines
1.4 KiB
Go
package queryservice
|
|
|
|
import (
|
|
"fmt"
|
|
"net/http"
|
|
"queryorchestration/internal/job"
|
|
|
|
"github.com/labstack/echo/v4"
|
|
"github.com/oapi-codegen/runtime/types"
|
|
)
|
|
|
|
func (s *Controllers) CreateJob(ctx echo.Context) error {
|
|
req := JobCreate{}
|
|
if err := ctx.Bind(&req); err != nil {
|
|
return echo.NewHTTPError(http.StatusBadRequest, err)
|
|
}
|
|
|
|
id, err := s.svc.Job.Create(ctx.Request().Context(), req.ClientId)
|
|
if err != nil {
|
|
return echo.NewHTTPError(http.StatusBadRequest, fmt.Sprintf("Unable to create job: %s", err))
|
|
}
|
|
|
|
return ctx.JSON(http.StatusCreated, IdMessage{
|
|
Id: id,
|
|
})
|
|
}
|
|
|
|
func (s *Controllers) GetJob(ctx echo.Context, id types.UUID) error {
|
|
job, err := s.svc.Job.GetWithStatus(ctx.Request().Context(), id)
|
|
if err != nil {
|
|
return echo.NewHTTPError(http.StatusNotFound, fmt.Sprintf("Unable to find job: %s", err))
|
|
}
|
|
|
|
return ctx.JSON(http.StatusOK, Job{
|
|
Id: job.Job.ID,
|
|
ClientId: job.Job.ClientID,
|
|
CanSync: job.Job.CanSync,
|
|
Status: parseJobStatus(job.Status),
|
|
})
|
|
}
|
|
|
|
func (s *Controllers) UpdateJob(ctx echo.Context, id types.UUID) error {
|
|
req := JobUpdate{}
|
|
if err := ctx.Bind(&req); err != nil {
|
|
return echo.NewHTTPError(http.StatusBadRequest, err)
|
|
}
|
|
|
|
err := s.svc.Job.Update(ctx.Request().Context(), &job.Update{
|
|
ID: id,
|
|
CanSync: req.CanSync,
|
|
})
|
|
if err != nil {
|
|
return echo.NewHTTPError(http.StatusBadRequest, fmt.Sprintf("Unable to update job: %s", err))
|
|
}
|
|
|
|
return ctx.NoContent(http.StatusOK)
|
|
}
|