Skip to content

Commit

Permalink
feat(SPV-1214): add contact filter for admin (#815)
Browse files Browse the repository at this point in the history
  • Loading branch information
jakubmkowalski authored Dec 17, 2024
1 parent 334c8f5 commit c9fe3f6
Show file tree
Hide file tree
Showing 9 changed files with 376 additions and 25 deletions.
10 changes: 5 additions & 5 deletions actions/admin/contact.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,23 +15,23 @@ import (
"github.com/gin-gonic/gin"
)

// contactsSearch will fetch a list of contacts filtered by Metadata and ContactFilters
// Search for contacts filtering by metadata and ContactFilters godoc
// contactsSearch will fetch a list of contacts filtered by Metadata and AdminContactFilters
// Search for contacts filtering by metadata and AdminContactFilters godoc
// @Summary Search for contacts
// @Description Search for contacts
// @Tags Admin
// @Produce json
// @Param SearchContacts body filter.SearchContacts false "Supports targeted resource searches with filters and metadata, plus options for pagination and sorting to streamline data exploration and analysis"
// @Param AdminSearchContacts body filter.AdminContactFilter false "Supports targeted resource searches with filters and metadata, plus options for pagination and sorting to streamline data exploration and analysis"
// @Success 200 {object} response.PageModel[response.Contact] "List of contacts"
// @Failure 400 "Bad request - Error while parsing SearchContacts from request body"
// @Failure 400 "Bad request - Error while parsing AdminSearchContacts from request body"
// @Failure 500 "Internal server error - Error while searching for contacts"
// @Router /api/v1/admin/contacts [get]
// @Security x-auth-xpub
func contactsSearch(c *gin.Context, _ *reqctx.AdminContext) {
logger := reqctx.Logger(c)
engine := reqctx.Engine(c)

searchParams, err := query.ParseSearchParams[filter.ContactFilter](c)
searchParams, err := query.ParseSearchParams[filter.AdminContactFilter](c)
if err != nil {
spverrors.ErrorResponse(c, spverrors.ErrCannotParseQueryParams.WithTrace(err), logger)
return
Expand Down
8 changes: 4 additions & 4 deletions actions/admin/contact_old.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@ import (
"github.com/gin-gonic/gin"
)

// contactsSearchOld will fetch a list of contacts filtered by Metadata and ContactFilters
// Search for contacts filtering by metadata and ContactFilters godoc
// contactsSearchOld will fetch a list of contacts filtered by Metadata and AdminContactFilters
// Search for contacts filtering by metadata and AdminContactFilters godoc
// @DeprecatedRouter /v1/admin/contact/search [post]
// @Summary Search for contacts
// @Description Search for contacts
// @Tags Admin
// @Produce json
// @Param SearchContacts body filter.SearchContacts false "Supports targeted resource searches with filters and metadata, plus options for pagination and sorting to streamline data exploration and analysis"
// @Param AdminSearchContacts body filter.AdminSearchContacts false "Supports targeted resource searches with filters and metadata, plus options for pagination and sorting to streamline data exploration and analysis"
// @Success 200 {object} models.SearchContactsResponse "List of contacts"
// @Failure 400 "Bad request - Error while parsing SearchContacts from request body"
// @Failure 500 "Internal server error - Error while searching for contacts"
Expand All @@ -29,7 +29,7 @@ import (
func contactsSearchOld(c *gin.Context, _ *reqctx.AdminContext) {
logger := reqctx.Logger(c)
engine := reqctx.Engine(c)
var reqParams filter.SearchContacts
var reqParams filter.AdminSearchContacts
if err := c.Bind(&reqParams); err != nil {
spverrors.ErrorResponse(c, spverrors.ErrCannotBindRequest, logger)
return
Expand Down
103 changes: 98 additions & 5 deletions docs/docs.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,10 @@ const docTemplate = `{
"parameters": [
{
"description": "Supports targeted resource searches with filters and metadata, plus options for pagination and sorting to streamline data exploration and analysis",
"name": "SearchContacts",
"name": "AdminSearchContacts",
"in": "body",
"schema": {
"$ref": "#/definitions/filter.SearchContacts"
"$ref": "#/definitions/filter.AdminContactFilter"
}
}
],
Expand All @@ -93,7 +93,7 @@ const docTemplate = `{
}
},
"400": {
"description": "Bad request - Error while parsing SearchContacts from request body"
"description": "Bad request - Error while parsing AdminSearchContacts from request body"
},
"500": {
"description": "Internal server error - Error while searching for contacts"
Expand Down Expand Up @@ -2605,10 +2605,10 @@ const docTemplate = `{
"parameters": [
{
"description": "Supports targeted resource searches with filters and metadata, plus options for pagination and sorting to streamline data exploration and analysis",
"name": "SearchContacts",
"name": "AdminSearchContacts",
"in": "body",
"schema": {
"$ref": "#/definitions/filter.SearchContacts"
"$ref": "#/definitions/filter.AdminSearchContacts"
}
}
],
Expand Down Expand Up @@ -4864,6 +4864,62 @@ const docTemplate = `{
}
}
},
"filter.AdminContactFilter": {
"type": "object",
"properties": {
"createdRange": {
"description": "CreatedRange specifies the time range when a record was created.",
"allOf": [
{
"$ref": "#/definitions/filter.TimeRange"
}
]
},
"fullName": {
"type": "string",
"example": "Alice"
},
"id": {
"type": "string",
"example": "ffdbe74e-0700-4710-aac5-611a1f877c7f"
},
"includeDeleted": {
"description": "IncludeDeleted is a flag whether or not to include deleted items in the search results",
"type": "boolean",
"default": false,
"example": true
},
"paymail": {
"type": "string",
"example": "alice@example.com"
},
"pubKey": {
"type": "string",
"example": "0334f01ecb971e93db179e6fb320cd1466beb0c1ec6c1c6a37aa6cb02e53d5dd1a"
},
"status": {
"type": "string",
"enum": [
"unconfirmed",
"awaiting",
"confirmed",
"rejected"
]
},
"updatedRange": {
"description": "UpdatedRange specifies the time range when a record was updated.",
"allOf": [
{
"$ref": "#/definitions/filter.TimeRange"
}
]
},
"xpubid": {
"type": "string",
"example": "623bc25ce1c0fc510dea72b5ee27b2e70384c099f1f3dce9e73dd987198c3486"
}
}
},
"filter.AdminCountAccessKeys": {
"type": "object",
"properties": {
Expand Down Expand Up @@ -5020,6 +5076,43 @@ const docTemplate = `{
}
}
},
"filter.AdminSearchContacts": {
"type": "object",
"properties": {
"conditions": {
"description": "Custom conditions used for filtering the search results. Every field within the object is optional.",
"allOf": [
{
"$ref": "#/definitions/filter.AdminContactFilter"
}
]
},
"metadata": {
"description": "Accepts a JSON object for embedding custom metadata, enabling arbitrary additional information to be associated with the resource",
"type": "object",
"additionalProperties": {
"type": "string"
},
"example": {
"key": "value",
"key2": "value2"
}
},
"params": {
"description": "Pagination and sorting options to streamline data exploration and analysis",
"type": "object",
"additionalProperties": {
"type": "string"
},
"example": {
"order_by_direction": "desc",
"order_by_field": "created_at",
"page": "1",
"page_size": "10"
}
}
}
},
"filter.AdminSearchPaymails": {
"type": "object",
"properties": {
Expand Down
103 changes: 98 additions & 5 deletions docs/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,10 @@
"parameters": [
{
"description": "Supports targeted resource searches with filters and metadata, plus options for pagination and sorting to streamline data exploration and analysis",
"name": "SearchContacts",
"name": "AdminSearchContacts",
"in": "body",
"schema": {
"$ref": "#/definitions/filter.SearchContacts"
"$ref": "#/definitions/filter.AdminContactFilter"
}
}
],
Expand All @@ -84,7 +84,7 @@
}
},
"400": {
"description": "Bad request - Error while parsing SearchContacts from request body"
"description": "Bad request - Error while parsing AdminSearchContacts from request body"
},
"500": {
"description": "Internal server error - Error while searching for contacts"
Expand Down Expand Up @@ -2596,10 +2596,10 @@
"parameters": [
{
"description": "Supports targeted resource searches with filters and metadata, plus options for pagination and sorting to streamline data exploration and analysis",
"name": "SearchContacts",
"name": "AdminSearchContacts",
"in": "body",
"schema": {
"$ref": "#/definitions/filter.SearchContacts"
"$ref": "#/definitions/filter.AdminSearchContacts"
}
}
],
Expand Down Expand Up @@ -4855,6 +4855,62 @@
}
}
},
"filter.AdminContactFilter": {
"type": "object",
"properties": {
"createdRange": {
"description": "CreatedRange specifies the time range when a record was created.",
"allOf": [
{
"$ref": "#/definitions/filter.TimeRange"
}
]
},
"fullName": {
"type": "string",
"example": "Alice"
},
"id": {
"type": "string",
"example": "ffdbe74e-0700-4710-aac5-611a1f877c7f"
},
"includeDeleted": {
"description": "IncludeDeleted is a flag whether or not to include deleted items in the search results",
"type": "boolean",
"default": false,
"example": true
},
"paymail": {
"type": "string",
"example": "alice@example.com"
},
"pubKey": {
"type": "string",
"example": "0334f01ecb971e93db179e6fb320cd1466beb0c1ec6c1c6a37aa6cb02e53d5dd1a"
},
"status": {
"type": "string",
"enum": [
"unconfirmed",
"awaiting",
"confirmed",
"rejected"
]
},
"updatedRange": {
"description": "UpdatedRange specifies the time range when a record was updated.",
"allOf": [
{
"$ref": "#/definitions/filter.TimeRange"
}
]
},
"xpubid": {
"type": "string",
"example": "623bc25ce1c0fc510dea72b5ee27b2e70384c099f1f3dce9e73dd987198c3486"
}
}
},
"filter.AdminCountAccessKeys": {
"type": "object",
"properties": {
Expand Down Expand Up @@ -5011,6 +5067,43 @@
}
}
},
"filter.AdminSearchContacts": {
"type": "object",
"properties": {
"conditions": {
"description": "Custom conditions used for filtering the search results. Every field within the object is optional.",
"allOf": [
{
"$ref": "#/definitions/filter.AdminContactFilter"
}
]
},
"metadata": {
"description": "Accepts a JSON object for embedding custom metadata, enabling arbitrary additional information to be associated with the resource",
"type": "object",
"additionalProperties": {
"type": "string"
},
"example": {
"key": "value",
"key2": "value2"
}
},
"params": {
"description": "Pagination and sorting options to streamline data exploration and analysis",
"type": "object",
"additionalProperties": {
"type": "string"
},
"example": {
"order_by_direction": "desc",
"order_by_field": "created_at",
"page": "1",
"page_size": "10"
}
}
}
},
"filter.AdminSearchPaymails": {
"type": "object",
"properties": {
Expand Down
Loading

0 comments on commit c9fe3f6

Please sign in to comment.