Merged in feature/textextract (pull request #108)
Start adding Textract + UUID changes * base * startclient * ts * short * tests
This commit is contained in:
@@ -9,13 +9,11 @@ import (
|
||||
"regexp"
|
||||
|
||||
docsyncrunner "queryorchestration/api/docSyncRunner"
|
||||
"queryorchestration/internal/database"
|
||||
"queryorchestration/internal/database/repository"
|
||||
"queryorchestration/internal/document"
|
||||
"queryorchestration/internal/serviceconfig/queue"
|
||||
|
||||
"github.com/google/uuid"
|
||||
"github.com/jackc/pgx/v5/pgtype"
|
||||
)
|
||||
|
||||
type Create struct {
|
||||
@@ -52,18 +50,18 @@ func (s *Service) Create(ctx context.Context, doc *Create) (uuid.UUID, error) {
|
||||
}
|
||||
|
||||
type createDocumentParams struct {
|
||||
ID *pgtype.UUID
|
||||
ClientID pgtype.UUID
|
||||
ID *uuid.UUID
|
||||
ClientID uuid.UUID
|
||||
Hash string
|
||||
Location document.Location
|
||||
}
|
||||
|
||||
func (s *Service) getCreateParams(ctx context.Context, doc *Create) (*createDocumentParams, error) {
|
||||
idbyhash, err := s.cfg.GetDBQueries().GetDocumentIDByHash(ctx, &repository.GetDocumentIDByHashParams{
|
||||
Clientid: database.MustToDBUUID(doc.ClientID),
|
||||
Clientid: doc.ClientID,
|
||||
Hash: doc.Hash,
|
||||
})
|
||||
var docID *pgtype.UUID
|
||||
var docID *uuid.UUID
|
||||
if err != nil && !errors.Is(err, sql.ErrNoRows) {
|
||||
return nil, err
|
||||
} else if err == nil {
|
||||
@@ -72,7 +70,7 @@ func (s *Service) getCreateParams(ctx context.Context, doc *Create) (*createDocu
|
||||
|
||||
return &createDocumentParams{
|
||||
ID: docID,
|
||||
ClientID: database.MustToDBUUID(doc.ClientID),
|
||||
ClientID: doc.ClientID,
|
||||
Hash: doc.Hash,
|
||||
Location: doc.Location,
|
||||
}, nil
|
||||
@@ -82,7 +80,7 @@ func (s *Service) submitCreate(ctx context.Context, params *createDocumentParams
|
||||
var id uuid.UUID
|
||||
|
||||
err := s.cfg.ExecuteDBTransaction(ctx, func(ctx context.Context, q *repository.Queries) error {
|
||||
var dbid pgtype.UUID
|
||||
var dbid uuid.UUID
|
||||
if params.ID == nil {
|
||||
createid, err := s.cfg.GetDBQueries().CreateDocument(ctx, &repository.CreateDocumentParams{
|
||||
Clientid: params.ClientID,
|
||||
@@ -109,7 +107,7 @@ func (s *Service) submitCreate(ctx context.Context, params *createDocumentParams
|
||||
return err
|
||||
}
|
||||
|
||||
id = database.MustToUUID(dbid)
|
||||
id = dbid
|
||||
|
||||
return nil
|
||||
})
|
||||
|
||||
@@ -6,7 +6,6 @@ import (
|
||||
"fmt"
|
||||
"testing"
|
||||
|
||||
"queryorchestration/internal/database"
|
||||
"queryorchestration/internal/database/repository"
|
||||
"queryorchestration/internal/document"
|
||||
queuemock "queryorchestration/mocks/queue"
|
||||
@@ -45,30 +44,30 @@ func TestCreate(t *testing.T) {
|
||||
Key: "/i/am/here",
|
||||
}
|
||||
|
||||
pool.ExpectQuery("name: GetDocumentIDByHash :one").WithArgs(doc.Hash, database.MustToDBUUID(doc.ClientID)).WillReturnRows(
|
||||
pool.ExpectQuery("name: GetDocumentIDByHash :one").WithArgs(doc.Hash, doc.ClientID).WillReturnRows(
|
||||
pgxmock.NewRows([]string{"id"}),
|
||||
)
|
||||
pool.ExpectBegin()
|
||||
pool.ExpectQuery("name: CreateDocument :one").WithArgs(database.MustToDBUUID(doc.ClientID), doc.Hash).
|
||||
pool.ExpectQuery("name: CreateDocument :one").WithArgs(doc.ClientID, doc.Hash).
|
||||
WillReturnRows(
|
||||
pgxmock.NewRows([]string{"id"}).
|
||||
AddRow(database.MustToDBUUID(doc.ID)),
|
||||
AddRow(doc.ID),
|
||||
)
|
||||
pool.ExpectExec("name: AddDocumentEntry :exec").WithArgs(database.MustToDBUUID(doc.ID), location.Bucket, location.Key).
|
||||
pool.ExpectExec("name: AddDocumentEntry :exec").WithArgs(doc.ID, location.Bucket, location.Key).
|
||||
WillReturnResult(pgxmock.NewResult("", 1))
|
||||
pool.ExpectCommit()
|
||||
pool.ExpectQuery("name: GetDocumentSummary :one").WithArgs(database.MustToDBUUID(doc.ID)).
|
||||
pool.ExpectQuery("name: GetDocumentSummary :one").WithArgs(doc.ID).
|
||||
WillReturnRows(
|
||||
pgxmock.NewRows([]string{"id", "clientId", "hash"}).
|
||||
AddRow(database.MustToDBUUID(doc.ID), database.MustToDBUUID(doc.ClientID), doc.Hash),
|
||||
AddRow(doc.ID, doc.ClientID, doc.Hash),
|
||||
)
|
||||
pool.ExpectQuery("name: GetClient :one").WithArgs(database.MustToDBUUID(clientId)).WillReturnRows(
|
||||
pool.ExpectQuery("name: GetClient :one").WithArgs(clientId).WillReturnRows(
|
||||
pgxmock.NewRows([]string{"id", "clientId", "canSync"}).
|
||||
AddRow(database.MustToDBUUID(clientId), database.MustToDBUUID(clientId), true),
|
||||
AddRow(clientId, clientId, true),
|
||||
)
|
||||
pool.ExpectQuery("name: GetClient :one").WithArgs(database.MustToDBUUID(clientId)).WillReturnRows(
|
||||
pool.ExpectQuery("name: GetClient :one").WithArgs(clientId).WillReturnRows(
|
||||
pgxmock.NewRows([]string{"id", "name", "canSync"}).
|
||||
AddRow(database.MustToDBUUID(clientId), "client_name", true),
|
||||
AddRow(clientId, "client_name", true),
|
||||
)
|
||||
|
||||
mockSQS.EXPECT().
|
||||
@@ -110,7 +109,7 @@ func TestGetCreateParams(t *testing.T) {
|
||||
Key: "/i/am/here",
|
||||
}
|
||||
|
||||
pool.ExpectQuery("name: GetDocumentIDByHash :one").WithArgs(doc.Hash, database.MustToDBUUID(doc.ClientID)).WillReturnRows(
|
||||
pool.ExpectQuery("name: GetDocumentIDByHash :one").WithArgs(doc.Hash, doc.ClientID).WillReturnRows(
|
||||
pgxmock.NewRows([]string{"id"}),
|
||||
)
|
||||
|
||||
@@ -121,7 +120,7 @@ func TestGetCreateParams(t *testing.T) {
|
||||
})
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, &createDocumentParams{
|
||||
ClientID: database.MustToDBUUID(doc.ClientID),
|
||||
ClientID: doc.ClientID,
|
||||
Hash: doc.Hash,
|
||||
Location: location,
|
||||
}, params)
|
||||
@@ -148,9 +147,9 @@ func TestGetCreateParamsExisting(t *testing.T) {
|
||||
Key: "/i/am/here",
|
||||
}
|
||||
|
||||
pool.ExpectQuery("name: GetDocumentIDByHash :one").WithArgs(doc.Hash, database.MustToDBUUID(doc.ClientID)).WillReturnRows(
|
||||
pool.ExpectQuery("name: GetDocumentIDByHash :one").WithArgs(doc.Hash, doc.ClientID).WillReturnRows(
|
||||
pgxmock.NewRows([]string{"id"}).
|
||||
AddRow(database.MustToDBUUID(doc.ID)),
|
||||
AddRow(doc.ID),
|
||||
)
|
||||
|
||||
params, err := svc.getCreateParams(ctx, &Create{
|
||||
@@ -159,10 +158,10 @@ func TestGetCreateParamsExisting(t *testing.T) {
|
||||
Hash: doc.Hash,
|
||||
})
|
||||
require.NoError(t, err)
|
||||
dbid := database.MustToDBUUID(doc.ID)
|
||||
dbid := doc.ID
|
||||
assert.Equal(t, &createDocumentParams{
|
||||
ID: &dbid,
|
||||
ClientID: database.MustToDBUUID(doc.ClientID),
|
||||
ClientID: doc.ClientID,
|
||||
Hash: doc.Hash,
|
||||
Location: location,
|
||||
}, params)
|
||||
@@ -188,7 +187,7 @@ func TestGetCreateParamsCurrentDocErr(t *testing.T) {
|
||||
Key: "/i/am/here",
|
||||
}
|
||||
|
||||
pool.ExpectQuery("name: GetDocumentIDByHash :one").WithArgs(doc.Hash, database.MustToDBUUID(doc.ClientID)).
|
||||
pool.ExpectQuery("name: GetDocumentIDByHash :one").WithArgs(doc.Hash, doc.ClientID).
|
||||
WillReturnError(errors.New("db err"))
|
||||
|
||||
_, err = svc.getCreateParams(ctx, &Create{
|
||||
@@ -220,17 +219,17 @@ func TestSubmitCreate(t *testing.T) {
|
||||
}
|
||||
|
||||
pool.ExpectBegin()
|
||||
pool.ExpectQuery("name: CreateDocument :one").WithArgs(database.MustToDBUUID(doc.ClientID), doc.Hash).
|
||||
pool.ExpectQuery("name: CreateDocument :one").WithArgs(doc.ClientID, doc.Hash).
|
||||
WillReturnRows(
|
||||
pgxmock.NewRows([]string{"id"}).
|
||||
AddRow(database.MustToDBUUID(doc.ID)),
|
||||
AddRow(doc.ID),
|
||||
)
|
||||
pool.ExpectExec("name: AddDocumentEntry :exec").WithArgs(database.MustToDBUUID(doc.ID), location.Bucket, location.Key).
|
||||
pool.ExpectExec("name: AddDocumentEntry :exec").WithArgs(doc.ID, location.Bucket, location.Key).
|
||||
WillReturnResult(pgxmock.NewResult("", 1))
|
||||
pool.ExpectCommit()
|
||||
|
||||
id, err := svc.submitCreate(ctx, &createDocumentParams{
|
||||
ClientID: database.MustToDBUUID(doc.ClientID),
|
||||
ClientID: doc.ClientID,
|
||||
Location: location,
|
||||
Hash: doc.Hash,
|
||||
})
|
||||
@@ -260,14 +259,14 @@ func TestSubmitCreateExists(t *testing.T) {
|
||||
}
|
||||
|
||||
pool.ExpectBegin()
|
||||
pool.ExpectExec("name: AddDocumentEntry :exec").WithArgs(database.MustToDBUUID(doc.ID), location.Bucket, location.Key).
|
||||
pool.ExpectExec("name: AddDocumentEntry :exec").WithArgs(doc.ID, location.Bucket, location.Key).
|
||||
WillReturnResult(pgxmock.NewResult("", 1))
|
||||
pool.ExpectCommit()
|
||||
|
||||
docid := database.MustToDBUUID(doc.ID)
|
||||
docid := doc.ID
|
||||
id, err := svc.submitCreate(ctx, &createDocumentParams{
|
||||
ID: &docid,
|
||||
ClientID: database.MustToDBUUID(doc.ClientID),
|
||||
ClientID: doc.ClientID,
|
||||
Location: location,
|
||||
Hash: doc.Hash,
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user