Merged in feature/jobcrud (pull request #35)

Job CRUD + Collector Integration

* startedcreate

* openapispec

* createjobintegration

* jobgetcontroller

* jobcreateclient

* updatejob

* job

* collector
This commit is contained in:
Michael McGuinness
2025-01-24 14:52:56 +00:00
parent 5b7160fe44
commit 4ec1d51a12
40 changed files with 1775 additions and 403 deletions
+168 -82
View File
@@ -16,6 +16,7 @@ import (
"github.com/getkin/kin-openapi/openapi3"
"github.com/labstack/echo/v4"
"github.com/oapi-codegen/runtime"
openapi_types "github.com/oapi-codegen/runtime/types"
)
// Defines values for ExportStatus.
@@ -61,7 +62,7 @@ type ClientUpdate struct {
// ExportDetails Payload for export trigger response.
type ExportDetails struct {
// JobId The job id relative to the export.
JobId *string `json:"job_id,omitempty"`
JobId *openapi_types.UUID `json:"job_id,omitempty"`
// OutputLocation The location in which the export zip file will be found.
OutputLocation *string `json:"output_location,omitempty"`
@@ -88,7 +89,7 @@ type ExportTrigger struct {
} `json:"ingestion_filters,omitempty"`
// JobId The job id of the query results to be exported.
JobId string `json:"job_id"`
JobId openapi_types.UUID `json:"job_id"`
}
// FieldFilter Filtering a column
@@ -109,7 +110,19 @@ type FieldFilterCondition string
// IdMessage defines model for IdMessage.
type IdMessage struct {
// Id Unique identifier for entity.
Id string `json:"id"`
Id openapi_types.UUID `json:"id"`
}
// Job defines model for Job.
type Job struct {
// CanSync Specifies whether the job is actively syncing
CanSync bool `json:"can_sync"`
// ClientId The client id the job belongs to
ClientId openapi_types.UUID `json:"client_id"`
// Id The job id
Id openapi_types.UUID `json:"id"`
}
// JobClient defines model for JobClient.
@@ -118,7 +131,7 @@ type JobClient struct {
CanSync bool `json:"can_sync"`
// Id The client id
Id string `json:"id"`
Id openapi_types.UUID `json:"id"`
// Name The client name
Name string `json:"name"`
@@ -133,7 +146,7 @@ type JobCollector struct {
Fields []JobCollectorField `json:"fields"`
// JobId The ID of the associated job.
JobId string `json:"job_id"`
JobId openapi_types.UUID `json:"job_id"`
// LatestVersion The latest version of the collector.
LatestVersion int32 `json:"latest_version"`
@@ -151,7 +164,7 @@ type JobCollectorField struct {
Name string `json:"name"`
// QueryId The query id that will populate the result.
QueryId string `json:"query_id"`
QueryId openapi_types.UUID `json:"query_id"`
}
// JobCollectorUpdate Payload for updating a JobCollector.
@@ -169,6 +182,18 @@ type JobCollectorUpdate struct {
MinimumTextVersion *int32 `json:"minimum_text_version,omitempty"`
}
// JobCreate defines model for JobCreate.
type JobCreate struct {
// ClientId The client id the job belongs to
ClientId openapi_types.UUID `json:"client_id"`
}
// JobUpdate defines model for JobUpdate.
type JobUpdate struct {
// CanSync Specifies whether the job is actively syncing
CanSync *bool `json:"can_sync,omitempty"`
}
// ListQueries defines model for ListQueries.
type ListQueries struct {
// Queries List of queries.
@@ -184,13 +209,13 @@ type Query struct {
Config *string `json:"config,omitempty"`
// Id Unique identifier for the query.
Id string `json:"id"`
Id openapi_types.UUID `json:"id"`
// LatestVersion The latest version of the query.
LatestVersion int32 `json:"latest_version"`
// RequiredQueries List of required query IDs.
RequiredQueries *[]string `json:"required_queries,omitempty"`
RequiredQueries *[]openapi_types.UUID `json:"required_queries,omitempty"`
// Type Specifies the type of the query.
Type QueryType `json:"type"`
@@ -202,7 +227,7 @@ type QueryCreate struct {
Config *string `json:"config,omitempty"`
// RequiredQueries List of required query IDs.
RequiredQueries *[]string `json:"required_queries,omitempty"`
RequiredQueries *[]openapi_types.UUID `json:"required_queries,omitempty"`
// Type Specifies the type of the query.
Type QueryType `json:"type"`
@@ -211,7 +236,7 @@ type QueryCreate struct {
// QueryTestRequest defines model for QueryTestRequest.
type QueryTestRequest struct {
// DocumentId ID of the document to test against.
DocumentId string `json:"document_id"`
DocumentId openapi_types.UUID `json:"document_id"`
// QueryVersion Version of the query to use for testing.
QueryVersion int32 `json:"query_version"`
@@ -235,7 +260,7 @@ type QueryUpdate struct {
Config *string `json:"config,omitempty"`
// RequiredQueries Updated list of required query IDs.
RequiredQueries *[]string `json:"required_queries,omitempty"`
RequiredQueries *[]openapi_types.UUID `json:"required_queries,omitempty"`
}
// CreateClientJSONRequestBody defines body for CreateClient for application/json ContentType.
@@ -244,9 +269,15 @@ type CreateClientJSONRequestBody = ClientCreate
// UpdateClientJSONRequestBody defines body for UpdateClient for application/json ContentType.
type UpdateClientJSONRequestBody = ClientUpdate
// CreateJobJSONRequestBody defines body for CreateJob for application/json ContentType.
type CreateJobJSONRequestBody = JobCreate
// TriggerExportJSONRequestBody defines body for TriggerExport for application/json ContentType.
type TriggerExportJSONRequestBody = ExportTrigger
// UpdateJobJSONRequestBody defines body for UpdateJob for application/json ContentType.
type UpdateJobJSONRequestBody = JobUpdate
// UpdateJobCollectorByJobIdJSONRequestBody defines body for UpdateJobCollectorByJobId for application/json ContentType.
type UpdateJobCollectorByJobIdJSONRequestBody = JobCollectorUpdate
@@ -262,41 +293,50 @@ type TestQueryJSONRequestBody = QueryTestRequest
// ServerInterface represents all server handlers.
type ServerInterface interface {
// Create a new client
// (POST /clients)
// (POST /client)
CreateClient(ctx echo.Context) error
// Get a client by ID
// (GET /clients/{id})
GetClient(ctx echo.Context, id string) error
// (GET /client/{id})
GetClient(ctx echo.Context, id openapi_types.UUID) error
// Update a client
// (PATCH /clients/{id})
UpdateClient(ctx echo.Context, id string) error
// (PATCH /client/{id})
UpdateClient(ctx echo.Context, id openapi_types.UUID) error
// Create a new job
// (POST /job)
CreateJob(ctx echo.Context) error
// Trigger an export
// (POST /job/export)
TriggerExport(ctx echo.Context) error
// Check export state.
// (GET /job/export/{id})
ExportState(ctx echo.Context, id string) error
ExportState(ctx echo.Context, id openapi_types.UUID) error
// Get a job by ID
// (GET /job/{id})
GetJob(ctx echo.Context, id openapi_types.UUID) error
// Update a job
// (PATCH /job/{id})
UpdateJob(ctx echo.Context, id openapi_types.UUID) error
// Get a job collector by ID
// (GET /job/{id}/collector)
GetJobCollectorByJobId(ctx echo.Context, id string) error
GetJobCollectorByJobId(ctx echo.Context, id openapi_types.UUID) error
// Update a job collector
// (PATCH /job/{id}/collector)
UpdateJobCollectorByJobId(ctx echo.Context, id string) error
UpdateJobCollectorByJobId(ctx echo.Context, id openapi_types.UUID) error
// List queries
// (GET /queries)
// (GET /query)
ListQueries(ctx echo.Context) error
// Create a new query
// (POST /queries)
// (POST /query)
CreateQuery(ctx echo.Context) error
// Get a query by ID
// (GET /queries/{id})
GetQuery(ctx echo.Context, id string) error
// (GET /query/{id})
GetQuery(ctx echo.Context, id openapi_types.UUID) error
// Update a query
// (PATCH /queries/{id})
UpdateQuery(ctx echo.Context, id string) error
// (PATCH /query/{id})
UpdateQuery(ctx echo.Context, id openapi_types.UUID) error
// Test a query
// (POST /queries/{id}/test)
TestQuery(ctx echo.Context, id string) error
// (POST /query/{id}/test)
TestQuery(ctx echo.Context, id openapi_types.UUID) error
}
// ServerInterfaceWrapper converts echo contexts to parameters.
@@ -317,7 +357,7 @@ func (w *ServerInterfaceWrapper) CreateClient(ctx echo.Context) error {
func (w *ServerInterfaceWrapper) GetClient(ctx echo.Context) error {
var err error
// ------------- Path parameter "id" -------------
var id string
var id openapi_types.UUID
err = runtime.BindStyledParameterWithOptions("simple", "id", ctx.Param("id"), &id, runtime.BindStyledParameterOptions{ParamLocation: runtime.ParamLocationPath, Explode: false, Required: true})
if err != nil {
@@ -333,7 +373,7 @@ func (w *ServerInterfaceWrapper) GetClient(ctx echo.Context) error {
func (w *ServerInterfaceWrapper) UpdateClient(ctx echo.Context) error {
var err error
// ------------- Path parameter "id" -------------
var id string
var id openapi_types.UUID
err = runtime.BindStyledParameterWithOptions("simple", "id", ctx.Param("id"), &id, runtime.BindStyledParameterOptions{ParamLocation: runtime.ParamLocationPath, Explode: false, Required: true})
if err != nil {
@@ -345,6 +385,15 @@ func (w *ServerInterfaceWrapper) UpdateClient(ctx echo.Context) error {
return err
}
// CreateJob converts echo context to params.
func (w *ServerInterfaceWrapper) CreateJob(ctx echo.Context) error {
var err error
// Invoke the callback with all the unmarshaled arguments
err = w.Handler.CreateJob(ctx)
return err
}
// TriggerExport converts echo context to params.
func (w *ServerInterfaceWrapper) TriggerExport(ctx echo.Context) error {
var err error
@@ -358,7 +407,7 @@ func (w *ServerInterfaceWrapper) TriggerExport(ctx echo.Context) error {
func (w *ServerInterfaceWrapper) ExportState(ctx echo.Context) error {
var err error
// ------------- Path parameter "id" -------------
var id string
var id openapi_types.UUID
err = runtime.BindStyledParameterWithOptions("simple", "id", ctx.Param("id"), &id, runtime.BindStyledParameterOptions{ParamLocation: runtime.ParamLocationPath, Explode: false, Required: true})
if err != nil {
@@ -370,11 +419,43 @@ func (w *ServerInterfaceWrapper) ExportState(ctx echo.Context) error {
return err
}
// GetJob converts echo context to params.
func (w *ServerInterfaceWrapper) GetJob(ctx echo.Context) error {
var err error
// ------------- Path parameter "id" -------------
var id openapi_types.UUID
err = runtime.BindStyledParameterWithOptions("simple", "id", ctx.Param("id"), &id, runtime.BindStyledParameterOptions{ParamLocation: runtime.ParamLocationPath, Explode: false, Required: true})
if err != nil {
return echo.NewHTTPError(http.StatusBadRequest, fmt.Sprintf("Invalid format for parameter id: %s", err))
}
// Invoke the callback with all the unmarshaled arguments
err = w.Handler.GetJob(ctx, id)
return err
}
// UpdateJob converts echo context to params.
func (w *ServerInterfaceWrapper) UpdateJob(ctx echo.Context) error {
var err error
// ------------- Path parameter "id" -------------
var id openapi_types.UUID
err = runtime.BindStyledParameterWithOptions("simple", "id", ctx.Param("id"), &id, runtime.BindStyledParameterOptions{ParamLocation: runtime.ParamLocationPath, Explode: false, Required: true})
if err != nil {
return echo.NewHTTPError(http.StatusBadRequest, fmt.Sprintf("Invalid format for parameter id: %s", err))
}
// Invoke the callback with all the unmarshaled arguments
err = w.Handler.UpdateJob(ctx, id)
return err
}
// GetJobCollectorByJobId converts echo context to params.
func (w *ServerInterfaceWrapper) GetJobCollectorByJobId(ctx echo.Context) error {
var err error
// ------------- Path parameter "id" -------------
var id string
var id openapi_types.UUID
err = runtime.BindStyledParameterWithOptions("simple", "id", ctx.Param("id"), &id, runtime.BindStyledParameterOptions{ParamLocation: runtime.ParamLocationPath, Explode: false, Required: true})
if err != nil {
@@ -390,7 +471,7 @@ func (w *ServerInterfaceWrapper) GetJobCollectorByJobId(ctx echo.Context) error
func (w *ServerInterfaceWrapper) UpdateJobCollectorByJobId(ctx echo.Context) error {
var err error
// ------------- Path parameter "id" -------------
var id string
var id openapi_types.UUID
err = runtime.BindStyledParameterWithOptions("simple", "id", ctx.Param("id"), &id, runtime.BindStyledParameterOptions{ParamLocation: runtime.ParamLocationPath, Explode: false, Required: true})
if err != nil {
@@ -424,7 +505,7 @@ func (w *ServerInterfaceWrapper) CreateQuery(ctx echo.Context) error {
func (w *ServerInterfaceWrapper) GetQuery(ctx echo.Context) error {
var err error
// ------------- Path parameter "id" -------------
var id string
var id openapi_types.UUID
err = runtime.BindStyledParameterWithOptions("simple", "id", ctx.Param("id"), &id, runtime.BindStyledParameterOptions{ParamLocation: runtime.ParamLocationPath, Explode: false, Required: true})
if err != nil {
@@ -440,7 +521,7 @@ func (w *ServerInterfaceWrapper) GetQuery(ctx echo.Context) error {
func (w *ServerInterfaceWrapper) UpdateQuery(ctx echo.Context) error {
var err error
// ------------- Path parameter "id" -------------
var id string
var id openapi_types.UUID
err = runtime.BindStyledParameterWithOptions("simple", "id", ctx.Param("id"), &id, runtime.BindStyledParameterOptions{ParamLocation: runtime.ParamLocationPath, Explode: false, Required: true})
if err != nil {
@@ -456,7 +537,7 @@ func (w *ServerInterfaceWrapper) UpdateQuery(ctx echo.Context) error {
func (w *ServerInterfaceWrapper) TestQuery(ctx echo.Context) error {
var err error
// ------------- Path parameter "id" -------------
var id string
var id openapi_types.UUID
err = runtime.BindStyledParameterWithOptions("simple", "id", ctx.Param("id"), &id, runtime.BindStyledParameterOptions{ParamLocation: runtime.ParamLocationPath, Explode: false, Required: true})
if err != nil {
@@ -496,63 +577,68 @@ func RegisterHandlersWithBaseURL(router EchoRouter, si ServerInterface, baseURL
Handler: si,
}
router.POST(baseURL+"/clients", wrapper.CreateClient)
router.GET(baseURL+"/clients/:id", wrapper.GetClient)
router.PATCH(baseURL+"/clients/:id", wrapper.UpdateClient)
router.POST(baseURL+"/client", wrapper.CreateClient)
router.GET(baseURL+"/client/:id", wrapper.GetClient)
router.PATCH(baseURL+"/client/:id", wrapper.UpdateClient)
router.POST(baseURL+"/job", wrapper.CreateJob)
router.POST(baseURL+"/job/export", wrapper.TriggerExport)
router.GET(baseURL+"/job/export/:id", wrapper.ExportState)
router.GET(baseURL+"/job/:id", wrapper.GetJob)
router.PATCH(baseURL+"/job/:id", wrapper.UpdateJob)
router.GET(baseURL+"/job/:id/collector", wrapper.GetJobCollectorByJobId)
router.PATCH(baseURL+"/job/:id/collector", wrapper.UpdateJobCollectorByJobId)
router.GET(baseURL+"/queries", wrapper.ListQueries)
router.POST(baseURL+"/queries", wrapper.CreateQuery)
router.GET(baseURL+"/queries/:id", wrapper.GetQuery)
router.PATCH(baseURL+"/queries/:id", wrapper.UpdateQuery)
router.POST(baseURL+"/queries/:id/test", wrapper.TestQuery)
router.GET(baseURL+"/query", wrapper.ListQueries)
router.POST(baseURL+"/query", wrapper.CreateQuery)
router.GET(baseURL+"/query/:id", wrapper.GetQuery)
router.PATCH(baseURL+"/query/:id", wrapper.UpdateQuery)
router.POST(baseURL+"/query/:id/test", wrapper.TestQuery)
}
// Base64 encoded, gzipped, json marshaled Swagger object
var swaggerSpec = []string{
"H4sIAAAAAAAC/+RbW2/buBL+K4TOeTTsdLtPfusm6cJFz6anSQ8WWAQGTY5sZilSISmn3sD//YAX3SzR",
"UpxkkWKfGlvkDDnfNxfNuI8JkVkuBQijk/ljoskGMuz+POcMhDlXgA3Yz7mSOSjDwD0VOHPfUtBEsdww",
"KZJ5crMBRNw+5BZMErPLIZkn2igm1sl+P0kU3BdMAU3mf3gpt9UquboDYpL9JCj/ltNe5QSLpd4J0j3A",
"IkWmPgPTCHMuH5hYI0wM2wKy23R9rpWUHLCwKk+/Uef0l99zqcwFGMy47sr8gndcYopSqRC4pcgotl6D",
"Qgp0LoWGa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WHm1kStrlti3p",
"Hx3gC4SRrNl83vCaLHrVeJQzkk9b2gSTgkelesxRM79/kxJgwOkMfbkB9jtSgOVK2aDiHqvYlNF4ONKk",
"Q/UMBsbM0c13U2HDbKgmMUBKymc1YZivqmc5QbQdKoVPODymJ/A+KwdXiI6QdwvLn1+UuWvTkxVZEcXH",
"K8dCsXSUKuykt2EJ5jFp1F+NUDvA8FYGAvpXl1ll6h5QY42asc+prgKGG7O0OkmMsrAakICtE85YvYd/",
"njuWU/sds2ww/bS/lvEiGfvcVG4qVP2US2/6bgDuavgAj2zAcuyb5cqe4KTljUmzx/cK3Lba8hkO3MmJ",
"cUrwow7wczy72urYPj6AdHVvr8b3Ms4GgPui4dXr86LZlKu/sXWvXJniBhSnbVPXm4AjOnxdTYe/vzve",
"wcvmabyWDJrItVTuSxAKw7hZjRgw4HCLl7ZnH2+xtzmOd9WbV6/pQIRWGfmQe++BDRi1dLMnlLto6tN5",
"tbLrSI7l2+ohdEcpe3vcCdNsiU4jvbZ9avipp2yy/NXptObjA9Lo6K79zJtGtOaYmbKHL2WGPMtXZ6bo",
"Jr8aBnWmh6vvwHLMD65trXLXZ6bBTNH8o5OjGzTQZnQ+1bv1w0n10vp997sjst04GP2DxOckCieon3Z2",
"DqhdN8E+K5nkrGyIgq3sciWiebQxJtPz2YxmfOr/Wm3K5Ha2exNZtnhtx/I+FfbW+Jd3kBAj/RW8rtja",
"vII/TIaJuZNxTUbtwHmGgKqGbYpq1bBDZVaFlxfWwH+oFLwSq0lpXrAdbg//DwAA//8wRccXljoAAA==",
}
// GetSwagger returns the content of the embedded swagger specification file
+8 -18
View File
@@ -5,8 +5,8 @@ import (
"net/http"
"queryorchestration/internal/client"
"github.com/google/uuid"
"github.com/labstack/echo/v4"
"github.com/oapi-codegen/runtime/types"
)
func (s *Controllers) CreateClient(ctx echo.Context) error {
@@ -21,41 +21,31 @@ func (s *Controllers) CreateClient(ctx echo.Context) error {
}
return ctx.JSON(http.StatusCreated, IdMessage{
Id: id.String(),
Id: id,
})
}
func (s *Controllers) GetClient(ctx echo.Context, id string) error {
uid, err := uuid.Parse(id)
if err != nil {
return echo.NewHTTPError(http.StatusBadRequest, "Invalid ID")
}
client, err := s.svc.Client.Get(ctx.Request().Context(), uid)
func (s *Controllers) GetClient(ctx echo.Context, id types.UUID) error {
client, err := s.svc.Client.Get(ctx.Request().Context(), id)
if err != nil {
return echo.NewHTTPError(http.StatusNotFound, fmt.Sprintf("Unable to get client: %s", err))
}
return ctx.JSON(http.StatusOK, JobClient{
Id: client.ID.String(),
Id: client.ID,
Name: client.Name,
CanSync: client.CanSync,
})
}
func (s *Controllers) UpdateClient(ctx echo.Context, id string) error {
func (s *Controllers) UpdateClient(ctx echo.Context, id types.UUID) error {
req := ClientUpdate{}
if err := ctx.Bind(&req); err != nil {
return echo.NewHTTPError(http.StatusBadRequest, err)
}
uid, err := uuid.Parse(id)
if err != nil {
return echo.NewHTTPError(http.StatusBadRequest, "Invalid ID")
}
err = s.svc.Client.Update(ctx.Request().Context(), &client.Update{
ID: uid,
err := s.svc.Client.Update(ctx.Request().Context(), &client.Update{
ID: id,
Name: req.Name,
CanSync: req.CanSync,
})
+3 -3
View File
@@ -88,7 +88,7 @@ func TestGetClient(t *testing.T) {
AddRow(database.MustToDBUUID(id), "client_name", true),
)
err = cons.GetClient(ctx, id.String())
err = cons.GetClient(ctx, id)
assert.Nil(t, err)
assert.Equal(t, http.StatusOK, rec.Code)
@@ -96,7 +96,7 @@ func TestGetClient(t *testing.T) {
err = json.Unmarshal(rec.Body.Bytes(), &res)
assert.Nil(t, err)
assert.EqualExportedValues(t, queryservice.JobClient{
Id: id.String(),
Id: id,
Name: "client_name",
CanSync: true,
}, res)
@@ -139,7 +139,7 @@ func TestUpdateClient(t *testing.T) {
pool.ExpectExec("name: UpdateClient :exec").WithArgs("client_name", true, database.MustToDBUUID(id)).
WillReturnResult(pgxmock.NewResult("", 1))
err = cons.UpdateClient(ctx, id.String())
err = cons.UpdateClient(ctx, id)
assert.Nil(t, err)
assert.Equal(t, http.StatusOK, rec.Code)
assert.Empty(t, rec.Body.String())
+2
View File
@@ -3,6 +3,7 @@ package queryservice
import (
"queryorchestration/internal/client"
"queryorchestration/internal/export"
"queryorchestration/internal/job"
"queryorchestration/internal/job/collector"
"queryorchestration/internal/query"
@@ -14,6 +15,7 @@ type Services struct {
JobCollector *collector.Service
Query *query.Service
Client *client.Service
Job *job.Service
}
type Controllers struct {
+2 -1
View File
@@ -4,12 +4,13 @@ import (
"net/http"
"github.com/labstack/echo/v4"
"github.com/oapi-codegen/runtime/types"
)
func (s *Controllers) TriggerExport(ctx echo.Context) error {
return ctx.JSON(http.StatusOK, map[string]string{"status": "export triggered"})
}
func (s *Controllers) ExportState(ctx echo.Context, id string) error {
func (s *Controllers) ExportState(ctx echo.Context, id types.UUID) error {
return ctx.JSON(http.StatusOK, map[string]string{"status": "export triggered"})
}
+1 -1
View File
@@ -35,7 +35,7 @@ func TestExportState(t *testing.T) {
cons := queryservice.NewControllers(validator.New(), &queryservice.Services{})
id := uuid.NewString()
id := uuid.New()
err := cons.ExportState(ctx, id)
assert.Nil(t, err)
+56
View File
@@ -0,0 +1,56 @@
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.Get(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.ID,
ClientId: job.ClientID,
CanSync: job.CanSync,
})
}
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)
}
+189
View File
@@ -0,0 +1,189 @@
package queryservice_test
import (
"encoding/json"
"fmt"
"net/http"
"net/http/httptest"
queryservice "queryorchestration/api/queryService"
"queryorchestration/internal/client"
"queryorchestration/internal/database"
"queryorchestration/internal/database/repository"
documentclean "queryorchestration/internal/document_clean"
"queryorchestration/internal/job"
"queryorchestration/internal/job/collector"
"queryorchestration/internal/query"
textextraction "queryorchestration/internal/text_extraction"
"strings"
"testing"
"github.com/go-playground/validator/v10"
"github.com/google/uuid"
"github.com/jackc/pgx/v5"
"github.com/labstack/echo/v4"
"github.com/pashagolub/pgxmock/v3"
"github.com/stretchr/testify/assert"
)
func TestCreateJob(t *testing.T) {
pool, err := pgxmock.NewPool()
if err != nil {
t.Fatalf("failed to open pgxmock database: %v", err)
}
queries := repository.New(pool)
db := &database.Connection{
Queries: queries,
Pool: pool,
}
cons := queryservice.NewControllers(validator.New(), &queryservice.Services{
Job: job.New(db, &job.Services{
Collector: collector.New(db, &collector.Services{
Query: query.New(db),
DocumentClean: documentclean.New(),
TextExtraction: textextraction.New(),
}),
}),
})
body := queryservice.JobCreate{
ClientId: uuid.New(),
}
bodyBytes, err := json.Marshal(body)
assert.Nil(t, err)
e := echo.New()
req := httptest.NewRequest(http.MethodPost, "/", strings.NewReader(string(bodyBytes)))
req.Header.Set(echo.HeaderContentType, echo.MIMEApplicationJSON)
rec := httptest.NewRecorder()
ctx := e.NewContext(req, rec)
id := uuid.New()
pool.ExpectQuery("-- name: CreateJob :one").WithArgs(database.MustToDBUUID(body.ClientId)).WillReturnRows(
pgxmock.NewRows([]string{"id"}).
AddRow(database.MustToDBUUID(id)),
)
pool.ExpectBeginTx(pgx.TxOptions{})
pool.ExpectQuery("name: CreateCollector :one").WithArgs(database.MustToDBUUID(id)).WillReturnRows(
pgxmock.NewRows([]string{"id"}).
AddRow(database.MustToDBUUID(uuid.New())),
)
pool.ExpectCommit()
err = cons.CreateJob(ctx)
assert.Nil(t, err)
assert.Equal(t, http.StatusCreated, rec.Code)
assert.Equal(t, fmt.Sprintf("{\"id\":\"%s\"}\n", id), rec.Body.String())
}
func TestGetJob(t *testing.T) {
pool, err := pgxmock.NewPool()
if err != nil {
t.Fatalf("failed to open pgxmock database: %v", err)
}
queries := repository.New(pool)
db := &database.Connection{
Queries: queries,
Pool: pool,
}
cons := queryservice.NewControllers(validator.New(), &queryservice.Services{
Job: job.New(db, &job.Services{
Client: client.New(db),
}),
})
e := echo.New()
req := httptest.NewRequest(http.MethodPost, "/", strings.NewReader(""))
rec := httptest.NewRecorder()
ctx := e.NewContext(req, rec)
j := job.Job{
ID: uuid.New(),
ClientID: uuid.New(),
CanSync: true,
}
pool.ExpectQuery("name: GetJob :one").WithArgs(database.MustToDBUUID(j.ID)).WillReturnRows(
pgxmock.NewRows([]string{"id", "clientId", "canSync"}).
AddRow(database.MustToDBUUID(j.ID), database.MustToDBUUID(j.ClientID), j.CanSync),
)
pool.ExpectQuery("name: GetClient :one").WithArgs(database.MustToDBUUID(j.ClientID)).
WillReturnRows(
pgxmock.NewRows([]string{"id", "name", "canSync"}).
AddRow(database.MustToDBUUID(j.ClientID), "client_name", true),
)
err = cons.GetJob(ctx, j.ID)
assert.Nil(t, err)
assert.Equal(t, http.StatusOK, rec.Code)
var res queryservice.Job
err = json.Unmarshal(rec.Body.Bytes(), &res)
assert.Nil(t, err)
assert.EqualExportedValues(t, queryservice.Job{
Id: j.ID,
ClientId: j.ClientID,
CanSync: j.CanSync,
}, res)
}
func TestUpdateJob(t *testing.T) {
pool, err := pgxmock.NewPool()
if err != nil {
t.Fatalf("failed to open pgxmock database: %v", err)
}
queries := repository.New(pool)
db := &database.Connection{
Queries: queries,
Pool: pool,
}
cons := queryservice.NewControllers(validator.New(), &queryservice.Services{
Job: job.New(db, &job.Services{
Client: client.New(db),
}),
})
j := job.Job{
ID: uuid.New(),
ClientID: uuid.New(),
CanSync: false,
}
ucs := !j.CanSync
body := queryservice.JobUpdate{
CanSync: &ucs,
}
bodyBytes, err := json.Marshal(body)
assert.Nil(t, err)
e := echo.New()
req := httptest.NewRequest(http.MethodPost, "/", strings.NewReader(string(bodyBytes)))
req.Header.Set(echo.HeaderContentType, echo.MIMEApplicationJSON)
rec := httptest.NewRecorder()
ctx := e.NewContext(req, rec)
pool.ExpectQuery("name: GetJob :one").WithArgs(database.MustToDBUUID(j.ID)).WillReturnRows(
pgxmock.NewRows([]string{"id", "clientId", "canSync"}).
AddRow(database.MustToDBUUID(j.ID), database.MustToDBUUID(j.ClientID), j.CanSync),
)
pool.ExpectQuery("name: GetClient :one").WithArgs(database.MustToDBUUID(j.ClientID)).
WillReturnRows(
pgxmock.NewRows([]string{"id", "name", "canSync"}).
AddRow(database.MustToDBUUID(j.ClientID), "client_name", true),
)
pool.ExpectQuery("name: GetClient :one").WithArgs(database.MustToDBUUID(j.ClientID)).
WillReturnRows(
pgxmock.NewRows([]string{"id", "name", "canSync"}).
AddRow(database.MustToDBUUID(j.ClientID), "client_name", true),
)
pool.ExpectExec("name: UpdateJob :exec").WithArgs(ucs, database.MustToDBUUID(j.ID)).
WillReturnResult(pgxmock.NewResult("", 1))
err = cons.UpdateJob(ctx, j.ID)
assert.Nil(t, err)
assert.Equal(t, http.StatusOK, rec.Code)
assert.Empty(t, rec.Body.String())
}
+9 -23
View File
@@ -7,15 +7,11 @@ import (
"github.com/google/uuid"
"github.com/labstack/echo/v4"
"github.com/oapi-codegen/runtime/types"
)
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)
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))
}
@@ -25,13 +21,13 @@ func (s *Controllers) GetJobCollectorByJobId(ctx echo.Context, jobId string) err
for name, id := range coll.Fields {
fields[index] = JobCollectorField{
Name: name,
QueryId: id.String(),
QueryId: id,
}
index++
}
return ctx.JSON(http.StatusOK, JobCollector{
JobId: coll.JobID.String(),
JobId: coll.JobID,
MinimumCleanerVersion: coll.MinCleanVersion,
MinimumTextVersion: coll.MinTextVersion,
ActiveVersion: coll.ActiveVersion,
@@ -40,32 +36,22 @@ func (s *Controllers) GetJobCollectorByJobId(ctx echo.Context, jobId string) err
})
}
func (s *Controllers) UpdateJobCollectorByJobId(ctx echo.Context, jobId string) error {
func (s *Controllers) UpdateJobCollectorByJobId(ctx echo.Context, jobId types.UUID) 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
(*fields)[field.Name] = field.QueryId
}
}
err = s.svc.JobCollector.UpdateByJobId(ctx.Request().Context(), &collector.UpdateParams{
JobID: uid,
err := s.svc.JobCollector.UpdateByJobId(ctx.Request().Context(), &collector.UpdateParams{
JobID: jobId,
ActiveVersion: req.ActiveVersion,
MinCleanVersion: req.MinimumCleanerVersion,
MinTextVersion: req.MinimumTextVersion,
+3 -3
View File
@@ -73,7 +73,7 @@ func TestUpdateJobCollector(t *testing.T) {
WillReturnResult(pgxmock.NewResult("", 1))
pool.ExpectCommit()
err = cons.UpdateJobCollectorByJobId(ctx, current.JobID.String())
err = cons.UpdateJobCollectorByJobId(ctx, current.JobID)
assert.Nil(t, err)
assert.Equal(t, http.StatusOK, rec.Code)
assert.Empty(t, rec.Body.String())
@@ -115,7 +115,7 @@ func TestGetJobCollectorByJobId(t *testing.T) {
AddRow(database.MustToDBUUID(coll.ID), database.MustToDBUUID(coll.JobID), &coll.MinCleanVersion, &coll.MinTextVersion, int32(1), int32(2), []byte("")),
)
err = cons.GetJobCollectorByJobId(ctx, coll.JobID.String())
err = cons.GetJobCollectorByJobId(ctx, coll.JobID)
assert.Nil(t, err)
assert.Equal(t, http.StatusOK, rec.Code)
@@ -123,7 +123,7 @@ func TestGetJobCollectorByJobId(t *testing.T) {
err = json.Unmarshal(rec.Body.Bytes(), &res)
assert.Nil(t, err)
assert.EqualExportedValues(t, queryservice.JobCollector{
JobId: coll.JobID.String(),
JobId: coll.JobID,
MinimumCleanerVersion: coll.MinCleanVersion,
MinimumTextVersion: coll.MinTextVersion,
ActiveVersion: int32(1),
+4 -10
View File
@@ -23,14 +23,8 @@ func parseQueries(queries []*query.Query) ([]Query, error) {
}
func parseQuery(query *query.Query) (*Query, error) {
var requiredQueries *[]string
if query.RequiredQueryIDs != nil && len(*query.RequiredQueryIDs) > 0 {
rQ := make([]string, len(*query.RequiredQueryIDs))
for index, id := range *query.RequiredQueryIDs {
rQ[index] = id.String()
}
requiredQueries = &rQ
if query.RequiredQueryIDs != nil && len(*query.RequiredQueryIDs) == 0 {
query.RequiredQueryIDs = nil
}
qt, err := parseQueryType(query.Type)
@@ -39,11 +33,11 @@ func parseQuery(query *query.Query) (*Query, error) {
}
q := &Query{
Id: query.ID.String(),
Id: query.ID,
Type: qt,
ActiveVersion: query.ActiveVersion,
LatestVersion: query.LatestVersion,
RequiredQueries: requiredQueries,
RequiredQueries: query.RequiredQueryIDs,
Config: query.Config,
}
+8 -7
View File
@@ -6,6 +6,7 @@ import (
"testing"
"github.com/google/uuid"
"github.com/oapi-codegen/runtime/types"
"github.com/stretchr/testify/assert"
)
@@ -28,12 +29,12 @@ func TestParseQueries(t *testing.T) {
assert.Len(t, out, len(in))
assert.ElementsMatch(t, []Query{
{
Id: in[0].ID.String(),
Id: in[0].ID,
Type: CONTEXTFULL,
ActiveVersion: 1,
LatestVersion: 2,
RequiredQueries: &[]string{
(*in[0].RequiredQueryIDs)[0].String(),
RequiredQueries: &[]types.UUID{
(*in[0].RequiredQueryIDs)[0],
},
Config: in[0].Config,
},
@@ -55,12 +56,12 @@ func TestParseQuery(t *testing.T) {
out, err := parseQuery(in)
assert.Nil(t, err)
assert.EqualExportedValues(t, Query{
Id: in.ID.String(),
Id: in.ID,
Type: CONTEXTFULL,
ActiveVersion: 1,
LatestVersion: 2,
RequiredQueries: &[]string{
(*in.RequiredQueryIDs)[0].String(),
RequiredQueries: &[]types.UUID{
(*in.RequiredQueryIDs)[0],
},
Config: in.Config,
},
@@ -77,7 +78,7 @@ func TestParseQueryMinimal(t *testing.T) {
out, err := parseQuery(in)
assert.Nil(t, err)
assert.EqualExportedValues(t, Query{
Id: in.ID.String(),
Id: in.ID,
Type: CONTEXTFULL,
ActiveVersion: 1,
LatestVersion: 2,
+12 -40
View File
@@ -6,8 +6,8 @@ import (
"queryorchestration/internal/query"
queryprocessor "queryorchestration/internal/query/processor"
"github.com/google/uuid"
"github.com/labstack/echo/v4"
"github.com/oapi-codegen/runtime/types"
)
func (s *Controllers) ListQueries(ctx echo.Context) error {
@@ -28,13 +28,8 @@ func (s *Controllers) ListQueries(ctx echo.Context) error {
})
}
func (s *Controllers) GetQuery(ctx echo.Context, id string) error {
uid, err := uuid.Parse(id)
if err != nil {
return echo.NewHTTPError(http.StatusBadRequest, "Invalid ID")
}
query, err := s.svc.Query.Get(ctx.Request().Context(), uid)
func (s *Controllers) GetQuery(ctx echo.Context, id types.UUID) error {
query, err := s.svc.Query.Get(ctx.Request().Context(), id)
if err != nil {
return echo.NewHTTPError(http.StatusNotFound, fmt.Sprintf("Unable to get query: %s", err))
}
@@ -53,11 +48,6 @@ func (s *Controllers) CreateQuery(ctx echo.Context) error {
return echo.NewHTTPError(http.StatusBadRequest, err)
}
requiredQueryIDs, err := parseStringToUUIDArray(req.RequiredQueries)
if err != nil {
return echo.NewHTTPError(http.StatusBadRequest, "Invalid Required IDs")
}
qt, err := parseSpecQueryType(req.Type)
if err != nil {
return echo.NewHTTPError(http.StatusBadRequest, "Invalid Query Type")
@@ -65,7 +55,7 @@ func (s *Controllers) CreateQuery(ctx echo.Context) error {
id, err := s.svc.Query.Create(ctx.Request().Context(), &queryprocessor.Create{
Type: qt,
RequiredQueryIDs: requiredQueryIDs,
RequiredQueryIDs: req.RequiredQueries,
Config: req.Config,
})
if err != nil {
@@ -73,31 +63,21 @@ func (s *Controllers) CreateQuery(ctx echo.Context) error {
}
return ctx.JSON(http.StatusCreated, IdMessage{
Id: id.String(),
Id: id,
})
}
func (s *Controllers) UpdateQuery(ctx echo.Context, id string) error {
func (s *Controllers) UpdateQuery(ctx echo.Context, id types.UUID) error {
req := QueryUpdate{}
if err := ctx.Bind(&req); err != nil {
return echo.NewHTTPError(http.StatusBadRequest, err)
}
uid, err := uuid.Parse(id)
if err != nil {
return echo.NewHTTPError(http.StatusBadRequest, "Invalid ID")
}
requiredQueryIDs, err := parseStringToUUIDArray(req.RequiredQueries)
if err != nil {
return echo.NewHTTPError(http.StatusBadRequest, "Invalid Required IDs")
}
err = s.svc.Query.Update(ctx.Request().Context(), &queryprocessor.Update{
err := s.svc.Query.Update(ctx.Request().Context(), &queryprocessor.Update{
ActiveVersion: req.ActiveVersion,
Config: req.Config,
RequiredQueryIDs: requiredQueryIDs,
ID: uid,
RequiredQueryIDs: req.RequiredQueries,
ID: id,
})
if err != nil {
return echo.NewHTTPError(http.StatusBadRequest, fmt.Sprintf("Unable to update query: %s", err))
@@ -106,24 +86,16 @@ func (s *Controllers) UpdateQuery(ctx echo.Context, id string) error {
return ctx.NoContent(http.StatusOK)
}
func (s *Controllers) TestQuery(ctx echo.Context, id string) error {
queryId, err := uuid.Parse(id)
if err != nil {
return echo.NewHTTPError(http.StatusBadRequest, "Invalid Query ID")
}
func (s *Controllers) TestQuery(ctx echo.Context, id types.UUID) error {
req := QueryTestRequest{}
if err := ctx.Bind(&req); err != nil {
return echo.NewHTTPError(http.StatusBadRequest, err)
}
docId, err := uuid.Parse(req.DocumentId)
if err != nil {
return echo.NewHTTPError(http.StatusBadRequest, "Invalid Doc ID")
}
value, err := s.svc.Query.Test(ctx.Request().Context(), query.Test{
QueryID: queryId,
QueryID: id,
QueryVersion: req.QueryVersion,
DocumentID: docId,
DocumentID: req.DocumentId,
})
if err != nil {
return echo.NewHTTPError(http.StatusBadRequest, fmt.Sprintf("Unable to test query: %s", err))
+6 -6
View File
@@ -100,7 +100,7 @@ func TestListQueries(t *testing.T) {
assert.NotNil(t, res.Queries)
assert.ElementsMatch(t, res.Queries, []queryservice.Query{
{
Id: id.String(),
Id: id,
Type: queryservice.CONTEXTFULL,
ActiveVersion: 1,
LatestVersion: 2,
@@ -137,7 +137,7 @@ func TestGetQuery(t *testing.T) {
AddRow(database.MustToDBUUID(id), repository.QuerytypeContextFull, int32(1), int32(2), nil, []pgtype.UUID{}),
)
err = cons.GetQuery(ctx, id.String())
err = cons.GetQuery(ctx, id)
assert.Nil(t, err)
assert.Equal(t, http.StatusOK, rec.Code)
@@ -145,7 +145,7 @@ func TestGetQuery(t *testing.T) {
err = json.Unmarshal(rec.Body.Bytes(), &res)
assert.Nil(t, err)
assert.EqualExportedValues(t, queryservice.Query{
Id: id.String(),
Id: id,
Type: queryservice.CONTEXTFULL,
ActiveVersion: 1,
LatestVersion: 2,
@@ -194,7 +194,7 @@ func TestUpdateQuery(t *testing.T) {
WillReturnResult(pgxmock.NewResult("", 1))
pool.ExpectCommit()
err = cons.UpdateQuery(ctx, id.String())
err = cons.UpdateQuery(ctx, id)
assert.Nil(t, err)
assert.Equal(t, http.StatusOK, rec.Code)
assert.Empty(t, rec.Body.String())
@@ -216,7 +216,7 @@ func TestTestQuery(t *testing.T) {
})
body := queryservice.QueryTestRequest{
DocumentId: uuid.NewString(),
DocumentId: uuid.New(),
}
bodyBytes, err := json.Marshal(body)
assert.Nil(t, err)
@@ -229,7 +229,7 @@ func TestTestQuery(t *testing.T) {
id := uuid.New()
err = cons.TestQuery(ctx, id.String())
err = cons.TestQuery(ctx, id)
assert.Nil(t, err)
assert.Equal(t, http.StatusOK, rec.Code)