Merged in feature/docresult (pull request #105)

Document Result Endpoint

* testing

* cleantesting

* progress

* query

* lint

* readme

* dockerclient

* api

* passtest

* tests

* test
This commit is contained in:
Michael McGuinness
2025-03-17 18:14:15 +00:00
parent f7c41c4ef3
commit 555b6d420b
105 changed files with 3276 additions and 2484 deletions
+2 -2
View File
@@ -67,7 +67,7 @@ func TestDocCleanRunner(t *testing.T) {
Body: &body,
}
doc := document.Document{
doc := document.DocumentSummary{
ID: bod.ID,
ClientID: uuid.New(),
Hash: "example_hash",
@@ -82,7 +82,7 @@ func TestDocCleanRunner(t *testing.T) {
pgxmock.NewRows([]string{"isclean"}).
AddRow(false),
)
pool.ExpectQuery("name: GetDocument :one").WithArgs(dbid).
pool.ExpectQuery("name: GetDocumentSummary :one").WithArgs(dbid).
WillReturnRows(
pgxmock.NewRows([]string{"id", "clientId", "hash"}).
AddRow(dbid, database.MustToDBUUID(doc.ClientID), doc.Hash),
+4 -4
View File
@@ -51,7 +51,7 @@ func TestDocInitRunner(t *testing.T) {
clientId := uuid.New()
bucketName := "bucketName"
location := fmt.Sprintf("%s/aaa", clientId)
docinfo := document.Document{
docinfo := document.DocumentSummary{
ID: uuid.New(),
ClientID: clientId,
Hash: "example_hash",
@@ -91,7 +91,7 @@ func TestDocInitRunner(t *testing.T) {
pool.ExpectExec("name: AddDocumentEntry :exec").WithArgs(database.MustToDBUUID(docinfo.ID), bucketName, location).
WillReturnResult(pgxmock.NewResult("", 1))
pool.ExpectCommit()
pool.ExpectQuery("name: GetDocument :one").WithArgs(database.MustToDBUUID(docinfo.ID)).
pool.ExpectQuery("name: GetDocumentSummary :one").WithArgs(database.MustToDBUUID(docinfo.ID)).
WillReturnRows(
pgxmock.NewRows([]string{"id", "clientId", "hash"}).
AddRow(database.MustToDBUUID(docinfo.ID), database.MustToDBUUID(docinfo.ClientID), "example"),
@@ -144,7 +144,7 @@ func TestProcessRecord(t *testing.T) {
}
bucketName := "bucketName"
location := fmt.Sprintf("%s/aaa", j.ID.String())
docinfo := document.Document{
docinfo := document.DocumentSummary{
ID: uuid.New(),
ClientID: j.ID,
Hash: "example_hash",
@@ -174,7 +174,7 @@ func TestProcessRecord(t *testing.T) {
pool.ExpectExec("name: AddDocumentEntry :exec").WithArgs(database.MustToDBUUID(docinfo.ID), bucketName, location).
WillReturnResult(pgxmock.NewResult("", 1))
pool.ExpectCommit()
pool.ExpectQuery("name: GetDocument :one").WithArgs(database.MustToDBUUID(docinfo.ID)).
pool.ExpectQuery("name: GetDocumentSummary :one").WithArgs(database.MustToDBUUID(docinfo.ID)).
WillReturnRows(
pgxmock.NewRows([]string{"id", "clientId", "hash"}).
AddRow(database.MustToDBUUID(docinfo.ID), database.MustToDBUUID(docinfo.ClientID), "example"),
+2 -2
View File
@@ -55,7 +55,7 @@ func TestDocInitRunner(t *testing.T) {
j := client.Client{
ID: uuid.New(),
}
docinfo := document.Document{
docinfo := document.DocumentSummary{
ID: uuid.New(),
ClientID: j.ID,
}
@@ -69,7 +69,7 @@ func TestDocInitRunner(t *testing.T) {
Body: &body,
}
pool.ExpectQuery("name: GetDocument :one").WithArgs(database.MustToDBUUID(docinfo.ID)).
pool.ExpectQuery("name: GetDocumentSummary :one").WithArgs(database.MustToDBUUID(docinfo.ID)).
WillReturnRows(
pgxmock.NewRows([]string{"id", "clientId", "hash"}).
AddRow(database.MustToDBUUID(docinfo.ID), database.MustToDBUUID(docinfo.ClientID), "example"),
+5 -2
View File
@@ -82,8 +82,11 @@ func TestDocCleanRunner(t *testing.T) {
pgxmock.NewRows([]string{"id", "documentId", "bucket", "key", "version", "mimetype", "fail"}).
AddRow(cleanId, database.MustToDBUUID(doc.ID), &inloc.Bucket, &inloc.Key, int64(1), dbmimetype, repository.NullCleanfailtype{}),
)
pool.ExpectExec("name: AddDocumentTextEntry :exec").WithArgs(pgxmock.AnyArg(), inloc.Bucket, inloc.Key, cleanId).
WillReturnResult(pgxmock.NewResult("", 1))
pool.ExpectQuery("name: AddDocumentTextEntry :one").WithArgs(pgxmock.AnyArg(), inloc.Bucket, inloc.Key, cleanId).
WillReturnRows(
pgxmock.NewRows([]string{"id"}).
AddRow(database.MustToDBUUID(uuid.New())),
)
mockSQS.EXPECT().
SendMessage(
@@ -1,7 +1,7 @@
// Package queryservice provides primitives to interact with the openapi HTTP API.
// Package queryapi provides primitives to interact with the openapi HTTP API.
//
// Code generated by github.com/oapi-codegen/oapi-codegen/v2 version 2.4.1 DO NOT EDIT.
package queryservice
package queryapi
import (
"bytes"
@@ -172,19 +172,31 @@ type DocClient struct {
// Document The document properties.
type Document struct {
// Bucket The bucket containing the document
Bucket string `json:"bucket"`
// ClientId The client external id
ClientId ClientID `json:"client_id"`
// Fields The fields and the value for the document
Fields map[string]interface{} `json:"fields"`
// Hash The document hash
Hash Hash `json:"hash"`
// Id The document id.
Id DocumentID `json:"id"`
// Key The path to the document
Key string `json:"key"`
}
// DocumentID The document id.
type DocumentID = openapi_types.UUID
// DocumentSummary The document properties.
type DocumentSummary struct {
// Hash The document hash
Hash Hash `json:"hash"`
// Id The document id.
Id DocumentID `json:"id"`
}
// ExportDetails Payload for export trigger response.
type ExportDetails struct {
// ClientId The client external id
@@ -233,6 +245,9 @@ type FieldFilter struct {
// FieldFilterCondition The possible field filtering conditions.
type FieldFilterCondition string
// Hash The document hash
type Hash = string
// IdMessage A single uuid.
type IdMessage struct {
// Id Unique identifier for entity.
@@ -240,7 +255,7 @@ type IdMessage struct {
}
// ListDocuments The documents in the client.
type ListDocuments = []Document
type ListDocuments = []DocumentSummary
// ListQueries A set of queries.
type ListQueries struct {
@@ -370,6 +385,9 @@ type ServerInterface interface {
// Get client sync status
// (GET /client/{id}/status)
GetStatusByClientId(ctx echo.Context, id ClientID) error
// Get document details by its id
// (GET /document/{id})
GetDocument(ctx echo.Context, id DocumentID) error
// Check export state.
// (GET /export/{id})
ExportState(ctx echo.Context, id ExportID) error
@@ -417,6 +435,8 @@ func (w *ServerInterfaceWrapper) GetClient(ctx echo.Context) error {
return echo.NewHTTPError(http.StatusBadRequest, fmt.Sprintf("Invalid format for parameter id: %s", err))
}
ctx.Set(PlaceholderAuthScopes, []string{})
// Invoke the callback with all the unmarshaled arguments
err = w.Handler.GetClient(ctx, id)
return err
@@ -530,6 +550,24 @@ func (w *ServerInterfaceWrapper) GetStatusByClientId(ctx echo.Context) error {
return err
}
// GetDocument converts echo context to params.
func (w *ServerInterfaceWrapper) GetDocument(ctx echo.Context) error {
var err error
// ------------- Path parameter "id" -------------
var id DocumentID
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))
}
ctx.Set(PlaceholderAuthScopes, []string{})
// Invoke the callback with all the unmarshaled arguments
err = w.Handler.GetDocument(ctx, id)
return err
}
// ExportState converts echo context to params.
func (w *ServerInterfaceWrapper) ExportState(ctx echo.Context) error {
var err error
@@ -660,6 +698,7 @@ func RegisterHandlersWithBaseURL(router EchoRouter, si ServerInterface, baseURL
router.GET(baseURL+"/client/:id/documents", wrapper.ListDocumentsByClientId)
router.POST(baseURL+"/client/:id/export", wrapper.TriggerExport)
router.GET(baseURL+"/client/:id/status", wrapper.GetStatusByClientId)
router.GET(baseURL+"/document/:id", wrapper.GetDocument)
router.GET(baseURL+"/export/:id", wrapper.ExportState)
router.GET(baseURL+"/query", wrapper.ListQueries)
router.POST(baseURL+"/query", wrapper.CreateQuery)
@@ -672,60 +711,63 @@ func RegisterHandlersWithBaseURL(router EchoRouter, si ServerInterface, baseURL
// Base64 encoded, gzipped, json marshaled Swagger object
var swaggerSpec = []string{
"H4sIAAAAAAAC/+xbaXMjt9H+Kyi8/mbeh0jprXyQpbWLyUa7WWlTTnYVFjjTJGEPZygAI4ne4n9P4ZoT",
"Qw654tou5ZsoXI3uBw8a3T1fsBet1lEIoeD44gteAvGBqT8/EAFv6YoK+cMH7jG6FjQK8Y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vRtYpNczjbPTkc5t6Rp4rgKU4beahSYzs5q+8tLqiBk+seTX8TpPo+k7eaEipMC",
"4WsvONXmnzbX3XfPwKjV976RnbuSvlS/Xhyq+2CVG87/jKSQPQPGz47YbDtiBWwL/YfHJNDccwirWwZt",
"0ioZWRy8hnSz3O1+1Ms56aPBd6Gpi0Z+7CX9UrJFK6YBGqMV5xs2brf9yPt92/KidfuxI1Gv1yjO9M7g",
"VkRsgeQgEbDJnApLG7/ySZpdo+Y0ptCSnalYfKk7WVqSSeYq3fPrzpVG53qmRPN1Z1A3xcwM+Svi7n73",
"7wAAAP//OVAUyb5OAAA=",
}
// GetSwagger returns the content of the embedded swagger specification file
@@ -1,4 +1,4 @@
package queryservice
package queryapi
import (
"fmt"
@@ -28,7 +28,7 @@ func (s *Controllers) CreateClient(ctx echo.Context) error {
})
}
func (s *Controllers) GetClient(ctx echo.Context, id string) error {
func (s *Controllers) GetClient(ctx echo.Context, id ClientID) error {
client, err := s.svc.Client.GetByExternalId(ctx.Request().Context(), id)
if err != nil {
return echo.NewHTTPError(http.StatusBadRequest, fmt.Sprintf("Unable to get client: %s", err))
@@ -42,7 +42,7 @@ func (s *Controllers) GetClient(ctx echo.Context, id string) error {
})
}
func (s *Controllers) UpdateClient(ctx echo.Context, id string) error {
func (s *Controllers) UpdateClient(ctx echo.Context, id ClientID) error {
req := ClientUpdate{}
if err := ctx.Bind(&req); err != nil {
return echo.NewHTTPError(http.StatusBadRequest, err)
@@ -1,4 +1,4 @@
package queryservice_test
package queryapi_test
import (
"encoding/json"
@@ -8,7 +8,7 @@ import (
"strings"
"testing"
queryservice "queryorchestration/api/queryService"
queryapi "queryorchestration/api/queryAPI"
"queryorchestration/internal/client"
"queryorchestration/internal/database"
"queryorchestration/internal/database/repository"
@@ -30,11 +30,11 @@ func TestCreateClient(t *testing.T) {
cfg.DBPool = pool
cfg.DBQueries = repository.New(pool)
cons := queryservice.NewControllers(validator.New(), &queryservice.Services{
cons := queryapi.NewControllers(validator.New(), &queryapi.Services{
Client: client.New(cfg),
})
body := queryservice.ClientCreate{
body := queryapi.ClientCreate{
Name: "example_name",
Id: "external_id",
}
@@ -66,7 +66,7 @@ func TestGetClient(t *testing.T) {
cfg.DBPool = pool
cfg.DBQueries = repository.New(pool)
cons := queryservice.NewControllers(validator.New(), &queryservice.Services{
cons := queryapi.NewControllers(validator.New(), &queryapi.Services{
Client: client.New(cfg),
})
@@ -89,10 +89,10 @@ func TestGetClient(t *testing.T) {
assert.NoError(t, err)
assert.Equal(t, http.StatusOK, rec.Code)
var res queryservice.DocClient
var res queryapi.DocClient
err = json.Unmarshal(rec.Body.Bytes(), &res)
assert.NoError(t, err)
assert.EqualExportedValues(t, queryservice.DocClient{
assert.EqualExportedValues(t, queryapi.DocClient{
Id: id,
Uid: clientUid,
Name: "client_name",
@@ -108,12 +108,12 @@ func TestUpdateClient(t *testing.T) {
cfg.DBPool = pool
cfg.DBQueries = repository.New(pool)
cons := queryservice.NewControllers(validator.New(), &queryservice.Services{
cons := queryapi.NewControllers(validator.New(), &queryapi.Services{
Client: client.New(cfg),
})
cs := false
body := queryservice.ClientUpdate{
body := queryapi.ClientUpdate{
CanSync: &cs,
}
bodyBytes, err := json.Marshal(body)
@@ -1,4 +1,4 @@
package queryservice
package queryapi
import (
"fmt"
@@ -10,7 +10,7 @@ import (
"github.com/labstack/echo/v4"
)
func (s *Controllers) GetCollectorByClientId(ctx echo.Context, clientId string) error {
func (s *Controllers) GetCollectorByClientId(ctx echo.Context, clientId ClientID) error {
coll, err := s.svc.Collector.GetByClientExternalID(ctx.Request().Context(), clientId)
if err != nil {
return echo.NewHTTPError(http.StatusBadRequest, fmt.Sprintf("Unable to get collector: %s", err))
@@ -36,7 +36,7 @@ func (s *Controllers) GetCollectorByClientId(ctx echo.Context, clientId string)
})
}
func (s *Controllers) SetCollectorByClientId(ctx echo.Context, clientId string) error {
func (s *Controllers) SetCollectorByClientId(ctx echo.Context, clientId ClientID) error {
req := CollectorSet{}
if err := ctx.Bind(&req); err != nil {
return echo.NewHTTPError(http.StatusBadRequest, err)
@@ -1,4 +1,4 @@
package queryservice_test
package queryapi_test
import (
"encoding/json"
@@ -8,7 +8,7 @@ import (
"strings"
"testing"
queryservice "queryorchestration/api/queryService"
queryapi "queryorchestration/api/queryAPI"
"queryorchestration/internal/collector"
collectorset "queryorchestration/internal/collector/set"
"queryorchestration/internal/database"
@@ -49,10 +49,10 @@ func TestSetCollector(t *testing.T) {
av := int32(2)
cv := int64(1)
body := queryservice.CollectorSet{
body := queryapi.CollectorSet{
ActiveVersion: &av,
MinimumCleanerVersion: &cv,
Fields: &[]queryservice.CollectorField{
Fields: &[]queryapi.CollectorField{
{
Name: "a",
QueryId: uuid.New(),
@@ -68,7 +68,7 @@ func TestSetCollector(t *testing.T) {
rec := httptest.NewRecorder()
ctx := e.NewContext(req, rec)
cons := queryservice.NewControllers(validator.New(), &queryservice.Services{
cons := queryapi.NewControllers(validator.New(), &queryapi.Services{
CollectorSet: collectorset.New(cfg, &collectorset.Services{
Collector: collector.New(cfg),
}),
@@ -134,7 +134,7 @@ func TestGetCollectorByclientId(t *testing.T) {
ctx := e.NewContext(req, rec)
svc := collector.New(cfg)
cons := queryservice.NewControllers(validator.New(), &queryservice.Services{
cons := queryapi.NewControllers(validator.New(), &queryapi.Services{
Collector: svc,
})
@@ -156,15 +156,15 @@ func TestGetCollectorByclientId(t *testing.T) {
assert.NoError(t, err)
assert.Equal(t, http.StatusOK, rec.Code)
var res queryservice.Collector
var res queryapi.Collector
err = json.Unmarshal(rec.Body.Bytes(), &res)
assert.NoError(t, err)
assert.EqualExportedValues(t, queryservice.Collector{
assert.EqualExportedValues(t, queryapi.Collector{
ClientId: id,
MinimumCleanerVersion: coll.MinCleanVersion,
MinimumTextVersion: coll.MinTextVersion,
ActiveVersion: int32(1),
LatestVersion: int32(2),
Fields: []queryservice.CollectorField{},
Fields: []queryapi.CollectorField{},
}, res)
}
@@ -1,4 +1,4 @@
package queryservice
package queryapi
import (
"queryorchestration/internal/client"
@@ -13,7 +13,7 @@ import (
"github.com/go-playground/validator/v10"
)
const Name = "queryService"
const Name = "queryAPI"
type Services struct {
Export *export.Service
@@ -1,15 +1,15 @@
package queryservice_test
package queryapi_test
import (
"testing"
queryservice "queryorchestration/api/queryService"
queryapi "queryorchestration/api/queryAPI"
"github.com/go-playground/validator/v10"
"github.com/stretchr/testify/assert"
)
func TestNewControllers(t *testing.T) {
cons := queryservice.NewControllers(validator.New(), &queryservice.Services{})
cons := queryapi.NewControllers(validator.New(), &queryapi.Services{})
assert.NotNil(t, cons)
}
+39
View File
@@ -0,0 +1,39 @@
package queryapi
import (
"fmt"
"net/http"
"github.com/labstack/echo/v4"
)
func (s *Controllers) ListDocumentsByClientId(ctx echo.Context, clientId ClientID) error {
documents, err := s.svc.Document.ListByClientExternalId(ctx.Request().Context(), clientId)
if err != nil {
return echo.NewHTTPError(http.StatusBadRequest, fmt.Sprintf("Unable to list documents: %s", err))
}
docs := make([]DocumentSummary, len(documents))
for i, doc := range documents {
docs[i] = DocumentSummary{
Id: doc.ID,
Hash: doc.Hash,
}
}
return ctx.JSON(http.StatusOK, docs)
}
func (s *Controllers) GetDocument(ctx echo.Context, id DocumentID) error {
document, err := s.svc.Document.GetExternal(ctx.Request().Context(), id)
if err != nil {
return echo.NewHTTPError(http.StatusBadRequest, fmt.Sprintf("Unable to list documents: %s", err))
}
return ctx.JSON(http.StatusOK, Document{
Id: document.Id,
ClientId: document.ClientID,
Hash: document.Hash,
Fields: document.Fields,
})
}
+122
View File
@@ -0,0 +1,122 @@
package queryapi_test
import (
"encoding/json"
"net/http"
"net/http/httptest"
"strings"
"testing"
queryapi "queryorchestration/api/queryAPI"
"queryorchestration/internal/database"
"queryorchestration/internal/database/repository"
"queryorchestration/internal/document"
"queryorchestration/internal/serviceconfig"
"queryorchestration/internal/serviceconfig/queue/clientsync"
queuemock "queryorchestration/mocks/queue"
"github.com/go-playground/validator/v10"
"github.com/google/uuid"
"github.com/labstack/echo/v4"
"github.com/pashagolub/pgxmock/v3"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestListDocumentsByClientId(t *testing.T) {
pool, err := pgxmock.NewPool()
require.NoError(t, err)
cfg := &struct {
serviceconfig.BaseConfig
clientsync.ClientSyncConfig
}{}
cfg.DBPool = pool
cfg.DBQueries = repository.New(pool)
mockSQS := queuemock.NewMockSQSClient(t)
cfg.QueueClient = mockSQS
clientId := "clientid"
e := echo.New()
req := httptest.NewRequest(http.MethodPost, "/", strings.NewReader(""))
req.Header.Set(echo.HeaderContentType, echo.MIMEApplicationJSON)
rec := httptest.NewRecorder()
ctx := e.NewContext(req, rec)
cons := queryapi.NewControllers(validator.New(), &queryapi.Services{
Document: document.New(cfg),
})
ctx.Set("id", clientId)
doc := queryapi.ListDocuments{
{
Id: uuid.New(),
Hash: "hash",
},
}
pool.ExpectQuery("name: ListDocumentsByClientExternalId :many").WithArgs(clientId).
WillReturnRows(
pgxmock.NewRows([]string{"id", "hash"}).
AddRow(database.MustToDBUUID(doc[0].Id), "hash"),
)
err = cons.ListDocumentsByClientId(ctx, clientId)
assert.NoError(t, err)
assert.Equal(t, http.StatusOK, rec.Code)
var res queryapi.ListDocuments
err = json.Unmarshal(rec.Body.Bytes(), &res)
assert.NoError(t, err)
assert.EqualExportedValues(t, doc, res)
}
func TestGetDocument(t *testing.T) {
pool, err := pgxmock.NewPool()
require.NoError(t, err)
cfg := &struct {
serviceconfig.BaseConfig
clientsync.ClientSyncConfig
}{}
cfg.DBPool = pool
cfg.DBQueries = repository.New(pool)
mockSQS := queuemock.NewMockSQSClient(t)
cfg.QueueClient = mockSQS
docId := uuid.New()
e := echo.New()
req := httptest.NewRequest(http.MethodPost, "/", strings.NewReader(""))
req.Header.Set(echo.HeaderContentType, echo.MIMEApplicationJSON)
rec := httptest.NewRecorder()
ctx := e.NewContext(req, rec)
cons := queryapi.NewControllers(validator.New(), &queryapi.Services{
Document: document.New(cfg),
})
ctx.Set("id", docId)
doc := queryapi.Document{
Id: docId,
ClientId: "externalID",
Hash: "example",
Fields: map[string]interface{}{
"json": "hello",
},
}
pool.ExpectQuery("name: GetDocumentExternal :one").WithArgs(database.MustToDBUUID(docId)).
WillReturnRows(
pgxmock.NewRows([]string{"id", "clientId", "hash", "fields"}).
AddRow(database.MustToDBUUID(doc.Id), "externalID", "example", []byte(`{"json": "hello"}`)),
)
err = cons.GetDocument(ctx, docId)
assert.NoError(t, err)
assert.Equal(t, http.StatusOK, rec.Code)
var res queryapi.Document
err = json.Unmarshal(rec.Body.Bytes(), &res)
assert.NoError(t, err)
assert.EqualExportedValues(t, doc, res)
}
@@ -1,16 +1,15 @@
package queryservice
package queryapi
import (
"net/http"
"github.com/labstack/echo/v4"
"github.com/oapi-codegen/runtime/types"
)
func (s *Controllers) TriggerExport(ctx echo.Context, clientId string) error {
func (s *Controllers) TriggerExport(ctx echo.Context, clientId ClientID) error {
return ctx.JSON(http.StatusOK, map[string]string{"status": "export triggered"})
}
func (s *Controllers) ExportState(ctx echo.Context, id types.UUID) error {
func (s *Controllers) ExportState(ctx echo.Context, id ExportID) error {
return ctx.JSON(http.StatusOK, map[string]string{"status": "export triggered"})
}
@@ -1,4 +1,4 @@
package queryservice_test
package queryapi_test
import (
"net/http"
@@ -6,7 +6,7 @@ import (
"strings"
"testing"
queryservice "queryorchestration/api/queryService"
queryapi "queryorchestration/api/queryAPI"
"github.com/go-playground/validator/v10"
"github.com/google/uuid"
@@ -20,7 +20,7 @@ func TestTriggerExport(t *testing.T) {
rec := httptest.NewRecorder()
ctx := e.NewContext(req, rec)
cons := queryservice.NewControllers(validator.New(), &queryservice.Services{})
cons := queryapi.NewControllers(validator.New(), &queryapi.Services{})
err := cons.TriggerExport(ctx, "clientid")
assert.NoError(t, err)
@@ -34,7 +34,7 @@ func TestExportState(t *testing.T) {
rec := httptest.NewRecorder()
ctx := e.NewContext(req, rec)
cons := queryservice.NewControllers(validator.New(), &queryservice.Services{})
cons := queryapi.NewControllers(validator.New(), &queryapi.Services{})
id := uuid.New()
@@ -1,4 +1,4 @@
package queryservice
package queryapi
import (
"errors"
@@ -1,4 +1,4 @@
package queryservice
package queryapi
import (
"testing"
@@ -1,4 +1,4 @@
package queryservice
package queryapi
import (
"fmt"
@@ -8,7 +8,6 @@ import (
resultprocessor "queryorchestration/internal/query/result/processor"
"github.com/labstack/echo/v4"
"github.com/oapi-codegen/runtime/types"
)
func (s *Controllers) ListQueries(ctx echo.Context) error {
@@ -27,7 +26,7 @@ func (s *Controllers) ListQueries(ctx echo.Context) error {
})
}
func (s *Controllers) GetQuery(ctx echo.Context, id types.UUID) error {
func (s *Controllers) GetQuery(ctx echo.Context, id QueryID) error {
query, err := s.svc.Query.Get(ctx.Request().Context(), id)
if err != nil {
return echo.NewHTTPError(http.StatusBadRequest, fmt.Sprintf("Unable to get query: %s", err))
@@ -66,7 +65,7 @@ func (s *Controllers) CreateQuery(ctx echo.Context) error {
})
}
func (s *Controllers) UpdateQuery(ctx echo.Context, id types.UUID) error {
func (s *Controllers) UpdateQuery(ctx echo.Context, id QueryID) error {
req := QueryUpdate{}
if err := ctx.Bind(&req); err != nil {
return echo.NewHTTPError(http.StatusBadRequest, err)
@@ -85,7 +84,7 @@ func (s *Controllers) UpdateQuery(ctx echo.Context, id types.UUID) error {
return ctx.NoContent(http.StatusOK)
}
func (s *Controllers) TestQuery(ctx echo.Context, id types.UUID) error {
func (s *Controllers) TestQuery(ctx echo.Context, id QueryID) error {
req := QueryTestRequest{}
if err := ctx.Bind(&req); err != nil {
return echo.NewHTTPError(http.StatusBadRequest, err)
@@ -1,4 +1,4 @@
package queryservice_test
package queryapi_test
import (
"encoding/json"
@@ -8,7 +8,7 @@ import (
"strings"
"testing"
queryservice "queryorchestration/api/queryService"
queryapi "queryorchestration/api/queryAPI"
"queryorchestration/internal/collector"
"queryorchestration/internal/database"
"queryorchestration/internal/database/repository"
@@ -41,12 +41,12 @@ func TestCreateQuery(t *testing.T) {
cfg.DBPool = pool
cfg.DBQueries = repository.New(pool)
cons := queryservice.NewControllers(validator.New(), &queryservice.Services{
cons := queryapi.NewControllers(validator.New(), &queryapi.Services{
Query: query.New(cfg),
})
body := queryservice.QueryCreate{
Type: queryservice.CONTEXTFULL,
body := queryapi.QueryCreate{
Type: queryapi.CONTEXTFULL,
}
bodyBytes, err := json.Marshal(body)
assert.NoError(t, err)
@@ -85,7 +85,7 @@ func TestListQueries(t *testing.T) {
cfg.DBPool = pool
cfg.DBQueries = repository.New(pool)
cons := queryservice.NewControllers(validator.New(), &queryservice.Services{
cons := queryapi.NewControllers(validator.New(), &queryapi.Services{
Query: query.New(cfg),
})
@@ -105,14 +105,14 @@ func TestListQueries(t *testing.T) {
assert.NoError(t, err)
assert.Equal(t, http.StatusOK, rec.Code)
var res queryservice.ListQueries
var res queryapi.ListQueries
err = json.Unmarshal(rec.Body.Bytes(), &res)
assert.NoError(t, err)
assert.NotNil(t, res.Queries)
assert.ElementsMatch(t, res.Queries, []queryservice.Query{
assert.ElementsMatch(t, res.Queries, []queryapi.Query{
{
Id: id,
Type: queryservice.CONTEXTFULL,
Type: queryapi.CONTEXTFULL,
ActiveVersion: 1,
LatestVersion: 2,
},
@@ -126,7 +126,7 @@ func TestGetQuery(t *testing.T) {
cfg.DBPool = pool
cfg.DBQueries = repository.New(pool)
cons := queryservice.NewControllers(validator.New(), &queryservice.Services{
cons := queryapi.NewControllers(validator.New(), &queryapi.Services{
Query: query.New(cfg),
})
@@ -148,12 +148,12 @@ func TestGetQuery(t *testing.T) {
assert.NoError(t, err)
assert.Equal(t, http.StatusOK, rec.Code)
var res queryservice.Query
var res queryapi.Query
err = json.Unmarshal(rec.Body.Bytes(), &res)
assert.NoError(t, err)
assert.EqualExportedValues(t, queryservice.Query{
assert.EqualExportedValues(t, queryapi.Query{
Id: id,
Type: queryservice.CONTEXTFULL,
Type: queryapi.CONTEXTFULL,
ActiveVersion: 1,
LatestVersion: 2,
}, res)
@@ -172,14 +172,14 @@ func TestUpdateQuery(t *testing.T) {
cfg.QueueClient = mockSQS
cfg.QueryVersionSyncURL = "here"
cons := queryservice.NewControllers(validator.New(), &queryservice.Services{
cons := queryapi.NewControllers(validator.New(), &queryapi.Services{
QueryUpdate: queryupdate.New(cfg, &queryupdate.Services{
Query: query.New(cfg),
}),
})
av := int32(2)
body := queryservice.QueryUpdate{
body := queryapi.QueryUpdate{
ActiveVersion: &av,
}
bodyBytes, err := json.Marshal(body)
@@ -230,7 +230,7 @@ func TestTestQuery(t *testing.T) {
docsvc := document.New(cfg)
col := collector.New(cfg)
que := query.New(cfg)
cons := queryservice.NewControllers(validator.New(), &queryservice.Services{
cons := queryapi.NewControllers(validator.New(), &queryapi.Services{
Collector: col,
Query: que,
QueryTest: querytest.New(cfg, &querytest.Services{
@@ -242,7 +242,7 @@ func TestTestQuery(t *testing.T) {
}),
})
doc := document.Document{
doc := document.DocumentSummary{
ID: uuid.New(),
}
params := &result.Process{
@@ -250,7 +250,7 @@ func TestTestQuery(t *testing.T) {
DocumentID: doc.ID,
QueryVersion: int32(3),
}
body := queryservice.QueryTestRequest{
body := queryapi.QueryTestRequest{
DocumentId: params.DocumentID,
QueryVersion: params.QueryVersion,
}
@@ -283,10 +283,10 @@ func TestTestQuery(t *testing.T) {
assert.NoError(t, err)
assert.Equal(t, http.StatusOK, rec.Code)
var res queryservice.QueryTestResponse
var res queryapi.QueryTestResponse
err = json.Unmarshal(rec.Body.Bytes(), &res)
assert.NoError(t, err)
assert.EqualExportedValues(t, queryservice.QueryTestResponse{
assert.EqualExportedValues(t, queryapi.QueryTestResponse{
Value: "old_value",
}, res)
}
@@ -1,4 +1,4 @@
package queryservice
package queryapi
import (
"fmt"
@@ -7,7 +7,7 @@ import (
"github.com/labstack/echo/v4"
)
func (s *Controllers) GetStatusByClientId(ctx echo.Context, id string) error {
func (s *Controllers) GetStatusByClientId(ctx echo.Context, id ClientID) error {
status, err := s.svc.Client.GetStatusByExternalId(ctx.Request().Context(), id)
if err != nil {
return echo.NewHTTPError(http.StatusBadRequest, fmt.Sprintf("Unable to find client: %s", err))
@@ -1,4 +1,4 @@
package queryservice_test
package queryapi_test
import (
"encoding/json"
@@ -7,7 +7,7 @@ import (
"strings"
"testing"
queryservice "queryorchestration/api/queryService"
queryapi "queryorchestration/api/queryAPI"
"queryorchestration/internal/client"
"queryorchestration/internal/database"
"queryorchestration/internal/database/repository"
@@ -28,7 +28,7 @@ func TestGetClientStatus(t *testing.T) {
cfg.DBPool = pool
cfg.DBQueries = repository.New(pool)
cons := queryservice.NewControllers(validator.New(), &queryservice.Services{
cons := queryapi.NewControllers(validator.New(), &queryapi.Services{
Client: client.New(cfg),
})
@@ -53,10 +53,10 @@ func TestGetClientStatus(t *testing.T) {
assert.NoError(t, err)
assert.Equal(t, http.StatusOK, rec.Code)
var res queryservice.ClientStatusBody
var res queryapi.ClientStatusBody
err = json.Unmarshal(rec.Body.Bytes(), &res)
assert.NoError(t, err)
assert.EqualExportedValues(t, queryservice.ClientStatusBody{
Status: queryservice.INSYNC,
assert.EqualExportedValues(t, queryapi.ClientStatusBody{
Status: queryapi.INSYNC,
}, res)
}
-26
View File
@@ -1,26 +0,0 @@
package queryservice
import (
"fmt"
"net/http"
"github.com/labstack/echo/v4"
)
func (s *Controllers) ListDocumentsByClientId(ctx echo.Context, clientId string) error {
documents, err := s.svc.Document.ListByClientExternalId(ctx.Request().Context(), clientId)
if err != nil {
return echo.NewHTTPError(http.StatusBadRequest, fmt.Sprintf("Unable to list documents: %s", err))
}
docs := make([]Document, len(documents))
for i, doc := range documents {
docs[i] = Document{
Id: doc.ID,
Bucket: doc.Bucket,
Key: doc.Key,
}
}
return ctx.JSON(http.StatusOK, docs)
}
-73
View File
@@ -1,73 +0,0 @@
package queryservice_test
import (
"encoding/json"
"net/http"
"net/http/httptest"
"strings"
"testing"
queryservice "queryorchestration/api/queryService"
"queryorchestration/internal/database"
"queryorchestration/internal/database/repository"
"queryorchestration/internal/document"
"queryorchestration/internal/serviceconfig"
"queryorchestration/internal/serviceconfig/queue/clientsync"
queuemock "queryorchestration/mocks/queue"
"github.com/go-playground/validator/v10"
"github.com/google/uuid"
"github.com/labstack/echo/v4"
"github.com/pashagolub/pgxmock/v3"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestListDocumentsByClientId(t *testing.T) {
pool, err := pgxmock.NewPool()
require.NoError(t, err)
cfg := &struct {
serviceconfig.BaseConfig
clientsync.ClientSyncConfig
}{}
cfg.DBPool = pool
cfg.DBQueries = repository.New(pool)
mockSQS := queuemock.NewMockSQSClient(t)
cfg.QueueClient = mockSQS
clientId := "clientid"
e := echo.New()
req := httptest.NewRequest(http.MethodPost, "/", strings.NewReader(""))
req.Header.Set(echo.HeaderContentType, echo.MIMEApplicationJSON)
rec := httptest.NewRecorder()
ctx := e.NewContext(req, rec)
cons := queryservice.NewControllers(validator.New(), &queryservice.Services{
Document: document.New(cfg),
})
ctx.Set("id", clientId)
doc := queryservice.ListDocuments{
{
Id: uuid.New(),
Bucket: "bucketone",
Key: "keyone",
},
}
pool.ExpectQuery("name: ListDocumentsByClientExternalId :many").WithArgs(clientId).
WillReturnRows(
pgxmock.NewRows([]string{"id", "bucket", "key"}).
AddRow(database.MustToDBUUID(doc[0].Id), doc[0].Bucket, doc[0].Key),
)
err = cons.ListDocumentsByClientId(ctx, clientId)
assert.NoError(t, err)
assert.Equal(t, http.StatusOK, rec.Code)
var res queryservice.ListDocuments
err = json.Unmarshal(rec.Body.Bytes(), &res)
assert.NoError(t, err)
assert.EqualExportedValues(t, doc, res)
}
+9 -6
View File
@@ -1,15 +1,18 @@
# Api related artifacts
## Prometheus metrics
Prometheus metrics are exposed for all api endpoints automatically at the standard `/metrics` endpoint. (http://localhost:8080/metrics)
## Swagger API documentation
Automatic API docs are generated and exposed for all routes at http://localhost:8080/swagger/index.html when the api server is running.
Prometheus metrics are exposed for all api endpoints automatically at the standard `/metrics` endpoint. (`http://localhost:8080/metrics`)
## Swagger API documentation
Automatic API docs are generated and exposed for all routes at `http://localhost:8080/swagger/index.html` when the api server is running.
## Logging
## Logging
Structured logging is built into all API routes automatically.
So for example here is a what a few API hits on queryService look like in the logs when using text (as opposed to json)
So for example here is a what a few API hits on queryAPI look like in the logs when using text (as opposed to json)
```bash
____ __
@@ -29,4 +32,4 @@ time=2025-02-05T13:38:39.807-08:00 level=INFO msg="HTTP request" method=GET uri=
time=2025-02-05T13:38:39.871-08:00 level=INFO msg="HTTP request" method=GET uri=/swagger/doc.json status=200 latency=1.163167ms error=<nil> remote_ip=::1
time=2025-02-05T13:38:39.871-08:00 level=INFO msg="HTTP request" method=GET uri=/swagger/favicon-32x32.png status=200 latency=60.875µs error=<nil> remote_ip=::1
```
```