diff --git a/api/queryService/api.gen.go b/api/queryService/api.gen.go index 03aa3521..c339a632 100644 --- a/api/queryService/api.gen.go +++ b/api/queryService/api.gen.go @@ -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", - "Qgp0LoWGaTI5uPOdXC0Z7T/gnVwhRpECjt0ljXRW8LKn3TNPElmYvDBLLgn2cvrElk8RE+hhw8imIRX9", - "xXKUMg7ogXGOVoBSWQhqlcF3nOXc6Xs/n80eVwX5E8x+9ujtyOh+9ngnV+5fwzLQBmf5fvnoBTO6n/7F", - "8r5Da4NN4YzxbwVpMk/+NavZOwvUnXnjX/u1h4RjNKnk3EaRu64UdY2SS63Zild2sLa3AkG7u4sis3rs", - "uTgYsOqYWOZKrhVoS7wUMw60oby+n1d+46lwnDaBL47YogF0mzMpA06XKeMGVM91ProHDlRNZA5ohTVQ", - "JAVyG5EnCdpiXvjbMQPZoP0/2r1edFI7B1YK7+xnJtag7QFOOVe1GeVY4Qzs/u61QdBlGTh6WI21QfYx", - "kmktcBohnDJRUUyjlKmRwvrCxAiXlj6e3RegdjY4FNxo696rkn9Ap4NRNujp43sTrAgOjmOISF5komNq", - "IgVlZQQZyYrzas9+Eigaj732SWkFz0omrDnioHm69kvzz1ChIS14GSY9D1v87ghts/jAvo07TBoWqY4y", - "YPjzpg2PBBx//bQCpdLUijwctF6aDbb61y55q/Ij4VIDXTJhQG0xTyaJzEE0P3NIzbK7TLH1pu97Jggv", - "KLiY7//qC2sL+h/QGq97Enkf+78Jdl8AYtTmipSB8nlSGGZ2w1yP8PyTXPmS4m8qJmJuXcqifcx9mZrK", - "yS7JWN4tZhPJORAje5y/+RRlkgLvBlpvhuUWlI7SN5gqrCldmZSirdBUqgybZJ4wYd7/VF/QMm3ts4jj", - "fsSp/TMbF0wInC3po5JW87bONftS17F4vbgor4a1loRhA9SepTdEcVsumON282uea7eMCZYV2ZJYYoI6", - "rjIsrnS6QmMDiEpSZJZ/QcoTdRv4bk5TbHfaTK9H6uzzhABaRaG4TSIn7sA1OeT9kHN5QsW5i2qvqq7e", - "ofHY169QtHnBdlkvA11BESWzLzcYRWaDjS/wc5kX1g7ucL4QmY57vWsoGzJU/b4Xr3wLu8bXJM2t//jg", - "9I/z9A6TPjNt/luACvi32XBfP2ifyu6ywIcFo0GxmnaDpWGpto/5XkLnpKfz1vnZSMiIFClbd6Wfu+8L", - "5V/8S3gqyZ1AMr6COy7n9JT4lFuX0CwH6VCuDLFwcaGf8oJQfh5BoRu7sDdzORGdZNMxVZRasdbd06AX", - "8HAEth/FoG531FI3oM1XcG+VXXOVMbE3W9ZlXxU67VulpSleYya0OZJ+o2T/Xw/DrdxCg8fFvv6K9Sk1", - "UfM2h+cYsI/vTHYN5N5yu5f46oqEgzuAHlE2eIHx0wQmtNVd50BssNE+n+xy6ASI8hX50/XVb8vL32++", - "fji/ufqaTJLzq99uLn+/WX789vlz7yus0xvrRg8FbL+PHgTtZ8bpUih5YrwedthSMn8Rx+0m6r1rAqay", - "q/nDl0XlRu37OPujK0U2oE24qwa1ZcRnbMOMazj3rfvwZZFMkgqd5N30bHrmeuA5CJyzZJ68n55N39sC", - "EpuNu9TMv3D7OkL6qHAQLF1w1Qi7ABnezx+Y8T3yXMkto0AR9TOAqe+1+BMtaLU/9CQ8LKDNL5LuQog2", - "oVmB85wz34ef3WnPLx/vhqJha4CzbzuZUQW4L7xTu4v+dPbuxXTXPR+n+MB23lrEnYwiXRACWqcF57up", - "Bebns7OeSCu2mLshh7MUWklqV+8niS6yDNtKKhi1hYklB15r6/Ze7bWnTXJrt5Y4zx4Z3VudazB9kcwo", - "BluHtvZhhpSQr3aIGY0WF12IfwVT4Vu3q5P5H8f7B0GwkUgFvc7f7ELLz7K5M/dFQhvSSQOewxh724H7", - "7MXgrttrcbgrVxiLcLPF7/b83OOGoTEmTTl/ajPiVzAIN7BaXBwhhAsAZBMLidqPWpjLvS2Xt3SLerrf", - "/DwmuJfel+TBa0WbkCNHRZuzKJxFSEHPigwjGXNAGH+BijMD4eNOrmZ+DhPPFAvBDHP0aUxPcyXtzbps", - "CdM/Pwp8pcTQnjO+pcxw2ZqGvxIDPslVPGAEq9RT1QYDwnA4woDjOeR8A+RPTwFSKGUp6KbG1tdbE9w2", - "Hep5NDwtdtQC33bmaP9UIk6JDdZoBSBQNVmPA3xZT+ajODs8Sm90SExHIG0hnpHm0GR8wdDq/Q3UDc2O", - "3y+7T3K1oGPgtyoWF1XV3O40vvkCojJrDws+tYzXLiUiLl4vH6gOOsC0ioTmyU4sFdoKxlYMJ3KgDgFt", - "tT9GFdEzDRiVnwY58JolxUi2VaVFC5hBqtnY03hZHww4vN3Qbv6ox/2shihmQDHc5V2zgf6Kvt5U0+Pq", - "Hw5v8LJvDL5FEAXJtSvvKyOU0LhdLfcf0RXwDZMnNwX8XOB1/KvZGH5LhZ9H5ZU7AvfBsBFQG452Qj/A", - "g308rZfIPiGIV73fH6cZECZjMZBfpQ8w4NU+0VcQtRJ817XHZ/aGh4/I6M+B/wfI3c0m+akNAI/jaybr", - "AaZUSfqJwWJmyuFRb2K4/A6k8JnBDYdU4aY7OJoj2r9vPegRgH5WKCmnMG+bSc2h3Hg6vbT+MPTqiWY3", - "DsfwS5jn5CgnaJhwdg+obT/SX5SkBanmImDLykLxZJ5sjMn1fDbDOZuGX+ZPicxm23eJhS9oO5R3VRJO", - "+/9VANQSp5yKVHRp98T2k3FiWvVvQ1pf/TtWZl2yBWEt842V4vsBDSntRsD+dv//AAAA///KtJqFMTMA", - "AA==", + "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", } // GetSwagger returns the content of the embedded swagger specification file diff --git a/api/queryService/client.go b/api/queryService/client.go index e2232070..108f323d 100644 --- a/api/queryService/client.go +++ b/api/queryService/client.go @@ -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, }) diff --git a/api/queryService/client_test.go b/api/queryService/client_test.go index cffd4f16..d420298b 100644 --- a/api/queryService/client_test.go +++ b/api/queryService/client_test.go @@ -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()) diff --git a/api/queryService/controllers.go b/api/queryService/controllers.go index d19c0729..a5d9432a 100644 --- a/api/queryService/controllers.go +++ b/api/queryService/controllers.go @@ -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 { diff --git a/api/queryService/export.go b/api/queryService/export.go index e915f938..62130839 100644 --- a/api/queryService/export.go +++ b/api/queryService/export.go @@ -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"}) } diff --git a/api/queryService/export_test.go b/api/queryService/export_test.go index ed5bbddc..ebb42a12 100644 --- a/api/queryService/export_test.go +++ b/api/queryService/export_test.go @@ -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) diff --git a/api/queryService/job.go b/api/queryService/job.go new file mode 100644 index 00000000..dd1479b1 --- /dev/null +++ b/api/queryService/job.go @@ -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) +} diff --git a/api/queryService/job_test.go b/api/queryService/job_test.go new file mode 100644 index 00000000..5297de20 --- /dev/null +++ b/api/queryService/job_test.go @@ -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()) +} diff --git a/api/queryService/jobcollector.go b/api/queryService/jobcollector.go index 983a0668..9c405225 100644 --- a/api/queryService/jobcollector.go +++ b/api/queryService/jobcollector.go @@ -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, diff --git a/api/queryService/jobcollector_test.go b/api/queryService/jobcollector_test.go index abb18d79..453bd716 100644 --- a/api/queryService/jobcollector_test.go +++ b/api/queryService/jobcollector_test.go @@ -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), diff --git a/api/queryService/parse.go b/api/queryService/parse.go index b2992bd9..1f9cd462 100644 --- a/api/queryService/parse.go +++ b/api/queryService/parse.go @@ -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, } diff --git a/api/queryService/parse_test.go b/api/queryService/parse_test.go index a54dddbc..e1ca7bcd 100644 --- a/api/queryService/parse_test.go +++ b/api/queryService/parse_test.go @@ -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, diff --git a/api/queryService/query.go b/api/queryService/query.go index eba054d0..2e116504 100644 --- a/api/queryService/query.go +++ b/api/queryService/query.go @@ -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)) diff --git a/api/queryService/query_test.go b/api/queryService/query_test.go index efdf4dd6..d830e1b3 100644 --- a/api/queryService/query_test.go +++ b/api/queryService/query_test.go @@ -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) diff --git a/cmd/queryService/main.go b/cmd/queryService/main.go index db363a99..f6fbe326 100644 --- a/cmd/queryService/main.go +++ b/cmd/queryService/main.go @@ -7,6 +7,7 @@ import ( "queryorchestration/internal/client" documentclean "queryorchestration/internal/document_clean" "queryorchestration/internal/export" + "queryorchestration/internal/job" "queryorchestration/internal/job/collector" "queryorchestration/internal/query" "queryorchestration/internal/server" @@ -31,12 +32,17 @@ func main() { DocumentClean: clean, }) cli := client.New(cfg.Database) + jbb := job.New(cfg.Database, &job.Services{ + Collector: col, + Client: cli, + }) services := &queryservice.Services{ Export: exp, JobCollector: col, Query: que, Client: cli, + Job: jbb, } cons := queryservice.NewControllers(cfg.Validator, services) diff --git a/database/queries/job.sql b/database/queries/job.sql index 2db186e5..3bf93c12 100644 --- a/database/queries/job.sql +++ b/database/queries/job.sql @@ -2,4 +2,7 @@ SELECT id, clientId, canSync FROM jobs WHERE id = $1 LIMIT 1; -- name: CreateJob :one -INSERT INTO jobs (clientId) VALUES ($1) RETURNING id; \ No newline at end of file +INSERT INTO jobs (clientId) VALUES ($1) RETURNING id; + +-- name: UpdateJob :exec +UPDATE jobs SET canSync = $1 WHERE id = $2; \ No newline at end of file diff --git a/internal/database/repository/job.sql.go b/internal/database/repository/job.sql.go index e9277ca2..88a28134 100644 --- a/internal/database/repository/job.sql.go +++ b/internal/database/repository/job.sql.go @@ -38,3 +38,20 @@ func (q *Queries) GetJob(ctx context.Context, id pgtype.UUID) (*Job, error) { err := row.Scan(&i.ID, &i.Clientid, &i.Cansync) return &i, err } + +const updateJob = `-- name: UpdateJob :exec +UPDATE jobs SET canSync = $1 WHERE id = $2 +` + +type UpdateJobParams struct { + Cansync bool `db:"cansync"` + ID pgtype.UUID `db:"id"` +} + +// UpdateJob +// +// UPDATE jobs SET canSync = $1 WHERE id = $2 +func (q *Queries) UpdateJob(ctx context.Context, arg *UpdateJobParams) error { + _, err := q.db.Exec(ctx, updateJob, arg.Cansync, arg.ID) + return err +} diff --git a/internal/database/repository/job_test.go b/internal/database/repository/job_test.go index 3176716d..6f1d8ff5 100644 --- a/internal/database/repository/job_test.go +++ b/internal/database/repository/job_test.go @@ -36,4 +36,18 @@ func TestJob(t *testing.T) { Clientid: clientId, Cansync: false, }, job) + + err = queries.UpdateJob(ctx, &repository.UpdateJobParams{ + Cansync: true, + ID: id, + }) + assert.Nil(t, err) + + job, err = queries.GetJob(ctx, id) + assert.Nil(t, err) + assert.EqualExportedValues(t, &repository.Job{ + ID: id, + Clientid: clientId, + Cansync: true, + }, job) } diff --git a/internal/job/collector/create.go b/internal/job/collector/create.go index 3e9f988c..44c40163 100644 --- a/internal/job/collector/create.go +++ b/internal/job/collector/create.go @@ -14,7 +14,7 @@ type CreateParams struct { JobID uuid.UUID MinCleanVersion *int32 MinTextVersion *int32 - Fields map[string]uuid.UUID + Fields *map[string]uuid.UUID } func (s *Service) Create(ctx context.Context, params *CreateParams) (uuid.UUID, error) { @@ -35,7 +35,7 @@ type dbCreateParams struct { JobID pgtype.UUID MinCleanVersion *int32 MinTextVersion *int32 - Fields map[string]pgtype.UUID + Fields *map[string]pgtype.UUID } type fields struct { @@ -102,15 +102,17 @@ func (s *Service) submitCreate(ctx context.Context, params *dbCreateParams) (uui } } - for key, field := range params.Fields { - err = qtx.AddCollectorQuery(ctx, &repository.AddCollectorQueryParams{ - Collectorid: dbID, - Name: key, - Queryid: field, - Addedversion: latestVersion, - }) - if err != nil { - return err + if params.Fields != nil { + for key, field := range *params.Fields { + err = qtx.AddCollectorQuery(ctx, &repository.AddCollectorQueryParams{ + Collectorid: dbID, + Name: key, + Queryid: field, + Addedversion: latestVersion, + }) + if err != nil { + return err + } } } diff --git a/internal/job/collector/create_test.go b/internal/job/collector/create_test.go index d9df07dc..ffe28f22 100644 --- a/internal/job/collector/create_test.go +++ b/internal/job/collector/create_test.go @@ -38,12 +38,12 @@ func TestCreate(t *testing.T) { JobID: uuid.New(), MinCleanVersion: &minCleanV, MinTextVersion: &minTextV, - Fields: map[string]uuid.UUID{ + Fields: &map[string]uuid.UUID{ "example_key": uuid.New(), }, } - pool.ExpectQuery("name: AllQueriesExist :one").WithArgs(database.MustToDBUUIDArray([]uuid.UUID{create.Fields["example_key"]})).WillReturnRows( + pool.ExpectQuery("name: AllQueriesExist :one").WithArgs(database.MustToDBUUIDArray([]uuid.UUID{(*create.Fields)["example_key"]})).WillReturnRows( pgxmock.NewRows([]string{"all_exist"}). AddRow(true), ) @@ -54,7 +54,7 @@ func TestCreate(t *testing.T) { ) pool.ExpectExec("name: AddCollectorCodeVersion :exec").WithArgs(database.MustToDBUUID(id), int32(1), *create.MinCleanVersion, *create.MinTextVersion). WillReturnResult(pgxmock.NewResult("", 1)) - pool.ExpectExec("name: AddCollectorQuery :exec").WithArgs(database.MustToDBUUID(id), "example_key", database.MustToDBUUID(create.Fields["example_key"]), int32(1)). + pool.ExpectExec("name: AddCollectorQuery :exec").WithArgs(database.MustToDBUUID(id), "example_key", database.MustToDBUUID((*create.Fields)["example_key"]), int32(1)). WillReturnResult(pgxmock.NewResult("", 1)) pool.ExpectCommit() diff --git a/internal/job/collector/createprivate_test.go b/internal/job/collector/createprivate_test.go index 82b04af0..649f86c7 100644 --- a/internal/job/collector/createprivate_test.go +++ b/internal/job/collector/createprivate_test.go @@ -40,12 +40,12 @@ func TestGetCreateParams(t *testing.T) { JobID: uuid.New(), MinCleanVersion: &minCleanV, MinTextVersion: &minTextV, - Fields: map[string]uuid.UUID{ + Fields: &map[string]uuid.UUID{ "example_key": uuid.New(), }, } - pool.ExpectQuery("name: AllQueriesExist :one").WithArgs(database.MustToDBUUIDArray([]uuid.UUID{params.Fields["example_key"]})).WillReturnRows( + pool.ExpectQuery("name: AllQueriesExist :one").WithArgs(database.MustToDBUUIDArray([]uuid.UUID{(*params.Fields)["example_key"]})).WillReturnRows( pgxmock.NewRows([]string{"all_exist"}). AddRow(true), ) @@ -56,13 +56,13 @@ func TestGetCreateParams(t *testing.T) { JobID: database.MustToDBUUID(params.JobID), MinCleanVersion: &minCleanV, MinTextVersion: &minTextV, - Fields: map[string]pgtype.UUID{ - "example_key": database.MustToDBUUID(params.Fields["example_key"]), + Fields: &map[string]pgtype.UUID{ + "example_key": database.MustToDBUUID((*params.Fields)["example_key"]), }, }, dbparams) - params.Fields["second_key"] = params.Fields["example_key"] - assert.Len(t, params.Fields, 2) + (*params.Fields)["second_key"] = (*params.Fields)["example_key"] + assert.Len(t, *params.Fields, 2) _, err = svc.getCreateParams(ctx, ¶ms) assert.Error(t, err) } @@ -94,7 +94,7 @@ func TestSubmitCreate(t *testing.T) { JobID: database.MustToDBUUID(uuid.New()), MinCleanVersion: &minCleanV, MinTextVersion: &minTextV, - Fields: map[string]pgtype.UUID{ + Fields: &map[string]pgtype.UUID{ "example_key": database.MustToDBUUID(uuid.New()), }, } @@ -106,7 +106,7 @@ func TestSubmitCreate(t *testing.T) { ) pool.ExpectExec("name: AddCollectorCodeVersion :exec").WithArgs(database.MustToDBUUID(id), int32(1), *params.MinCleanVersion, *params.MinTextVersion). WillReturnResult(pgxmock.NewResult("", 1)) - pool.ExpectExec("name: AddCollectorQuery :exec").WithArgs(database.MustToDBUUID(id), "example_key", params.Fields["example_key"], int32(1)). + pool.ExpectExec("name: AddCollectorQuery :exec").WithArgs(database.MustToDBUUID(id), "example_key", (*params.Fields)["example_key"], int32(1)). WillReturnResult(pgxmock.NewResult("", 1)) pool.ExpectCommit() diff --git a/internal/job/collector/update.go b/internal/job/collector/update.go index 3645627b..707edb01 100644 --- a/internal/job/collector/update.go +++ b/internal/job/collector/update.go @@ -52,13 +52,9 @@ func (s *Service) getUpdateParams(ctx context.Context, current *Collector, param return nil, err } - var ufields *map[string]pgtype.UUID - if params.Fields != nil { - ufs, err := s.normalizeFieldsToDB(ctx, *params.Fields) - if err != nil { - return nil, err - } - ufields = &ufs + fs, err := s.normalizeFieldsToDB(ctx, params.Fields) + if err != nil { + return nil, err } err = s.normalizeActiveVersion(current, params) @@ -69,7 +65,7 @@ func (s *Service) getUpdateParams(ctx context.Context, current *Collector, param if params.ActiveVersion == nil && params.MinCleanVersion == nil && params.MinTextVersion == nil && - ufields == nil { + fs == nil { return nil, errors.New("no changes") } @@ -78,7 +74,7 @@ func (s *Service) getUpdateParams(ctx context.Context, current *Collector, param ActiveVersion: params.ActiveVersion, MinCleanVersion: params.MinCleanVersion, MinTextVersion: params.MinTextVersion, - Fields: ufields, + Fields: fs, }, nil } @@ -136,9 +132,15 @@ func (s *Service) normalizeActiveVersion(current *Collector, params *UpdateParam return nil } -func (s *Service) normalizeFieldsToDB(ctx context.Context, ofields map[string]uuid.UUID) (map[string]pgtype.UUID, error) { +func (s *Service) normalizeFieldsToDB(ctx context.Context, ofields *map[string]uuid.UUID) (*map[string]pgtype.UUID, error) { + if ofields == nil || *ofields == nil { + return nil, nil + } else if len(*ofields) == 0 { + return nil, nil + } + fids := []uuid.UUID{} - for _, id := range ofields { + for _, id := range *ofields { fids = append(fids, id) } vfields := fields{ @@ -148,17 +150,16 @@ func (s *Service) normalizeFieldsToDB(ctx context.Context, ofields map[string]uu err := s.svc.Query.NormalizeQueryIDs(ctx, &vfields) if err != nil { return nil, err - } - if len(ofields) != len(*vfields.values) { + } else if len(*ofields) != len(*vfields.values) { return nil, errors.New("duplicate output fields") } - ufields := map[string]pgtype.UUID{} - for key, value := range ofields { - ufields[key] = database.MustToDBUUID(value) + fs := map[string]pgtype.UUID{} + for name, id := range *ofields { + fs[name] = database.MustToDBUUID(id) } - return ufields, nil + return &fs, nil } func (s *Service) submitUpdate(ctx context.Context, current *Collector, params *dbUpdateParams) error { diff --git a/internal/job/collector/updateprivate_test.go b/internal/job/collector/updateprivate_test.go index 3e92d0a7..cc053be7 100644 --- a/internal/job/collector/updateprivate_test.go +++ b/internal/job/collector/updateprivate_test.go @@ -138,6 +138,7 @@ func TestSubmitUpdate(t *testing.T) { WillReturnResult(pgxmock.NewResult("", 1)) pool.ExpectExec("name: RemoveCollectorQuery :exec").WithArgs(&rv, database.MustToDBUUID(current.Fields["original_key"]), database.MustToDBUUID(current.ID)). WillReturnResult(pgxmock.NewResult("", 1)) + pool.MatchExpectationsInOrder(false) pool.ExpectExec("name: AddCollectorQuery :exec").WithArgs(database.MustToDBUUID(current.ID), "example_key", (*params.Fields)["example_key"], int32(2)). WillReturnResult(pgxmock.NewResult("", 1)) pool.ExpectExec("name: AddCollectorQuery :exec").WithArgs(database.MustToDBUUID(current.ID), "second_key", (*params.Fields)["second_key"], int32(2)). @@ -181,9 +182,9 @@ func TestNormalizeFieldsToDB(t *testing.T) { AddRow(true), ) - dbparams, err := svc.normalizeFieldsToDB(ctx, fields) + dbparams, err := svc.normalizeFieldsToDB(ctx, &fields) assert.Nil(t, err) - assert.EqualExportedValues(t, map[string]pgtype.UUID{ + assert.EqualExportedValues(t, &map[string]pgtype.UUID{ "example_key": database.MustToDBUUID(fields["example_key"]), }, dbparams) @@ -194,7 +195,7 @@ func TestNormalizeFieldsToDB(t *testing.T) { AddRow(true), ) - _, err = svc.normalizeFieldsToDB(ctx, fields) + _, err = svc.normalizeFieldsToDB(ctx, &fields) assert.Error(t, err) } diff --git a/internal/job/create.go b/internal/job/create.go new file mode 100644 index 00000000..eb5cd05a --- /dev/null +++ b/internal/job/create.go @@ -0,0 +1,27 @@ +package job + +import ( + "context" + "queryorchestration/internal/database" + "queryorchestration/internal/job/collector" + + "github.com/google/uuid" +) + +func (s *Service) Create(ctx context.Context, clientID uuid.UUID) (uuid.UUID, error) { + did, err := s.db.Queries.CreateJob(ctx, database.MustToDBUUID(clientID)) + if err != nil { + return uuid.Nil, err + } + + id := database.MustToUUID(did) + + _, err = s.svc.Collector.Create(ctx, &collector.CreateParams{ + JobID: id, + }) + if err != nil { + return uuid.Nil, err + } + + return id, nil +} diff --git a/internal/job/create_test.go b/internal/job/create_test.go new file mode 100644 index 00000000..1c1035be --- /dev/null +++ b/internal/job/create_test.go @@ -0,0 +1,53 @@ +package job_test + +import ( + "context" + "queryorchestration/internal/database" + "queryorchestration/internal/database/repository" + "queryorchestration/internal/job" + "queryorchestration/internal/job/collector" + "testing" + + "github.com/google/uuid" + "github.com/jackc/pgx/v5" + "github.com/pashagolub/pgxmock/v3" + "github.com/stretchr/testify/assert" +) + +func TestCreate(t *testing.T) { + ctx := context.Background() + + 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, + } + + svc := job.New(db, &job.Services{ + Collector: collector.New(db, &collector.Services{}), + }) + + job := job.Job{ + ID: uuid.New(), + ClientID: uuid.New(), + } + + pool.ExpectQuery("name: CreateJob :one").WithArgs(database.MustToDBUUID(job.ClientID)).WillReturnRows( + pgxmock.NewRows([]string{"id"}). + AddRow(database.MustToDBUUID(job.ID)), + ) + pool.ExpectBeginTx(pgx.TxOptions{}) + pool.ExpectQuery("name: CreateCollector :one").WithArgs(database.MustToDBUUID(job.ID)).WillReturnRows( + pgxmock.NewRows([]string{"id"}). + AddRow(database.MustToDBUUID(uuid.New())), + ) + pool.ExpectCommit() + + aid, err := svc.Create(ctx, job.ClientID) + assert.Nil(t, err) + assert.Equal(t, job.ID, aid) +} diff --git a/internal/job/get.go b/internal/job/get.go new file mode 100644 index 00000000..5ebebe9a --- /dev/null +++ b/internal/job/get.go @@ -0,0 +1,31 @@ +package job + +import ( + "context" + "queryorchestration/internal/database" + + "github.com/google/uuid" +) + +func (s *Service) Get(ctx context.Context, id uuid.UUID) (*Job, error) { + job, err := s.db.Queries.GetJob(ctx, database.MustToDBUUID(id)) + if err != nil { + return nil, err + } + + client, err := s.svc.Client.Get(ctx, database.MustToUUID(job.Clientid)) + if err != nil { + return nil, err + } + + canSync := job.Cansync + if !client.CanSync { + canSync = false + } + + return &Job{ + ID: id, + ClientID: database.MustToUUID(job.Clientid), + CanSync: canSync, + }, nil +} diff --git a/internal/job/get_test.go b/internal/job/get_test.go new file mode 100644 index 00000000..3f9bcf91 --- /dev/null +++ b/internal/job/get_test.go @@ -0,0 +1,76 @@ +package job_test + +import ( + "context" + "queryorchestration/internal/client" + "queryorchestration/internal/database" + "queryorchestration/internal/database/repository" + "queryorchestration/internal/job" + "queryorchestration/internal/job/collector" + "testing" + + "github.com/google/uuid" + "github.com/pashagolub/pgxmock/v3" + "github.com/stretchr/testify/assert" +) + +func TestGet(t *testing.T) { + ctx := context.Background() + + 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, + } + + svc := job.New(db, &job.Services{ + Collector: collector.New(db, &collector.Services{}), + Client: client.New(db), + }) + + 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", false), + ) + + ajob, err := svc.Get(ctx, j.ID) + assert.Nil(t, err) + assert.EqualExportedValues(t, &job.Job{ + ID: j.ID, + ClientID: j.ClientID, + CanSync: false, + }, ajob) + + 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), + ) + + ajob, err = svc.Get(ctx, j.ID) + assert.Nil(t, err) + assert.EqualExportedValues(t, &job.Job{ + ID: j.ID, + ClientID: j.ClientID, + CanSync: true, + }, ajob) +} diff --git a/internal/job/service.go b/internal/job/service.go new file mode 100644 index 00000000..ae2bb2e8 --- /dev/null +++ b/internal/job/service.go @@ -0,0 +1,32 @@ +package job + +import ( + "queryorchestration/internal/client" + "queryorchestration/internal/database" + "queryorchestration/internal/job/collector" + + "github.com/google/uuid" +) + +type Job struct { + ID uuid.UUID + ClientID uuid.UUID + CanSync bool +} + +type Services struct { + Collector *collector.Service + Client *client.Service +} + +type Service struct { + db *database.Connection + svc *Services +} + +func New(db *database.Connection, svc *Services) *Service { + return &Service{ + db, + svc, + } +} diff --git a/internal/job/service_test.go b/internal/job/service_test.go new file mode 100644 index 00000000..eff737fa --- /dev/null +++ b/internal/job/service_test.go @@ -0,0 +1,26 @@ +package job_test + +import ( + "queryorchestration/internal/database" + "queryorchestration/internal/database/repository" + "queryorchestration/internal/job" + "testing" + + "github.com/pashagolub/pgxmock/v3" + "github.com/stretchr/testify/assert" +) + +func TestService(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, + } + + svc := job.New(db, &job.Services{}) + assert.NotNil(t, svc) +} diff --git a/internal/job/update.go b/internal/job/update.go new file mode 100644 index 00000000..386ff2c1 --- /dev/null +++ b/internal/job/update.go @@ -0,0 +1,63 @@ +package job + +import ( + "context" + "errors" + "queryorchestration/internal/database" + "queryorchestration/internal/database/repository" + + "github.com/google/uuid" +) + +type Update struct { + ID uuid.UUID + CanSync *bool +} + +func (s *Service) Update(ctx context.Context, update *Update) error { + if update == nil { + return errors.New("Update required") + } + + current, err := s.Get(ctx, update.ID) + if err != nil { + return err + } + + err = s.normalizeCanSync(ctx, current, update) + if err != nil { + return err + } + + if update.CanSync == nil { + return errors.New("no changes") + } + + err = s.db.Queries.UpdateJob(ctx, &repository.UpdateJobParams{ + ID: database.MustToDBUUID(update.ID), + Cansync: *update.CanSync, + }) + if err != nil { + return err + } + + return nil +} + +func (s *Service) normalizeCanSync(ctx context.Context, current *Job, update *Update) error { + if update.CanSync == nil { + return nil + } else if current.CanSync == *update.CanSync { + update.CanSync = nil + return nil + } + + client, err := s.svc.Client.Get(ctx, current.ClientID) + if err != nil { + return err + } else if !client.CanSync && *update.CanSync { + return errors.New("client not allowing sync") + } + + return nil +} diff --git a/internal/job/update_test.go b/internal/job/update_test.go new file mode 100644 index 00000000..951ecdb5 --- /dev/null +++ b/internal/job/update_test.go @@ -0,0 +1,62 @@ +package job_test + +import ( + "context" + "queryorchestration/internal/client" + "queryorchestration/internal/database" + "queryorchestration/internal/database/repository" + "queryorchestration/internal/job" + "testing" + + "github.com/google/uuid" + "github.com/pashagolub/pgxmock/v3" + "github.com/stretchr/testify/assert" +) + +func TestUpdate(t *testing.T) { + ctx := context.Background() + + 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, + } + + svc := job.New(db, &job.Services{ + Client: client.New(db), + }) + + 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), + ) + 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), + ) + ucs := !j.CanSync + pool.ExpectExec("name: UpdateJob :exec").WithArgs(ucs, database.MustToDBUUID(j.ID)). + WillReturnResult(pgxmock.NewResult("", 1)) + + err = svc.Update(ctx, &job.Update{ + ID: j.ID, + CanSync: &ucs, + }) + assert.Nil(t, err) +} diff --git a/internal/job/updateprivate_test.go b/internal/job/updateprivate_test.go new file mode 100644 index 00000000..a5742a61 --- /dev/null +++ b/internal/job/updateprivate_test.go @@ -0,0 +1,93 @@ +package job + +import ( + "context" + "queryorchestration/internal/client" + "queryorchestration/internal/database" + "queryorchestration/internal/database/repository" + "testing" + + "github.com/google/uuid" + "github.com/pashagolub/pgxmock/v3" + "github.com/stretchr/testify/assert" +) + +func TestNormalizeCanSync(t *testing.T) { + ctx := context.Background() + + 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, + } + + svc := New(db, &Services{ + Client: client.New(db), + }) + + j := Job{ + ID: uuid.New(), + ClientID: uuid.New(), + CanSync: false, + } + + update := Update{ + ID: j.ID, + } + + err = svc.normalizeCanSync(ctx, &j, &update) + assert.Nil(t, err) + assert.Nil(t, update.CanSync) + + cs := false + update.CanSync = &cs + err = svc.normalizeCanSync(ctx, &j, &update) + assert.Nil(t, err) + assert.Nil(t, update.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", false), + ) + + cs = true + update.CanSync = &cs + err = svc.normalizeCanSync(ctx, &j, &update) + assert.Error(t, err) + + 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), + ) + + cs = false + update.CanSync = &cs + err = svc.normalizeCanSync(ctx, &j, &update) + assert.Nil(t, err) + assert.Nil(t, update.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), + ) + + cs = true + update.CanSync = &cs + err = svc.normalizeCanSync(ctx, &j, &update) + assert.Nil(t, err) + assert.True(t, *update.CanSync) + + j.CanSync = true + cs = true + update.CanSync = &cs + err = svc.normalizeCanSync(ctx, &j, &update) + assert.Nil(t, err) + assert.Nil(t, update.CanSync) +} diff --git a/pkg/queryService/api.gen.go b/pkg/queryService/api.gen.go index e163dbe3..062f9555 100644 --- a/pkg/queryService/api.gen.go +++ b/pkg/queryService/api.gen.go @@ -14,6 +14,7 @@ import ( "strings" "github.com/oapi-codegen/runtime" + openapi_types "github.com/oapi-codegen/runtime/types" ) // Defines values for ExportStatus. @@ -59,7 +60,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"` @@ -86,7 +87,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 @@ -107,7 +108,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. @@ -116,7 +129,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"` @@ -131,7 +144,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"` @@ -149,7 +162,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. @@ -167,6 +180,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. @@ -182,13 +207,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"` @@ -200,7 +225,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"` @@ -209,7 +234,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"` @@ -233,7 +258,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. @@ -242,9 +267,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 @@ -336,12 +367,17 @@ type ClientInterface interface { CreateClient(ctx context.Context, body CreateClientJSONRequestBody, reqEditors ...RequestEditorFn) (*http.Response, error) // GetClient request - GetClient(ctx context.Context, id string, reqEditors ...RequestEditorFn) (*http.Response, error) + GetClient(ctx context.Context, id openapi_types.UUID, reqEditors ...RequestEditorFn) (*http.Response, error) // UpdateClientWithBody request with any body - UpdateClientWithBody(ctx context.Context, id string, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*http.Response, error) + UpdateClientWithBody(ctx context.Context, id openapi_types.UUID, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*http.Response, error) - UpdateClient(ctx context.Context, id string, body UpdateClientJSONRequestBody, reqEditors ...RequestEditorFn) (*http.Response, error) + UpdateClient(ctx context.Context, id openapi_types.UUID, body UpdateClientJSONRequestBody, reqEditors ...RequestEditorFn) (*http.Response, error) + + // CreateJobWithBody request with any body + CreateJobWithBody(ctx context.Context, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*http.Response, error) + + CreateJob(ctx context.Context, body CreateJobJSONRequestBody, reqEditors ...RequestEditorFn) (*http.Response, error) // TriggerExportWithBody request with any body TriggerExportWithBody(ctx context.Context, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*http.Response, error) @@ -349,15 +385,23 @@ type ClientInterface interface { TriggerExport(ctx context.Context, body TriggerExportJSONRequestBody, reqEditors ...RequestEditorFn) (*http.Response, error) // ExportState request - ExportState(ctx context.Context, id string, reqEditors ...RequestEditorFn) (*http.Response, error) + ExportState(ctx context.Context, id openapi_types.UUID, reqEditors ...RequestEditorFn) (*http.Response, error) + + // GetJob request + GetJob(ctx context.Context, id openapi_types.UUID, reqEditors ...RequestEditorFn) (*http.Response, error) + + // UpdateJobWithBody request with any body + UpdateJobWithBody(ctx context.Context, id openapi_types.UUID, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*http.Response, error) + + UpdateJob(ctx context.Context, id openapi_types.UUID, body UpdateJobJSONRequestBody, reqEditors ...RequestEditorFn) (*http.Response, error) // GetJobCollectorByJobId request - GetJobCollectorByJobId(ctx context.Context, id string, reqEditors ...RequestEditorFn) (*http.Response, error) + GetJobCollectorByJobId(ctx context.Context, id openapi_types.UUID, reqEditors ...RequestEditorFn) (*http.Response, error) // UpdateJobCollectorByJobIdWithBody request with any body - UpdateJobCollectorByJobIdWithBody(ctx context.Context, id string, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*http.Response, error) + UpdateJobCollectorByJobIdWithBody(ctx context.Context, id openapi_types.UUID, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*http.Response, error) - UpdateJobCollectorByJobId(ctx context.Context, id string, body UpdateJobCollectorByJobIdJSONRequestBody, reqEditors ...RequestEditorFn) (*http.Response, error) + UpdateJobCollectorByJobId(ctx context.Context, id openapi_types.UUID, body UpdateJobCollectorByJobIdJSONRequestBody, reqEditors ...RequestEditorFn) (*http.Response, error) // ListQueries request ListQueries(ctx context.Context, reqEditors ...RequestEditorFn) (*http.Response, error) @@ -368,17 +412,17 @@ type ClientInterface interface { CreateQuery(ctx context.Context, body CreateQueryJSONRequestBody, reqEditors ...RequestEditorFn) (*http.Response, error) // GetQuery request - GetQuery(ctx context.Context, id string, reqEditors ...RequestEditorFn) (*http.Response, error) + GetQuery(ctx context.Context, id openapi_types.UUID, reqEditors ...RequestEditorFn) (*http.Response, error) // UpdateQueryWithBody request with any body - UpdateQueryWithBody(ctx context.Context, id string, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*http.Response, error) + UpdateQueryWithBody(ctx context.Context, id openapi_types.UUID, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*http.Response, error) - UpdateQuery(ctx context.Context, id string, body UpdateQueryJSONRequestBody, reqEditors ...RequestEditorFn) (*http.Response, error) + UpdateQuery(ctx context.Context, id openapi_types.UUID, body UpdateQueryJSONRequestBody, reqEditors ...RequestEditorFn) (*http.Response, error) // TestQueryWithBody request with any body - TestQueryWithBody(ctx context.Context, id string, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*http.Response, error) + TestQueryWithBody(ctx context.Context, id openapi_types.UUID, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*http.Response, error) - TestQuery(ctx context.Context, id string, body TestQueryJSONRequestBody, reqEditors ...RequestEditorFn) (*http.Response, error) + TestQuery(ctx context.Context, id openapi_types.UUID, body TestQueryJSONRequestBody, reqEditors ...RequestEditorFn) (*http.Response, error) } func (c *Client) CreateClientWithBody(ctx context.Context, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*http.Response, error) { @@ -405,7 +449,7 @@ func (c *Client) CreateClient(ctx context.Context, body CreateClientJSONRequestB return c.Client.Do(req) } -func (c *Client) GetClient(ctx context.Context, id string, reqEditors ...RequestEditorFn) (*http.Response, error) { +func (c *Client) GetClient(ctx context.Context, id openapi_types.UUID, reqEditors ...RequestEditorFn) (*http.Response, error) { req, err := NewGetClientRequest(c.Server, id) if err != nil { return nil, err @@ -417,7 +461,7 @@ func (c *Client) GetClient(ctx context.Context, id string, reqEditors ...Request return c.Client.Do(req) } -func (c *Client) UpdateClientWithBody(ctx context.Context, id string, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*http.Response, error) { +func (c *Client) UpdateClientWithBody(ctx context.Context, id openapi_types.UUID, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*http.Response, error) { req, err := NewUpdateClientRequestWithBody(c.Server, id, contentType, body) if err != nil { return nil, err @@ -429,7 +473,7 @@ func (c *Client) UpdateClientWithBody(ctx context.Context, id string, contentTyp return c.Client.Do(req) } -func (c *Client) UpdateClient(ctx context.Context, id string, body UpdateClientJSONRequestBody, reqEditors ...RequestEditorFn) (*http.Response, error) { +func (c *Client) UpdateClient(ctx context.Context, id openapi_types.UUID, body UpdateClientJSONRequestBody, reqEditors ...RequestEditorFn) (*http.Response, error) { req, err := NewUpdateClientRequest(c.Server, id, body) if err != nil { return nil, err @@ -441,6 +485,30 @@ func (c *Client) UpdateClient(ctx context.Context, id string, body UpdateClientJ return c.Client.Do(req) } +func (c *Client) CreateJobWithBody(ctx context.Context, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*http.Response, error) { + req, err := NewCreateJobRequestWithBody(c.Server, contentType, body) + if err != nil { + return nil, err + } + req = req.WithContext(ctx) + if err := c.applyEditors(ctx, req, reqEditors); err != nil { + return nil, err + } + return c.Client.Do(req) +} + +func (c *Client) CreateJob(ctx context.Context, body CreateJobJSONRequestBody, reqEditors ...RequestEditorFn) (*http.Response, error) { + req, err := NewCreateJobRequest(c.Server, body) + if err != nil { + return nil, err + } + req = req.WithContext(ctx) + if err := c.applyEditors(ctx, req, reqEditors); err != nil { + return nil, err + } + return c.Client.Do(req) +} + func (c *Client) TriggerExportWithBody(ctx context.Context, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*http.Response, error) { req, err := NewTriggerExportRequestWithBody(c.Server, contentType, body) if err != nil { @@ -465,7 +533,7 @@ func (c *Client) TriggerExport(ctx context.Context, body TriggerExportJSONReques return c.Client.Do(req) } -func (c *Client) ExportState(ctx context.Context, id string, reqEditors ...RequestEditorFn) (*http.Response, error) { +func (c *Client) ExportState(ctx context.Context, id openapi_types.UUID, reqEditors ...RequestEditorFn) (*http.Response, error) { req, err := NewExportStateRequest(c.Server, id) if err != nil { return nil, err @@ -477,7 +545,43 @@ func (c *Client) ExportState(ctx context.Context, id string, reqEditors ...Reque return c.Client.Do(req) } -func (c *Client) GetJobCollectorByJobId(ctx context.Context, id string, reqEditors ...RequestEditorFn) (*http.Response, error) { +func (c *Client) GetJob(ctx context.Context, id openapi_types.UUID, reqEditors ...RequestEditorFn) (*http.Response, error) { + req, err := NewGetJobRequest(c.Server, id) + if err != nil { + return nil, err + } + req = req.WithContext(ctx) + if err := c.applyEditors(ctx, req, reqEditors); err != nil { + return nil, err + } + return c.Client.Do(req) +} + +func (c *Client) UpdateJobWithBody(ctx context.Context, id openapi_types.UUID, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*http.Response, error) { + req, err := NewUpdateJobRequestWithBody(c.Server, id, contentType, body) + if err != nil { + return nil, err + } + req = req.WithContext(ctx) + if err := c.applyEditors(ctx, req, reqEditors); err != nil { + return nil, err + } + return c.Client.Do(req) +} + +func (c *Client) UpdateJob(ctx context.Context, id openapi_types.UUID, body UpdateJobJSONRequestBody, reqEditors ...RequestEditorFn) (*http.Response, error) { + req, err := NewUpdateJobRequest(c.Server, id, body) + if err != nil { + return nil, err + } + req = req.WithContext(ctx) + if err := c.applyEditors(ctx, req, reqEditors); err != nil { + return nil, err + } + return c.Client.Do(req) +} + +func (c *Client) GetJobCollectorByJobId(ctx context.Context, id openapi_types.UUID, reqEditors ...RequestEditorFn) (*http.Response, error) { req, err := NewGetJobCollectorByJobIdRequest(c.Server, id) if err != nil { return nil, err @@ -489,7 +593,7 @@ func (c *Client) GetJobCollectorByJobId(ctx context.Context, id string, reqEdito return c.Client.Do(req) } -func (c *Client) UpdateJobCollectorByJobIdWithBody(ctx context.Context, id string, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*http.Response, error) { +func (c *Client) UpdateJobCollectorByJobIdWithBody(ctx context.Context, id openapi_types.UUID, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*http.Response, error) { req, err := NewUpdateJobCollectorByJobIdRequestWithBody(c.Server, id, contentType, body) if err != nil { return nil, err @@ -501,7 +605,7 @@ func (c *Client) UpdateJobCollectorByJobIdWithBody(ctx context.Context, id strin return c.Client.Do(req) } -func (c *Client) UpdateJobCollectorByJobId(ctx context.Context, id string, body UpdateJobCollectorByJobIdJSONRequestBody, reqEditors ...RequestEditorFn) (*http.Response, error) { +func (c *Client) UpdateJobCollectorByJobId(ctx context.Context, id openapi_types.UUID, body UpdateJobCollectorByJobIdJSONRequestBody, reqEditors ...RequestEditorFn) (*http.Response, error) { req, err := NewUpdateJobCollectorByJobIdRequest(c.Server, id, body) if err != nil { return nil, err @@ -549,7 +653,7 @@ func (c *Client) CreateQuery(ctx context.Context, body CreateQueryJSONRequestBod return c.Client.Do(req) } -func (c *Client) GetQuery(ctx context.Context, id string, reqEditors ...RequestEditorFn) (*http.Response, error) { +func (c *Client) GetQuery(ctx context.Context, id openapi_types.UUID, reqEditors ...RequestEditorFn) (*http.Response, error) { req, err := NewGetQueryRequest(c.Server, id) if err != nil { return nil, err @@ -561,7 +665,7 @@ func (c *Client) GetQuery(ctx context.Context, id string, reqEditors ...RequestE return c.Client.Do(req) } -func (c *Client) UpdateQueryWithBody(ctx context.Context, id string, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*http.Response, error) { +func (c *Client) UpdateQueryWithBody(ctx context.Context, id openapi_types.UUID, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*http.Response, error) { req, err := NewUpdateQueryRequestWithBody(c.Server, id, contentType, body) if err != nil { return nil, err @@ -573,7 +677,7 @@ func (c *Client) UpdateQueryWithBody(ctx context.Context, id string, contentType return c.Client.Do(req) } -func (c *Client) UpdateQuery(ctx context.Context, id string, body UpdateQueryJSONRequestBody, reqEditors ...RequestEditorFn) (*http.Response, error) { +func (c *Client) UpdateQuery(ctx context.Context, id openapi_types.UUID, body UpdateQueryJSONRequestBody, reqEditors ...RequestEditorFn) (*http.Response, error) { req, err := NewUpdateQueryRequest(c.Server, id, body) if err != nil { return nil, err @@ -585,7 +689,7 @@ func (c *Client) UpdateQuery(ctx context.Context, id string, body UpdateQueryJSO return c.Client.Do(req) } -func (c *Client) TestQueryWithBody(ctx context.Context, id string, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*http.Response, error) { +func (c *Client) TestQueryWithBody(ctx context.Context, id openapi_types.UUID, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*http.Response, error) { req, err := NewTestQueryRequestWithBody(c.Server, id, contentType, body) if err != nil { return nil, err @@ -597,7 +701,7 @@ func (c *Client) TestQueryWithBody(ctx context.Context, id string, contentType s return c.Client.Do(req) } -func (c *Client) TestQuery(ctx context.Context, id string, body TestQueryJSONRequestBody, reqEditors ...RequestEditorFn) (*http.Response, error) { +func (c *Client) TestQuery(ctx context.Context, id openapi_types.UUID, body TestQueryJSONRequestBody, reqEditors ...RequestEditorFn) (*http.Response, error) { req, err := NewTestQueryRequest(c.Server, id, body) if err != nil { return nil, err @@ -629,7 +733,7 @@ func NewCreateClientRequestWithBody(server string, contentType string, body io.R return nil, err } - operationPath := fmt.Sprintf("/clients") + operationPath := fmt.Sprintf("/client") if operationPath[0] == '/' { operationPath = "." + operationPath } @@ -650,7 +754,7 @@ func NewCreateClientRequestWithBody(server string, contentType string, body io.R } // NewGetClientRequest generates requests for GetClient -func NewGetClientRequest(server string, id string) (*http.Request, error) { +func NewGetClientRequest(server string, id openapi_types.UUID) (*http.Request, error) { var err error var pathParam0 string @@ -665,7 +769,7 @@ func NewGetClientRequest(server string, id string) (*http.Request, error) { return nil, err } - operationPath := fmt.Sprintf("/clients/%s", pathParam0) + operationPath := fmt.Sprintf("/client/%s", pathParam0) if operationPath[0] == '/' { operationPath = "." + operationPath } @@ -684,7 +788,7 @@ func NewGetClientRequest(server string, id string) (*http.Request, error) { } // NewUpdateClientRequest calls the generic UpdateClient builder with application/json body -func NewUpdateClientRequest(server string, id string, body UpdateClientJSONRequestBody) (*http.Request, error) { +func NewUpdateClientRequest(server string, id openapi_types.UUID, body UpdateClientJSONRequestBody) (*http.Request, error) { var bodyReader io.Reader buf, err := json.Marshal(body) if err != nil { @@ -695,7 +799,7 @@ func NewUpdateClientRequest(server string, id string, body UpdateClientJSONReque } // NewUpdateClientRequestWithBody generates requests for UpdateClient with any type of body -func NewUpdateClientRequestWithBody(server string, id string, contentType string, body io.Reader) (*http.Request, error) { +func NewUpdateClientRequestWithBody(server string, id openapi_types.UUID, contentType string, body io.Reader) (*http.Request, error) { var err error var pathParam0 string @@ -710,7 +814,7 @@ func NewUpdateClientRequestWithBody(server string, id string, contentType string return nil, err } - operationPath := fmt.Sprintf("/clients/%s", pathParam0) + operationPath := fmt.Sprintf("/client/%s", pathParam0) if operationPath[0] == '/' { operationPath = "." + operationPath } @@ -730,6 +834,46 @@ func NewUpdateClientRequestWithBody(server string, id string, contentType string return req, nil } +// NewCreateJobRequest calls the generic CreateJob builder with application/json body +func NewCreateJobRequest(server string, body CreateJobJSONRequestBody) (*http.Request, error) { + var bodyReader io.Reader + buf, err := json.Marshal(body) + if err != nil { + return nil, err + } + bodyReader = bytes.NewReader(buf) + return NewCreateJobRequestWithBody(server, "application/json", bodyReader) +} + +// NewCreateJobRequestWithBody generates requests for CreateJob with any type of body +func NewCreateJobRequestWithBody(server string, contentType string, body io.Reader) (*http.Request, error) { + var err error + + serverURL, err := url.Parse(server) + if err != nil { + return nil, err + } + + operationPath := fmt.Sprintf("/job") + if operationPath[0] == '/' { + operationPath = "." + operationPath + } + + queryURL, err := serverURL.Parse(operationPath) + if err != nil { + return nil, err + } + + req, err := http.NewRequest("POST", queryURL.String(), body) + if err != nil { + return nil, err + } + + req.Header.Add("Content-Type", contentType) + + return req, nil +} + // NewTriggerExportRequest calls the generic TriggerExport builder with application/json body func NewTriggerExportRequest(server string, body TriggerExportJSONRequestBody) (*http.Request, error) { var bodyReader io.Reader @@ -771,7 +915,7 @@ func NewTriggerExportRequestWithBody(server string, contentType string, body io. } // NewExportStateRequest generates requests for ExportState -func NewExportStateRequest(server string, id string) (*http.Request, error) { +func NewExportStateRequest(server string, id openapi_types.UUID) (*http.Request, error) { var err error var pathParam0 string @@ -804,8 +948,89 @@ func NewExportStateRequest(server string, id string) (*http.Request, error) { return req, nil } +// NewGetJobRequest generates requests for GetJob +func NewGetJobRequest(server string, id openapi_types.UUID) (*http.Request, error) { + var err error + + var pathParam0 string + + pathParam0, err = runtime.StyleParamWithLocation("simple", false, "id", runtime.ParamLocationPath, id) + if err != nil { + return nil, err + } + + serverURL, err := url.Parse(server) + if err != nil { + return nil, err + } + + operationPath := fmt.Sprintf("/job/%s", pathParam0) + if operationPath[0] == '/' { + operationPath = "." + operationPath + } + + queryURL, err := serverURL.Parse(operationPath) + if err != nil { + return nil, err + } + + req, err := http.NewRequest("GET", queryURL.String(), nil) + if err != nil { + return nil, err + } + + return req, nil +} + +// NewUpdateJobRequest calls the generic UpdateJob builder with application/json body +func NewUpdateJobRequest(server string, id openapi_types.UUID, body UpdateJobJSONRequestBody) (*http.Request, error) { + var bodyReader io.Reader + buf, err := json.Marshal(body) + if err != nil { + return nil, err + } + bodyReader = bytes.NewReader(buf) + return NewUpdateJobRequestWithBody(server, id, "application/json", bodyReader) +} + +// NewUpdateJobRequestWithBody generates requests for UpdateJob with any type of body +func NewUpdateJobRequestWithBody(server string, id openapi_types.UUID, contentType string, body io.Reader) (*http.Request, error) { + var err error + + var pathParam0 string + + pathParam0, err = runtime.StyleParamWithLocation("simple", false, "id", runtime.ParamLocationPath, id) + if err != nil { + return nil, err + } + + serverURL, err := url.Parse(server) + if err != nil { + return nil, err + } + + operationPath := fmt.Sprintf("/job/%s", pathParam0) + if operationPath[0] == '/' { + operationPath = "." + operationPath + } + + queryURL, err := serverURL.Parse(operationPath) + if err != nil { + return nil, err + } + + req, err := http.NewRequest("PATCH", queryURL.String(), body) + if err != nil { + return nil, err + } + + req.Header.Add("Content-Type", contentType) + + return req, nil +} + // NewGetJobCollectorByJobIdRequest generates requests for GetJobCollectorByJobId -func NewGetJobCollectorByJobIdRequest(server string, id string) (*http.Request, error) { +func NewGetJobCollectorByJobIdRequest(server string, id openapi_types.UUID) (*http.Request, error) { var err error var pathParam0 string @@ -839,7 +1064,7 @@ func NewGetJobCollectorByJobIdRequest(server string, id string) (*http.Request, } // NewUpdateJobCollectorByJobIdRequest calls the generic UpdateJobCollectorByJobId builder with application/json body -func NewUpdateJobCollectorByJobIdRequest(server string, id string, body UpdateJobCollectorByJobIdJSONRequestBody) (*http.Request, error) { +func NewUpdateJobCollectorByJobIdRequest(server string, id openapi_types.UUID, body UpdateJobCollectorByJobIdJSONRequestBody) (*http.Request, error) { var bodyReader io.Reader buf, err := json.Marshal(body) if err != nil { @@ -850,7 +1075,7 @@ func NewUpdateJobCollectorByJobIdRequest(server string, id string, body UpdateJo } // NewUpdateJobCollectorByJobIdRequestWithBody generates requests for UpdateJobCollectorByJobId with any type of body -func NewUpdateJobCollectorByJobIdRequestWithBody(server string, id string, contentType string, body io.Reader) (*http.Request, error) { +func NewUpdateJobCollectorByJobIdRequestWithBody(server string, id openapi_types.UUID, contentType string, body io.Reader) (*http.Request, error) { var err error var pathParam0 string @@ -894,7 +1119,7 @@ func NewListQueriesRequest(server string) (*http.Request, error) { return nil, err } - operationPath := fmt.Sprintf("/queries") + operationPath := fmt.Sprintf("/query") if operationPath[0] == '/' { operationPath = "." + operationPath } @@ -932,7 +1157,7 @@ func NewCreateQueryRequestWithBody(server string, contentType string, body io.Re return nil, err } - operationPath := fmt.Sprintf("/queries") + operationPath := fmt.Sprintf("/query") if operationPath[0] == '/' { operationPath = "." + operationPath } @@ -953,7 +1178,7 @@ func NewCreateQueryRequestWithBody(server string, contentType string, body io.Re } // NewGetQueryRequest generates requests for GetQuery -func NewGetQueryRequest(server string, id string) (*http.Request, error) { +func NewGetQueryRequest(server string, id openapi_types.UUID) (*http.Request, error) { var err error var pathParam0 string @@ -968,7 +1193,7 @@ func NewGetQueryRequest(server string, id string) (*http.Request, error) { return nil, err } - operationPath := fmt.Sprintf("/queries/%s", pathParam0) + operationPath := fmt.Sprintf("/query/%s", pathParam0) if operationPath[0] == '/' { operationPath = "." + operationPath } @@ -987,7 +1212,7 @@ func NewGetQueryRequest(server string, id string) (*http.Request, error) { } // NewUpdateQueryRequest calls the generic UpdateQuery builder with application/json body -func NewUpdateQueryRequest(server string, id string, body UpdateQueryJSONRequestBody) (*http.Request, error) { +func NewUpdateQueryRequest(server string, id openapi_types.UUID, body UpdateQueryJSONRequestBody) (*http.Request, error) { var bodyReader io.Reader buf, err := json.Marshal(body) if err != nil { @@ -998,7 +1223,7 @@ func NewUpdateQueryRequest(server string, id string, body UpdateQueryJSONRequest } // NewUpdateQueryRequestWithBody generates requests for UpdateQuery with any type of body -func NewUpdateQueryRequestWithBody(server string, id string, contentType string, body io.Reader) (*http.Request, error) { +func NewUpdateQueryRequestWithBody(server string, id openapi_types.UUID, contentType string, body io.Reader) (*http.Request, error) { var err error var pathParam0 string @@ -1013,7 +1238,7 @@ func NewUpdateQueryRequestWithBody(server string, id string, contentType string, return nil, err } - operationPath := fmt.Sprintf("/queries/%s", pathParam0) + operationPath := fmt.Sprintf("/query/%s", pathParam0) if operationPath[0] == '/' { operationPath = "." + operationPath } @@ -1034,7 +1259,7 @@ func NewUpdateQueryRequestWithBody(server string, id string, contentType string, } // NewTestQueryRequest calls the generic TestQuery builder with application/json body -func NewTestQueryRequest(server string, id string, body TestQueryJSONRequestBody) (*http.Request, error) { +func NewTestQueryRequest(server string, id openapi_types.UUID, body TestQueryJSONRequestBody) (*http.Request, error) { var bodyReader io.Reader buf, err := json.Marshal(body) if err != nil { @@ -1045,7 +1270,7 @@ func NewTestQueryRequest(server string, id string, body TestQueryJSONRequestBody } // NewTestQueryRequestWithBody generates requests for TestQuery with any type of body -func NewTestQueryRequestWithBody(server string, id string, contentType string, body io.Reader) (*http.Request, error) { +func NewTestQueryRequestWithBody(server string, id openapi_types.UUID, contentType string, body io.Reader) (*http.Request, error) { var err error var pathParam0 string @@ -1060,7 +1285,7 @@ func NewTestQueryRequestWithBody(server string, id string, contentType string, b return nil, err } - operationPath := fmt.Sprintf("/queries/%s/test", pathParam0) + operationPath := fmt.Sprintf("/query/%s/test", pathParam0) if operationPath[0] == '/' { operationPath = "." + operationPath } @@ -1129,12 +1354,17 @@ type ClientWithResponsesInterface interface { CreateClientWithResponse(ctx context.Context, body CreateClientJSONRequestBody, reqEditors ...RequestEditorFn) (*CreateClientResponse, error) // GetClientWithResponse request - GetClientWithResponse(ctx context.Context, id string, reqEditors ...RequestEditorFn) (*GetClientResponse, error) + GetClientWithResponse(ctx context.Context, id openapi_types.UUID, reqEditors ...RequestEditorFn) (*GetClientResponse, error) // UpdateClientWithBodyWithResponse request with any body - UpdateClientWithBodyWithResponse(ctx context.Context, id string, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*UpdateClientResponse, error) + UpdateClientWithBodyWithResponse(ctx context.Context, id openapi_types.UUID, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*UpdateClientResponse, error) - UpdateClientWithResponse(ctx context.Context, id string, body UpdateClientJSONRequestBody, reqEditors ...RequestEditorFn) (*UpdateClientResponse, error) + UpdateClientWithResponse(ctx context.Context, id openapi_types.UUID, body UpdateClientJSONRequestBody, reqEditors ...RequestEditorFn) (*UpdateClientResponse, error) + + // CreateJobWithBodyWithResponse request with any body + CreateJobWithBodyWithResponse(ctx context.Context, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*CreateJobResponse, error) + + CreateJobWithResponse(ctx context.Context, body CreateJobJSONRequestBody, reqEditors ...RequestEditorFn) (*CreateJobResponse, error) // TriggerExportWithBodyWithResponse request with any body TriggerExportWithBodyWithResponse(ctx context.Context, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*TriggerExportResponse, error) @@ -1142,15 +1372,23 @@ type ClientWithResponsesInterface interface { TriggerExportWithResponse(ctx context.Context, body TriggerExportJSONRequestBody, reqEditors ...RequestEditorFn) (*TriggerExportResponse, error) // ExportStateWithResponse request - ExportStateWithResponse(ctx context.Context, id string, reqEditors ...RequestEditorFn) (*ExportStateResponse, error) + ExportStateWithResponse(ctx context.Context, id openapi_types.UUID, reqEditors ...RequestEditorFn) (*ExportStateResponse, error) + + // GetJobWithResponse request + GetJobWithResponse(ctx context.Context, id openapi_types.UUID, reqEditors ...RequestEditorFn) (*GetJobResponse, error) + + // UpdateJobWithBodyWithResponse request with any body + UpdateJobWithBodyWithResponse(ctx context.Context, id openapi_types.UUID, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*UpdateJobResponse, error) + + UpdateJobWithResponse(ctx context.Context, id openapi_types.UUID, body UpdateJobJSONRequestBody, reqEditors ...RequestEditorFn) (*UpdateJobResponse, error) // GetJobCollectorByJobIdWithResponse request - GetJobCollectorByJobIdWithResponse(ctx context.Context, id string, reqEditors ...RequestEditorFn) (*GetJobCollectorByJobIdResponse, error) + GetJobCollectorByJobIdWithResponse(ctx context.Context, id openapi_types.UUID, reqEditors ...RequestEditorFn) (*GetJobCollectorByJobIdResponse, error) // UpdateJobCollectorByJobIdWithBodyWithResponse request with any body - UpdateJobCollectorByJobIdWithBodyWithResponse(ctx context.Context, id string, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*UpdateJobCollectorByJobIdResponse, error) + UpdateJobCollectorByJobIdWithBodyWithResponse(ctx context.Context, id openapi_types.UUID, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*UpdateJobCollectorByJobIdResponse, error) - UpdateJobCollectorByJobIdWithResponse(ctx context.Context, id string, body UpdateJobCollectorByJobIdJSONRequestBody, reqEditors ...RequestEditorFn) (*UpdateJobCollectorByJobIdResponse, error) + UpdateJobCollectorByJobIdWithResponse(ctx context.Context, id openapi_types.UUID, body UpdateJobCollectorByJobIdJSONRequestBody, reqEditors ...RequestEditorFn) (*UpdateJobCollectorByJobIdResponse, error) // ListQueriesWithResponse request ListQueriesWithResponse(ctx context.Context, reqEditors ...RequestEditorFn) (*ListQueriesResponse, error) @@ -1161,17 +1399,17 @@ type ClientWithResponsesInterface interface { CreateQueryWithResponse(ctx context.Context, body CreateQueryJSONRequestBody, reqEditors ...RequestEditorFn) (*CreateQueryResponse, error) // GetQueryWithResponse request - GetQueryWithResponse(ctx context.Context, id string, reqEditors ...RequestEditorFn) (*GetQueryResponse, error) + GetQueryWithResponse(ctx context.Context, id openapi_types.UUID, reqEditors ...RequestEditorFn) (*GetQueryResponse, error) // UpdateQueryWithBodyWithResponse request with any body - UpdateQueryWithBodyWithResponse(ctx context.Context, id string, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*UpdateQueryResponse, error) + UpdateQueryWithBodyWithResponse(ctx context.Context, id openapi_types.UUID, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*UpdateQueryResponse, error) - UpdateQueryWithResponse(ctx context.Context, id string, body UpdateQueryJSONRequestBody, reqEditors ...RequestEditorFn) (*UpdateQueryResponse, error) + UpdateQueryWithResponse(ctx context.Context, id openapi_types.UUID, body UpdateQueryJSONRequestBody, reqEditors ...RequestEditorFn) (*UpdateQueryResponse, error) // TestQueryWithBodyWithResponse request with any body - TestQueryWithBodyWithResponse(ctx context.Context, id string, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*TestQueryResponse, error) + TestQueryWithBodyWithResponse(ctx context.Context, id openapi_types.UUID, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*TestQueryResponse, error) - TestQueryWithResponse(ctx context.Context, id string, body TestQueryJSONRequestBody, reqEditors ...RequestEditorFn) (*TestQueryResponse, error) + TestQueryWithResponse(ctx context.Context, id openapi_types.UUID, body TestQueryJSONRequestBody, reqEditors ...RequestEditorFn) (*TestQueryResponse, error) } type CreateClientResponse struct { @@ -1239,6 +1477,28 @@ func (r UpdateClientResponse) StatusCode() int { return 0 } +type CreateJobResponse struct { + Body []byte + HTTPResponse *http.Response + JSON201 *IdMessage +} + +// Status returns HTTPResponse.Status +func (r CreateJobResponse) Status() string { + if r.HTTPResponse != nil { + return r.HTTPResponse.Status + } + return http.StatusText(0) +} + +// StatusCode returns HTTPResponse.StatusCode +func (r CreateJobResponse) StatusCode() int { + if r.HTTPResponse != nil { + return r.HTTPResponse.StatusCode + } + return 0 +} + type TriggerExportResponse struct { Body []byte HTTPResponse *http.Response @@ -1283,6 +1543,49 @@ func (r ExportStateResponse) StatusCode() int { return 0 } +type GetJobResponse struct { + Body []byte + HTTPResponse *http.Response + JSON200 *Job +} + +// Status returns HTTPResponse.Status +func (r GetJobResponse) Status() string { + if r.HTTPResponse != nil { + return r.HTTPResponse.Status + } + return http.StatusText(0) +} + +// StatusCode returns HTTPResponse.StatusCode +func (r GetJobResponse) StatusCode() int { + if r.HTTPResponse != nil { + return r.HTTPResponse.StatusCode + } + return 0 +} + +type UpdateJobResponse struct { + Body []byte + HTTPResponse *http.Response +} + +// Status returns HTTPResponse.Status +func (r UpdateJobResponse) Status() string { + if r.HTTPResponse != nil { + return r.HTTPResponse.Status + } + return http.StatusText(0) +} + +// StatusCode returns HTTPResponse.StatusCode +func (r UpdateJobResponse) StatusCode() int { + if r.HTTPResponse != nil { + return r.HTTPResponse.StatusCode + } + return 0 +} + type GetJobCollectorByJobIdResponse struct { Body []byte HTTPResponse *http.Response @@ -1453,7 +1756,7 @@ func (c *ClientWithResponses) CreateClientWithResponse(ctx context.Context, body } // GetClientWithResponse request returning *GetClientResponse -func (c *ClientWithResponses) GetClientWithResponse(ctx context.Context, id string, reqEditors ...RequestEditorFn) (*GetClientResponse, error) { +func (c *ClientWithResponses) GetClientWithResponse(ctx context.Context, id openapi_types.UUID, reqEditors ...RequestEditorFn) (*GetClientResponse, error) { rsp, err := c.GetClient(ctx, id, reqEditors...) if err != nil { return nil, err @@ -1462,7 +1765,7 @@ func (c *ClientWithResponses) GetClientWithResponse(ctx context.Context, id stri } // UpdateClientWithBodyWithResponse request with arbitrary body returning *UpdateClientResponse -func (c *ClientWithResponses) UpdateClientWithBodyWithResponse(ctx context.Context, id string, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*UpdateClientResponse, error) { +func (c *ClientWithResponses) UpdateClientWithBodyWithResponse(ctx context.Context, id openapi_types.UUID, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*UpdateClientResponse, error) { rsp, err := c.UpdateClientWithBody(ctx, id, contentType, body, reqEditors...) if err != nil { return nil, err @@ -1470,7 +1773,7 @@ func (c *ClientWithResponses) UpdateClientWithBodyWithResponse(ctx context.Conte return ParseUpdateClientResponse(rsp) } -func (c *ClientWithResponses) UpdateClientWithResponse(ctx context.Context, id string, body UpdateClientJSONRequestBody, reqEditors ...RequestEditorFn) (*UpdateClientResponse, error) { +func (c *ClientWithResponses) UpdateClientWithResponse(ctx context.Context, id openapi_types.UUID, body UpdateClientJSONRequestBody, reqEditors ...RequestEditorFn) (*UpdateClientResponse, error) { rsp, err := c.UpdateClient(ctx, id, body, reqEditors...) if err != nil { return nil, err @@ -1478,6 +1781,23 @@ func (c *ClientWithResponses) UpdateClientWithResponse(ctx context.Context, id s return ParseUpdateClientResponse(rsp) } +// CreateJobWithBodyWithResponse request with arbitrary body returning *CreateJobResponse +func (c *ClientWithResponses) CreateJobWithBodyWithResponse(ctx context.Context, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*CreateJobResponse, error) { + rsp, err := c.CreateJobWithBody(ctx, contentType, body, reqEditors...) + if err != nil { + return nil, err + } + return ParseCreateJobResponse(rsp) +} + +func (c *ClientWithResponses) CreateJobWithResponse(ctx context.Context, body CreateJobJSONRequestBody, reqEditors ...RequestEditorFn) (*CreateJobResponse, error) { + rsp, err := c.CreateJob(ctx, body, reqEditors...) + if err != nil { + return nil, err + } + return ParseCreateJobResponse(rsp) +} + // TriggerExportWithBodyWithResponse request with arbitrary body returning *TriggerExportResponse func (c *ClientWithResponses) TriggerExportWithBodyWithResponse(ctx context.Context, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*TriggerExportResponse, error) { rsp, err := c.TriggerExportWithBody(ctx, contentType, body, reqEditors...) @@ -1496,7 +1816,7 @@ func (c *ClientWithResponses) TriggerExportWithResponse(ctx context.Context, bod } // ExportStateWithResponse request returning *ExportStateResponse -func (c *ClientWithResponses) ExportStateWithResponse(ctx context.Context, id string, reqEditors ...RequestEditorFn) (*ExportStateResponse, error) { +func (c *ClientWithResponses) ExportStateWithResponse(ctx context.Context, id openapi_types.UUID, reqEditors ...RequestEditorFn) (*ExportStateResponse, error) { rsp, err := c.ExportState(ctx, id, reqEditors...) if err != nil { return nil, err @@ -1504,8 +1824,34 @@ func (c *ClientWithResponses) ExportStateWithResponse(ctx context.Context, id st return ParseExportStateResponse(rsp) } +// GetJobWithResponse request returning *GetJobResponse +func (c *ClientWithResponses) GetJobWithResponse(ctx context.Context, id openapi_types.UUID, reqEditors ...RequestEditorFn) (*GetJobResponse, error) { + rsp, err := c.GetJob(ctx, id, reqEditors...) + if err != nil { + return nil, err + } + return ParseGetJobResponse(rsp) +} + +// UpdateJobWithBodyWithResponse request with arbitrary body returning *UpdateJobResponse +func (c *ClientWithResponses) UpdateJobWithBodyWithResponse(ctx context.Context, id openapi_types.UUID, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*UpdateJobResponse, error) { + rsp, err := c.UpdateJobWithBody(ctx, id, contentType, body, reqEditors...) + if err != nil { + return nil, err + } + return ParseUpdateJobResponse(rsp) +} + +func (c *ClientWithResponses) UpdateJobWithResponse(ctx context.Context, id openapi_types.UUID, body UpdateJobJSONRequestBody, reqEditors ...RequestEditorFn) (*UpdateJobResponse, error) { + rsp, err := c.UpdateJob(ctx, id, body, reqEditors...) + if err != nil { + return nil, err + } + return ParseUpdateJobResponse(rsp) +} + // GetJobCollectorByJobIdWithResponse request returning *GetJobCollectorByJobIdResponse -func (c *ClientWithResponses) GetJobCollectorByJobIdWithResponse(ctx context.Context, id string, reqEditors ...RequestEditorFn) (*GetJobCollectorByJobIdResponse, error) { +func (c *ClientWithResponses) GetJobCollectorByJobIdWithResponse(ctx context.Context, id openapi_types.UUID, reqEditors ...RequestEditorFn) (*GetJobCollectorByJobIdResponse, error) { rsp, err := c.GetJobCollectorByJobId(ctx, id, reqEditors...) if err != nil { return nil, err @@ -1514,7 +1860,7 @@ func (c *ClientWithResponses) GetJobCollectorByJobIdWithResponse(ctx context.Con } // UpdateJobCollectorByJobIdWithBodyWithResponse request with arbitrary body returning *UpdateJobCollectorByJobIdResponse -func (c *ClientWithResponses) UpdateJobCollectorByJobIdWithBodyWithResponse(ctx context.Context, id string, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*UpdateJobCollectorByJobIdResponse, error) { +func (c *ClientWithResponses) UpdateJobCollectorByJobIdWithBodyWithResponse(ctx context.Context, id openapi_types.UUID, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*UpdateJobCollectorByJobIdResponse, error) { rsp, err := c.UpdateJobCollectorByJobIdWithBody(ctx, id, contentType, body, reqEditors...) if err != nil { return nil, err @@ -1522,7 +1868,7 @@ func (c *ClientWithResponses) UpdateJobCollectorByJobIdWithBodyWithResponse(ctx return ParseUpdateJobCollectorByJobIdResponse(rsp) } -func (c *ClientWithResponses) UpdateJobCollectorByJobIdWithResponse(ctx context.Context, id string, body UpdateJobCollectorByJobIdJSONRequestBody, reqEditors ...RequestEditorFn) (*UpdateJobCollectorByJobIdResponse, error) { +func (c *ClientWithResponses) UpdateJobCollectorByJobIdWithResponse(ctx context.Context, id openapi_types.UUID, body UpdateJobCollectorByJobIdJSONRequestBody, reqEditors ...RequestEditorFn) (*UpdateJobCollectorByJobIdResponse, error) { rsp, err := c.UpdateJobCollectorByJobId(ctx, id, body, reqEditors...) if err != nil { return nil, err @@ -1557,7 +1903,7 @@ func (c *ClientWithResponses) CreateQueryWithResponse(ctx context.Context, body } // GetQueryWithResponse request returning *GetQueryResponse -func (c *ClientWithResponses) GetQueryWithResponse(ctx context.Context, id string, reqEditors ...RequestEditorFn) (*GetQueryResponse, error) { +func (c *ClientWithResponses) GetQueryWithResponse(ctx context.Context, id openapi_types.UUID, reqEditors ...RequestEditorFn) (*GetQueryResponse, error) { rsp, err := c.GetQuery(ctx, id, reqEditors...) if err != nil { return nil, err @@ -1566,7 +1912,7 @@ func (c *ClientWithResponses) GetQueryWithResponse(ctx context.Context, id strin } // UpdateQueryWithBodyWithResponse request with arbitrary body returning *UpdateQueryResponse -func (c *ClientWithResponses) UpdateQueryWithBodyWithResponse(ctx context.Context, id string, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*UpdateQueryResponse, error) { +func (c *ClientWithResponses) UpdateQueryWithBodyWithResponse(ctx context.Context, id openapi_types.UUID, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*UpdateQueryResponse, error) { rsp, err := c.UpdateQueryWithBody(ctx, id, contentType, body, reqEditors...) if err != nil { return nil, err @@ -1574,7 +1920,7 @@ func (c *ClientWithResponses) UpdateQueryWithBodyWithResponse(ctx context.Contex return ParseUpdateQueryResponse(rsp) } -func (c *ClientWithResponses) UpdateQueryWithResponse(ctx context.Context, id string, body UpdateQueryJSONRequestBody, reqEditors ...RequestEditorFn) (*UpdateQueryResponse, error) { +func (c *ClientWithResponses) UpdateQueryWithResponse(ctx context.Context, id openapi_types.UUID, body UpdateQueryJSONRequestBody, reqEditors ...RequestEditorFn) (*UpdateQueryResponse, error) { rsp, err := c.UpdateQuery(ctx, id, body, reqEditors...) if err != nil { return nil, err @@ -1583,7 +1929,7 @@ func (c *ClientWithResponses) UpdateQueryWithResponse(ctx context.Context, id st } // TestQueryWithBodyWithResponse request with arbitrary body returning *TestQueryResponse -func (c *ClientWithResponses) TestQueryWithBodyWithResponse(ctx context.Context, id string, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*TestQueryResponse, error) { +func (c *ClientWithResponses) TestQueryWithBodyWithResponse(ctx context.Context, id openapi_types.UUID, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*TestQueryResponse, error) { rsp, err := c.TestQueryWithBody(ctx, id, contentType, body, reqEditors...) if err != nil { return nil, err @@ -1591,7 +1937,7 @@ func (c *ClientWithResponses) TestQueryWithBodyWithResponse(ctx context.Context, return ParseTestQueryResponse(rsp) } -func (c *ClientWithResponses) TestQueryWithResponse(ctx context.Context, id string, body TestQueryJSONRequestBody, reqEditors ...RequestEditorFn) (*TestQueryResponse, error) { +func (c *ClientWithResponses) TestQueryWithResponse(ctx context.Context, id openapi_types.UUID, body TestQueryJSONRequestBody, reqEditors ...RequestEditorFn) (*TestQueryResponse, error) { rsp, err := c.TestQuery(ctx, id, body, reqEditors...) if err != nil { return nil, err @@ -1667,6 +2013,32 @@ func ParseUpdateClientResponse(rsp *http.Response) (*UpdateClientResponse, error return response, nil } +// ParseCreateJobResponse parses an HTTP response from a CreateJobWithResponse call +func ParseCreateJobResponse(rsp *http.Response) (*CreateJobResponse, error) { + bodyBytes, err := io.ReadAll(rsp.Body) + defer func() { _ = rsp.Body.Close() }() + if err != nil { + return nil, err + } + + response := &CreateJobResponse{ + Body: bodyBytes, + HTTPResponse: rsp, + } + + switch { + case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 201: + var dest IdMessage + if err := json.Unmarshal(bodyBytes, &dest); err != nil { + return nil, err + } + response.JSON201 = &dest + + } + + return response, nil +} + // ParseTriggerExportResponse parses an HTTP response from a TriggerExportWithResponse call func ParseTriggerExportResponse(rsp *http.Response) (*TriggerExportResponse, error) { bodyBytes, err := io.ReadAll(rsp.Body) @@ -1719,6 +2091,48 @@ func ParseExportStateResponse(rsp *http.Response) (*ExportStateResponse, error) return response, nil } +// ParseGetJobResponse parses an HTTP response from a GetJobWithResponse call +func ParseGetJobResponse(rsp *http.Response) (*GetJobResponse, error) { + bodyBytes, err := io.ReadAll(rsp.Body) + defer func() { _ = rsp.Body.Close() }() + if err != nil { + return nil, err + } + + response := &GetJobResponse{ + Body: bodyBytes, + HTTPResponse: rsp, + } + + switch { + case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 200: + var dest Job + if err := json.Unmarshal(bodyBytes, &dest); err != nil { + return nil, err + } + response.JSON200 = &dest + + } + + return response, nil +} + +// ParseUpdateJobResponse parses an HTTP response from a UpdateJobWithResponse call +func ParseUpdateJobResponse(rsp *http.Response) (*UpdateJobResponse, error) { + bodyBytes, err := io.ReadAll(rsp.Body) + defer func() { _ = rsp.Body.Close() }() + if err != nil { + return nil, err + } + + response := &UpdateJobResponse{ + Body: bodyBytes, + HTTPResponse: rsp, + } + + return response, nil +} + // ParseGetJobCollectorByJobIdResponse parses an HTTP response from a GetJobCollectorByJobIdWithResponse call func ParseGetJobCollectorByJobIdResponse(rsp *http.Response) (*GetJobCollectorByJobIdResponse, error) { bodyBytes, err := io.ReadAll(rsp.Body) diff --git a/scripts/Taskfile.yml b/scripts/Taskfile.yml index e60718f5..7d3631c9 100644 --- a/scripts/Taskfile.yml +++ b/scripts/Taskfile.yml @@ -37,7 +37,7 @@ tasks: - task build - task lint - task test:unit - - task test:integration + - task test:integration:nocache build: deps: - generate diff --git a/scripts/tests.yml b/scripts/tests.yml index a329ff7c..8c1b21ac 100644 --- a/scripts/tests.yml +++ b/scripts/tests.yml @@ -52,6 +52,9 @@ tasks: cmds: - task generate - task docker:build + - task test:integration:nocache + integration:nocache: + cmds: - go test -count=1 -v ./test/... integration:nobuild: cmds: diff --git a/serviceAPIs/queryService.yaml b/serviceAPIs/queryService.yaml index 74351adb..c891af71 100644 --- a/serviceAPIs/queryService.yaml +++ b/serviceAPIs/queryService.yaml @@ -10,6 +10,8 @@ servers: tags: - name: ClientService description: Operations related to clients + - name: JobService + description: Operations related to jobs - name: JobCollectorService description: Operations related to job collectors - name: QueryService @@ -18,7 +20,7 @@ tags: description: Operations related to exports paths: - /clients: + /client: post: operationId: createClient tags: @@ -41,20 +43,21 @@ paths: '400': description: Invalid request body. - /clients/{id}: + /client/{id}: + parameters: + - in: path + name: id + required: true + schema: + type: string + format: uuid + description: The ID of the client to retrieve. get: operationId: getClient tags: - ClientService summary: Get a client by ID description: Retrieves a specific client by its ID. - parameters: - - in: path - name: id - required: true - schema: - type: string - description: The ID of the client to retrieve. responses: '200': description: Client details. @@ -72,13 +75,6 @@ paths: - ClientService summary: Update a client description: Updates an existing client with new details. - parameters: - - in: path - name: id - required: true - schema: - type: string - description: The ID of the client to update. requestBody: required: true content: @@ -93,7 +89,7 @@ paths: '404': description: Client not found - /queries: + /query: get: operationId: listQueries tags: @@ -133,20 +129,21 @@ paths: '400': description: Invalid request body. - /queries/{id}: + /query/{id}: + parameters: + - in: path + name: id + required: true + schema: + type: string + format: uuid + description: The ID of the query. get: operationId: getQuery tags: - QueryService summary: Get a query by ID description: Retrieves a specific query by its ID. - parameters: - - in: path - name: id - required: true - schema: - type: string - description: The ID of the query to retrieve. responses: '200': description: Query details. @@ -164,13 +161,6 @@ paths: - QueryService summary: Update a query description: Updates an existing query with new details. - parameters: - - in: path - name: id - required: true - schema: - type: string - description: The ID of the query to update. requestBody: required: true content: @@ -185,20 +175,21 @@ paths: '404': description: Query not found. - /queries/{id}/test: + /query/{id}/test: + parameters: + - in: path + name: id + required: true + schema: + type: string + format: uuid + description: The ID of the query. post: operationId: testQuery tags: - QueryService summary: Test a query description: Executes a test run of a query with the provided parameters. - parameters: - - in: path - name: id - required: true - schema: - type: string - description: The ID of the query to test. requestBody: required: true content: @@ -214,21 +205,91 @@ paths: $ref: '#/components/schemas/QueryTestResponse' '400': description: Invalid request body. + + /job: + post: + operationId: createJob + tags: + - JobService + summary: Create a new job + description: Creates a new job with the provided details. + requestBody: + required: true + content: + application/json: + schema: + $ref: '#/components/schemas/JobCreate' + responses: + '201': + description: Job created successfully. + content: + application/json: + schema: + $ref: '#/components/schemas/IdMessage' + '400': + description: Invalid request body. + + /job/{id}: + parameters: + - in: path + name: id + required: true + schema: + type: string + format: uuid + description: The job ID. + get: + operationId: getJob + tags: + - JobService + summary: Get a job by ID + description: Retrieves a specific job by its ID. + responses: + '200': + description: Job details. + content: + application/json: + schema: + $ref: '#/components/schemas/Job' + '400': + description: Invalid request parameters. + '404': + description: Job not found. + patch: + operationId: updateJob + tags: + - JobService + summary: Update a job + description: Updates an existing job with new details. + requestBody: + required: true + content: + application/json: + schema: + $ref: '#/components/schemas/JobUpdate' + responses: + '204': + description: Job updated successfully. + '400': + description: Invalid request body. + '404': + description: Job not found. /job/{id}/collector: + parameters: + - in: path + name: id + required: true + schema: + type: string + format: uuid + description: The job ID for the collector. get: operationId: getJobCollectorByJobId tags: - JobCollectorService summary: Get a job collector by ID description: Retrieves a specific job collector by its ID. - parameters: - - in: path - name: id - required: true - schema: - type: string - description: The job ID for the collector. responses: '200': description: Job collector details. @@ -244,13 +305,6 @@ paths: - JobCollectorService summary: Update a job collector description: Updates an existing job collector with new details. - parameters: - - in: path - name: id - required: true - schema: - type: string - description: The ID of the job collector to update. requestBody: required: true content: @@ -291,19 +345,20 @@ paths: description: Job not found. /job/export/{id}: + parameters: + - in: path + name: id + required: true + schema: + type: string + format: uuid + description: The ID of the export. get: operationId: exportState tags: - ExportService summary: Check export state. description: Checks the current state of an export. - parameters: - - in: path - name: id - required: true - schema: - type: string - description: The ID of the export. responses: '200': description: Export has been completed. @@ -329,6 +384,7 @@ components: properties: id: type: string + format: uuid description: Unique identifier for the query. type: $ref: '#/components/schemas/QueryType' @@ -348,6 +404,7 @@ components: type: array items: type: string + format: uuid description: List of required query IDs. required: - id @@ -379,6 +436,7 @@ components: type: array items: type: string + format: uuid description: List of required query IDs. required: - type @@ -397,6 +455,7 @@ components: type: array items: type: string + format: uuid description: Updated list of required query IDs. QueryTestRequest: @@ -404,6 +463,7 @@ components: properties: document_id: type: string + format: uuid description: ID of the document to test against. query_version: type: integer @@ -427,6 +487,7 @@ components: properties: id: type: string + format: uuid description: The client id name: type: string @@ -439,6 +500,42 @@ components: - name - can_sync + Job: + type: object + properties: + id: + type: string + format: uuid + description: The job id + client_id: + type: string + format: uuid + description: The client id the job belongs to + can_sync: + type: boolean + description: Specifies whether the job is actively syncing + required: + - id + - client_id + - can_sync + + JobCreate: + type: object + properties: + client_id: + type: string + format: uuid + description: The client id the job belongs to + required: + - client_id + + JobUpdate: + type: object + properties: + can_sync: + type: boolean + description: Specifies whether the job is actively syncing + ClientCreate: type: object properties: @@ -463,6 +560,7 @@ components: properties: id: type: string + format: uuid description: Unique identifier for entity. required: - id @@ -472,6 +570,7 @@ components: properties: job_id: type: string + format: uuid description: The ID of the associated job. active_version: type: integer @@ -535,6 +634,7 @@ components: description: The output field name. query_id: type: string + format: uuid description: The query id that will populate the result. required: - name @@ -545,6 +645,7 @@ components: properties: job_id: type: string + format: uuid description: The job id of the query results to be exported. ingestion_filters: type: object @@ -610,6 +711,7 @@ components: properties: job_id: type: string + format: uuid description: The job id relative to the export. status: $ref: '#/components/schemas/ExportStatus' diff --git a/test/queryService/job_test.go b/test/queryService/job_test.go new file mode 100644 index 00000000..80557dc6 --- /dev/null +++ b/test/queryService/job_test.go @@ -0,0 +1,52 @@ +package integration_test + +import ( + "context" + "queryorchestration/internal/test" + queryservice "queryorchestration/pkg/queryService" + "testing" + + "github.com/stretchr/testify/assert" +) + +func TestJob(t *testing.T) { + ctx := context.Background() + + address, cleanup := test.CreateAPIWithDependencies(t, ctx, "queryService") + defer cleanup() + + client, err := queryservice.NewClientWithResponses(address) + assert.Nil(t, err) + + clientRes, err := client.CreateClientWithResponse(ctx, queryservice.ClientCreate{ + Name: "example_name", + }) + assert.Nil(t, err) + idRes, err := client.CreateJobWithResponse(ctx, queryservice.JobCreate{ + ClientId: clientRes.JSON201.Id, + }) + assert.Nil(t, err) + assert.NotNil(t, idRes) + assert.NotNil(t, idRes.JSON201) + assert.NotNil(t, idRes.JSON201.Id) + id := idRes.JSON201.Id + + jobRes, err := client.GetJobWithResponse(ctx, id) + assert.Nil(t, err) + assert.Equal(t, id, jobRes.JSON200.Id) + assert.Equal(t, clientRes.JSON201.Id, jobRes.JSON200.ClientId) + assert.False(t, jobRes.JSON200.CanSync) + + updateCanSync := !jobRes.JSON200.CanSync + updateRes, err := client.UpdateJobWithResponse(ctx, id, queryservice.JobUpdate{ + CanSync: &updateCanSync, + }) + assert.Nil(t, err) + assert.NotNil(t, updateRes) + + jobRes, err = client.GetJobWithResponse(ctx, id) + assert.Nil(t, err) + assert.Equal(t, id, jobRes.JSON200.Id) + assert.Equal(t, clientRes.JSON201.Id, jobRes.JSON200.ClientId) + assert.False(t, jobRes.JSON200.CanSync) +} diff --git a/test/queryService/jobcollectorservice_test.go b/test/queryService/jobcollectorservice_test.go index 504a0f59..1ab12f60 100644 --- a/test/queryService/jobcollectorservice_test.go +++ b/test/queryService/jobcollectorservice_test.go @@ -6,7 +6,7 @@ import ( queryservice "queryorchestration/pkg/queryService" "testing" - "github.com/google/uuid" + "github.com/oapi-codegen/runtime/types" "github.com/stretchr/testify/assert" ) @@ -29,13 +29,22 @@ func TestJobCollectorService(t *testing.T) { jsonRes, err := client.CreateQueryWithResponse(ctx, queryservice.QueryCreate{ Type: queryservice.JSONEXTRACTOR, Config: &jsoncfg, - RequiredQueries: &[]string{ + RequiredQueries: &[]types.UUID{ contextRes.JSON201.Id, }, }) assert.Nil(t, err) - jobID := uuid.NewString() + clientRes, err := client.CreateClientWithResponse(ctx, queryservice.ClientCreate{ + Name: "example_name", + }) + assert.Nil(t, err) + jobRes, err := client.CreateJobWithResponse(ctx, queryservice.JobCreate{ + ClientId: clientRes.JSON201.Id, + }) + assert.Nil(t, err) + id := jobRes.JSON201.Id + fields := []queryservice.JobCollectorField{ { Name: "json_output", @@ -43,27 +52,34 @@ func TestJobCollectorService(t *testing.T) { }, } - collRes, err := client.GetJobCollectorByJobIdWithResponse(ctx, jobID) + collRes, err := client.GetJobCollectorByJobIdWithResponse(ctx, id) assert.Nil(t, err) - assert.NotNil(t, collRes.JSON200) - assert.EqualExportedValues(t, queryservice.JobCollector{ - JobId: jobID, - Fields: fields, - }, *collRes.JSON200) + assert.Equal(t, id, collRes.JSON200.JobId) + assert.Equal(t, 1, collRes.JSON200.ActiveVersion) + assert.Equal(t, 1, collRes.JSON200.LatestVersion) + assert.Equal(t, 1, collRes.JSON200.MinimumCleanerVersion) + assert.Equal(t, 1, collRes.JSON200.MinimumTextVersion) + assert.Len(t, collRes.JSON200.Fields, 0) - fields = []queryservice.JobCollectorField{ - { - Name: "json", - QueryId: jsonRes.JSON201.Id, - }, - } - res, err := client.UpdateJobCollectorByJobIdWithResponse(ctx, jobID, queryservice.JobCollectorUpdate{ - Fields: &fields, + av := int32(2) + minClean := int32(2) + minText := int32(2) + uRes, err := client.UpdateJobCollectorByJobIdWithResponse(ctx, id, queryservice.JobCollectorUpdate{ + ActiveVersion: &av, + MinimumCleanerVersion: &minClean, + MinimumTextVersion: &minText, + Fields: &fields, }) assert.Nil(t, err) - assert.EqualExportedValues(t, queryservice.JobCollector{ - JobId: jobID, - Fields: fields, - }, *collRes.JSON200) - assert.NotNil(t, res) + assert.Nil(t, uRes) + + collRes, err = client.GetJobCollectorByJobIdWithResponse(ctx, id) + assert.Nil(t, err) + assert.Equal(t, id, collRes.JSON200.JobId) + assert.Equal(t, 2, collRes.JSON200.ActiveVersion) + assert.Equal(t, 2, collRes.JSON200.LatestVersion) + assert.Equal(t, 2, collRes.JSON200.MinimumCleanerVersion) + assert.Equal(t, 2, collRes.JSON200.MinimumTextVersion) + assert.Len(t, collRes.JSON200.Fields, 1) + assert.ElementsMatch(t, fields, collRes.JSON200.Fields) } diff --git a/test/queryService/queryservice_test.go b/test/queryService/queryservice_test.go index 28d44a4d..a17dbcad 100644 --- a/test/queryService/queryservice_test.go +++ b/test/queryService/queryservice_test.go @@ -6,6 +6,7 @@ import ( queryservice "queryorchestration/pkg/queryService" "testing" + "github.com/oapi-codegen/runtime/types" "github.com/stretchr/testify/assert" ) @@ -49,7 +50,7 @@ func TestQueryService(t *testing.T) { aV := int32(2) res, err := client.UpdateQueryWithResponse(ctx, jsonID, queryservice.QueryUpdate{ ActiveVersion: &aV, - RequiredQueries: &[]string{ + RequiredQueries: &[]types.UUID{ contextID, }, }) @@ -63,5 +64,5 @@ func TestQueryService(t *testing.T) { assert.Equal(t, int32(2), queryRes.JSON200.ActiveVersion) assert.Equal(t, int32(2), queryRes.JSON200.LatestVersion) assert.Nil(t, queryRes.JSON200.Config) - assert.ElementsMatch(t, []string{contextID}, *queryRes.JSON200.RequiredQueries) + assert.ElementsMatch(t, []types.UUID{contextID}, *queryRes.JSON200.RequiredQueries) } diff --git a/test/queryService/testquery_test.go b/test/queryService/testquery_test.go index cad5d702..05b75197 100644 --- a/test/queryService/testquery_test.go +++ b/test/queryService/testquery_test.go @@ -29,7 +29,7 @@ func TestQueryServiceTest(t *testing.T) { docId := uuid.New() testRes, err := client.TestQueryWithResponse(ctx, id, queryservice.QueryTestRequest{ - DocumentId: docId.String(), + DocumentId: docId, QueryVersion: int32(1), }) assert.Nil(t, err)