Skip to content

Commit

Permalink
UI: added some documentation to exported funcs. Max limit for search …
Browse files Browse the repository at this point in the history
…documents is set to 1000
  • Loading branch information
matskramer committed Dec 20, 2024
1 parent 8569c1a commit 1e7c6b9
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 8 deletions.
3 changes: 3 additions & 0 deletions internal/apigw/apiv1/handlers_datastore.go
Original file line number Diff line number Diff line change
Expand Up @@ -480,6 +480,7 @@ func (c *Client) RevokeDocument(ctx context.Context, req *RevokeDocumentRequest)
return nil
}

// SearchDocumentsRequest the request to search for documents
type SearchDocumentsRequest struct {
AuthenticSource string `json:"authentic_source,omitempty"`
DocumentType string `json:"document_type,omitempty"`
Expand All @@ -496,11 +497,13 @@ type SearchDocumentsRequest struct {
SortFields map[string]int `json:"sort_fields,omitempty"`
}

// SearchDocumentsReply the reply from search documents
type SearchDocumentsReply struct {
Documents []*model.CompleteDocument `json:"documents"`
HasMoreResults bool `json:"has_more_results"`
}

// SearchDocuments search for documents
func (c *Client) SearchDocuments(ctx context.Context, req *SearchDocumentsRequest) (*SearchDocumentsReply, error) {
docs, hasMore, err := c.db.VCDatastoreColl.SearchDocuments(ctx, &db.SearchDocumentsQuery{
AuthenticSource: req.AuthenticSource,
Expand Down
23 changes: 16 additions & 7 deletions internal/apigw/db/methods_vc_datastore.go
Original file line number Diff line number Diff line change
Expand Up @@ -359,18 +359,24 @@ func (c *VCDatastoreColl) Replace(ctx context.Context, doc *model.CompleteDocume
return nil
}

// SearchDocumentsQuery the query to search for documents
type SearchDocumentsQuery struct {
AuthenticSource string `json:"authentic_source,omitempty"`
DocumentType string `json:"document_type,omitempty"`
DocumentID string `json:"document_id,omitempty"`
CollectID string `json:"collect_id,omitempty"`
AuthenticSource string `json:"authentic_source,omitempty" validate:"omitempty,max=1000"`
DocumentType string `json:"document_type,omitempty" validate:"omitempty,max=1000"`
DocumentID string `json:"document_id,omitempty" validate:"omitempty,max=1000"`
CollectID string `json:"collect_id,omitempty" validate:"omitempty,max=1000"`

AuthenticSourcePersonID string `json:"authentic_source_person_id,omitempty"`
FamilyName string `json:"family_name,omitempty"`
GivenName string `json:"given_name,omitempty"`
BirthDate string `json:"birth_date,omitempty"`
FamilyName string `json:"family_name,omitempty" validate:"omitempty,max=597"`
GivenName string `json:"given_name,omitempty" validate:"omitempty,max=1019"`
BirthDate string `json:"birth_date,omitempty" validate:"omitempty,datetime=2006-01-02"`
}

// SearchDocuments search documents in datastore
//
// @return return matching documents, has more results (refine query), or error
// @Description not supported in production mode
// @Deprecated
func (c *VCDatastoreColl) SearchDocuments(ctx context.Context, query *SearchDocumentsQuery, limit int64, fields []string, sortFields map[string]int) ([]*model.CompleteDocument, bool, error) {
if c.Service.cfg.Common.Production {
return nil, false, errors.New("Not supported in production mode")
Expand All @@ -384,8 +390,11 @@ func (c *VCDatastoreColl) SearchDocuments(ctx context.Context, query *SearchDocu
filter := buildSearchDocumentsFilter(query)

findOptions := options.Find()
const maxLimit = 500
if limit == 0 {
limit = 50
} else if limit > maxLimit {
limit = maxLimit
}
// Set one more than wanted to see if there are more results i db
findOptions.SetLimit(limit + 1)
Expand Down
1 change: 1 addition & 0 deletions internal/portal/apiv1/apigw_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ func NewAPIGWClient(cfg *model.Cfg, tracer *trace.Tracer, logger *logger.Log) *A
}
}

// SearchDocuments sends POST to /api/v1/document/search
func (c *APIGWClient) SearchDocuments(req *apiv1_apigw.SearchDocumentsRequest) (*apiv1_apigw.SearchDocumentsReply, error) {
reply, err := DoPostJSONGeneric[apiv1_apigw.SearchDocumentsReply](c.VCBaseClient, "/api/v1/document/search", req)
if err != nil {
Expand Down
1 change: 1 addition & 0 deletions internal/portal/apiv1/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ func (c *Client) Status(ctx context.Context, req *apiv1_status.StatusRequest) (*
return status, nil
}

// SearchDocuments search for documents
func (c *Client) SearchDocuments(ctx context.Context, req *apiv1_apigw.SearchDocumentsRequest) (*apiv1_apigw.SearchDocumentsReply, error) {
reply, err := c.apigwClient.SearchDocuments(req)
if err != nil {
Expand Down
2 changes: 2 additions & 0 deletions internal/ui/apiv1/apigw_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ func (c *APIGWClient) Notification(req *NotificationRequest) (any, error) {
return reply, nil
}

// SearchDocuments sends POST to /api/v1/document/search
func (c *APIGWClient) SearchDocuments(req *apiv1_apigw.SearchDocumentsRequest) (*apiv1_apigw.SearchDocumentsReply, error) {
reply, err := DoPostJSONGeneric[apiv1_apigw.SearchDocumentsReply](c.VCBaseClient, "/api/v1/document/search", req)
if err != nil {
Expand All @@ -81,6 +82,7 @@ func (c *APIGWClient) SearchDocuments(req *apiv1_apigw.SearchDocumentsRequest) (
return reply, nil
}

// DeleteDocument sends DELETE to /api/v1/document
func (c *APIGWClient) DeleteDocument(req *apiv1_apigw.DeleteDocumentRequest) error {
err := c.DoDelete("/api/v1/document", req)
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion internal/ui/static/ui.js
Original file line number Diff line number Diff line change
Expand Up @@ -1104,7 +1104,7 @@ const addSearchDocumentsFormArticleToContainer = () => {
input: checkboxShowCompleteDocsAsRawJson
} = createCheckboxElement("Show complete documents as raw json");

const limitInput = createInputElement('Max number of results (optional, default is 50)', '50');
const limitInput = createInputElement('Max number of results (optional, default is 50, max is 500)', '50');

const divResultContainer = document.createElement("div");
divResultContainer.id = generateUUID();
Expand Down

0 comments on commit 1e7c6b9

Please sign in to comment.