Skip to content

Commit

Permalink
Merge branch 'main' into feat-remove-old-api
Browse files Browse the repository at this point in the history
  • Loading branch information
pawellewandowski98 committed Jan 22, 2025
2 parents f8eaed3 + d4c9702 commit 16c18a5
Show file tree
Hide file tree
Showing 90 changed files with 3,754 additions and 1,500 deletions.
11 changes: 6 additions & 5 deletions actions/admin/access_keys.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,14 @@ import (
// accessKeysSearch will fetch a list of access keys filtered by metadata
// Access Keys Search godoc
// @Summary Access Keys Search
// @Description Access Keys Search
// @Description Fetches a list of access keys filtered by metadata, creation range, and other parameters.
// @Tags Admin
// @Produce json
// @Param SearchAccessKeys body filter.AdminSearchAccessKeys 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.AccessKey "List of access keys"
// @Failure 400 "Bad request - Error while parsing SearchAccessKeys from request body"
// @Failure 500 "Internal server error - Error while searching for access keys"
// @Param SwaggerCommonParams query swagger.CommonFilteringQueryParams false "Supports options for pagination and sorting to streamline data exploration and analysis"
// @Param AdminAccessKeyFilter query filter.AdminAccessKeyFilter false "Supports targeted resource searches with filters"
// @Success 200 {object} response.PageModel[response.AccessKey] "List of access keys with pagination details"
// @Failure 400 "Bad request - Invalid query parameters"
// @Failure 500 "Internal server error - Error while searching for access keys"
// @Router /api/v1/admin/users/keys [get]
// @Security x-auth-xpub
func accessKeysSearch(c *gin.Context, _ *reqctx.AdminContext) {
Expand Down
11 changes: 6 additions & 5 deletions actions/admin/contact.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,14 @@ import (
// 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
// @Description Fetches a list of contacts filtered by metadata and other criteria
// @Tags Admin
// @Produce json
// @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 AdminSearchContacts from request body"
// @Failure 500 "Internal server error - Error while searching for contacts"
// @Param SwaggerCommonParams query swagger.CommonFilteringQueryParams false "Supports options for pagination and sorting to streamline data exploration and analysis"
// @Param AdminContactFilter query filter.AdminContactFilter false "Supports targeted resource searches with filters"
// @Success 200 {object} response.PageModel[response.Contact] "List of contacts with pagination details"
// @Failure 400 "Bad request - Invalid query parameters"
// @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) {
Expand Down
17 changes: 0 additions & 17 deletions actions/admin/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,10 @@ package admin

import (
"fmt"
"net/http"

"github.com/bitcoin-sv/spv-wallet/actions/common"
"github.com/bitcoin-sv/spv-wallet/engine"
"github.com/bitcoin-sv/spv-wallet/engine/datastore"
"github.com/bitcoin-sv/spv-wallet/mappings"
"github.com/bitcoin-sv/spv-wallet/models/filter"
"github.com/bitcoin-sv/spv-wallet/models/response"
"github.com/bitcoin-sv/spv-wallet/server/reqctx"
"github.com/gin-gonic/gin"
)
Expand Down Expand Up @@ -57,16 +53,3 @@ func countTransactions(c *gin.Context, params *transactionQueryParams) (int64, e
}
return count, nil
}

// Helper function to map transactions and send the response
// sendPaginatedResponse sends a paginated response with any content type.
func sendPaginatedResponse[T any, U any](c *gin.Context, content []*T, pageOptions *datastore.QueryParams, count int64, mapToContractFunc func(*T) *U) {
contracts := common.MapToTypeContracts(content, mapToContractFunc)

result := response.PageModel[U]{
Content: contracts,
Page: common.GetPageDescriptionFromSearchParams(pageOptions, count),
}

c.JSON(http.StatusOK, result)
}
36 changes: 14 additions & 22 deletions actions/admin/paymail_addresses.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@ import (
// paymailGetAddress will return a paymail address
// Get Paymail godoc
// @Summary Get paymail
// @Description Get paymail
// @Description Fetches a paymail address by its ID
// @Tags Admin
// @Produce json
// @Param PaymailAddress body PaymailAddress false "PaymailAddress model containing paymail address to get"
// @Success 200 {object} response.PaymailAddress "PaymailAddress with given address"
// @Failure 400 "Bad request - Error while parsing PaymailAddress from request body"
// @Failure 500 "Internal Server Error - Error while getting paymail address"
// @Param id path string true "Paymail ID"
// @Success 200 {object} response.PaymailAddress "PaymailAddress with the given ID"
// @Failure 400 "Bad request - Invalid ID"
// @Failure 500 "Internal Server Error - Error while retrieving the paymail address"
// @Router /api/v1/admin/paymails/{id} [get]
// @Security x-auth-xpub
func paymailGetAddress(c *gin.Context, _ *reqctx.AdminContext) {
Expand All @@ -49,13 +49,14 @@ func paymailGetAddress(c *gin.Context, _ *reqctx.AdminContext) {
// paymailAddressesSearch will fetch a list of paymail addresses filtered by metadata
// Paymail addresses search by metadata godoc
// @Summary Paymail addresses search
// @Description Paymail addresses search
// @Description Fetches a list of paymail addresses filtered by metadata and other query parameters
// @Tags Admin
// @Produce json
// @Param SearchPaymails body filter.AdminPaymailFilter 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.PaymailAddress "List of paymail addresses
// @Failure 400 "Bad request - Error while parsing SearchPaymails from request body"
// @Failure 500 "Internal server error - Error while searching for paymail addresses"
// @Param SwaggerCommonParams query swagger.CommonFilteringQueryParams false "Supports options for pagination and sorting to streamline data exploration and analysis"
// @Param AdminPaymailFilter query filter.AdminPaymailFilter false "Supports targeted resource searches with filters"
// @Success 200 {object} response.PageModel[response.PaymailAddress] "List of paymail addresses with pagination"
// @Failure 400 "Bad request - Invalid query parameters"
// @Failure 500 "Internal server error - Error while searching for paymail addresses"
// @Router /api/v1/admin/paymails [get]
// @Security x-auth-xpub
func paymailAddressesSearch(c *gin.Context, _ *reqctx.AdminContext) {
Expand Down Expand Up @@ -160,7 +161,7 @@ func paymailCreateAddress(c *gin.Context, _ *reqctx.AdminContext) {
// @Description Delete paymail
// @Tags Admin
// @Produce json
// @Param PaymailAddress body PaymailAddress false "PaymailAddress model containing paymail address to delete"
// @Param id path string true "id of the paymail"
// @Success 200
// @Failure 400 "Bad request - Error while parsing PaymailAddress from request body or if address is missing"
// @Failure 500 "Internal Server Error - Error while deleting paymail address"
Expand All @@ -169,21 +170,12 @@ func paymailCreateAddress(c *gin.Context, _ *reqctx.AdminContext) {
func paymailDeleteAddress(c *gin.Context, _ *reqctx.AdminContext) {
logger := reqctx.Logger(c)
engine := reqctx.Engine(c)
var requestBody PaymailAddress
if err := c.ShouldBindJSON(&requestBody); err != nil {
spverrors.ErrorResponse(c, spverrors.ErrCannotBindRequest.WithTrace(err), logger)
return
}

if requestBody.Address == "" {
spverrors.ErrorResponse(c, spverrors.ErrMissingAddress, logger)
return
}
id := c.Param("id")

opts := engine.DefaultModelOptions()

// Delete a new paymail address
err := engine.DeletePaymailAddress(c.Request.Context(), requestBody.Address, opts...)
err := engine.DeletePaymailAddressByID(c.Request.Context(), id, opts...)
if err != nil {
spverrors.ErrorResponse(c, spverrors.ErrDeletePaymailAddress.WithTrace(err), logger)
return
Expand Down
6 changes: 0 additions & 6 deletions actions/admin/paymail_addresses_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -197,9 +197,6 @@ func TestPaymailLivecycle(t *testing.T) {

// when:
res, _ := client.R().
SetBody(map[string]any{
"address": newPaymail,
}).
Delete("/api/v1/admin/paymails/" + testState.newPaymailID)

// then:
Expand All @@ -217,9 +214,6 @@ func TestPaymailLivecycle(t *testing.T) {

// when:
res, _ := client.R().
SetBody(map[string]any{
"address": newPaymail,
}).
Delete("/api/v1/admin/paymails/" + testState.newPaymailID)

// then:
Expand Down
24 changes: 16 additions & 8 deletions actions/admin/transactions.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@ package admin
import (
"net/http"

"github.com/bitcoin-sv/spv-wallet/actions/common"
"github.com/bitcoin-sv/spv-wallet/engine/spverrors"
"github.com/bitcoin-sv/spv-wallet/internal/query"
"github.com/bitcoin-sv/spv-wallet/mappings"
"github.com/bitcoin-sv/spv-wallet/models/filter"
"github.com/bitcoin-sv/spv-wallet/models/response"
"github.com/bitcoin-sv/spv-wallet/server/reqctx"
"github.com/gin-gonic/gin"
)
Expand Down Expand Up @@ -43,15 +45,14 @@ func adminGetTxByID(c *gin.Context, _ *reqctx.AdminContext) {
// adminSearchTxs will fetch a list of transactions filtered by metadata
// Search for transactions filtering by metadata godoc
// @Summary Search for transactions
// @Description Search for transactions
// @Description Fetches a list of transactions filtered by metadata and other criteria
// @Tags Admin
// @Produce json
// @Param metadata query string false "Filter by metadata in the form of key-value pairs"
// @Param conditions query string false "Additional conditions for filtering, in URL-encoded JSON"
// @Param queryParams query string false "Pagination and sorting options"
// @Success 200 {object} []response.Transaction "List of transactions"
// @Failure 400 "Bad request - Error while parsing query parameters"
// @Failure 500 "Internal server error - Error while searching for transactions"
// @Param SwaggerCommonParams query swagger.CommonFilteringQueryParams false "Supports options for pagination and sorting to streamline data exploration and analysis"
// @Param AdminTransactionFilter query filter.AdminTransactionFilter false "Supports targeted resource searches with filters"
// @Success 200 {object} response.PageModel[response.Transaction] "List of transactions with pagination details"
// @Failure 400 "Bad request - Invalid query parameters"
// @Failure 500 "Internal server error - Error while searching for transactions"
// @Router /api/v1/admin/transactions [get]
// @Security x-auth-xpub
func adminSearchTxs(c *gin.Context, _ *reqctx.AdminContext) {
Expand All @@ -77,5 +78,12 @@ func adminSearchTxs(c *gin.Context, _ *reqctx.AdminContext) {
return
}

sendPaginatedResponse(c, transactions, queryParams.PageOptions, count, mappings.MapToTransactionContractForAdmin)
transactionContracts := common.MapToTypeContracts(transactions, mappings.MapToTransactionContractForAdmin)

result := response.PageModel[response.Transaction]{
Content: transactionContracts,
Page: common.GetPageDescriptionFromSearchParams(queryParams.PageOptions, count),
}

c.JSON(http.StatusOK, result)
}
11 changes: 6 additions & 5 deletions actions/admin/utxos.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,14 @@ import (
// utxosSearch will fetch a list of utxos filtered by metadata
// Search for utxos filtering by metadata godoc
// @Summary Search for utxos
// @Description Search for utxos
// @Description Fetches a list of UTXOs filtered by metadata and other criteria
// @Tags Admin
// @Produce json
// @Param SearchUtxos body filter.AdminUtxoFilter 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.Utxo "List of utxos"
// @Failure 400 "Bad request - Error while parsing SearchUtxos from request body"
// @Failure 500 "Internal server error - Error while searching for utxos"
// @Param SwaggerCommonParams query swagger.CommonFilteringQueryParams false "Supports options for pagination and sorting to streamline data exploration and analysis"
// @Param AdminUtxoFilter query filter.AdminUtxoFilter false "Supports targeted resource searches with filters"
// @Success 200 {object} response.PageModel[response.Utxo] "List of UTXOs with pagination details"
// @Failure 400 "Bad request - Invalid query parameters"
// @Failure 500 "Internal server error - Error while searching for UTXOs"
// @Router /api/v1/admin/utxos [get]
// @Security x-auth-xpub
func utxosSearch(c *gin.Context, _ *reqctx.AdminContext) {
Expand Down
11 changes: 6 additions & 5 deletions actions/admin/xpubs.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,14 @@ func xpubsCreate(c *gin.Context, _ *reqctx.AdminContext) {
// xpubsSearch will fetch a list of xpubs filtered by metadata
// Search for xpubs filtering by metadata godoc
// @Summary Search for xpubs
// @Description Search for xpubs
// @Description Fetches a list of xpubs filtered by metadata and other criteria
// @Tags Admin
// @Produce json
// @Param SearchXpubs body filter.XpubFilter 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.Xpub "List of xpubs"
// @Failure 400 "Bad request - Error while parsing SearchXpubs from request body"
// @Failure 500 "Internal server error - Error while searching for xpubs"
// @Param SwaggerCommonParams query swagger.CommonFilteringQueryParams false "Supports options for pagination and sorting to streamline data exploration and analysis"
// @Param XpubFilter query filter.XpubFilter false "Supports targeted resource searches with filters"
// @Success 200 {object} response.PageModel[response.Xpub] "List of xPubs with pagination details"
// @Failure 400 "Bad request - Invalid query parameters"
// @Failure 500 "Internal server error - Error while searching for xPubs"
// @Router /api/v1/admin/users [get]
// @Security x-auth-xpub
func xpubsSearch(c *gin.Context, _ *reqctx.AdminContext) {
Expand Down
2 changes: 2 additions & 0 deletions actions/base/routes.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"net/http"

"github.com/bitcoin-sv/spv-wallet/config"
"github.com/bitcoin-sv/spv-wallet/docs"
"github.com/bitcoin-sv/spv-wallet/server/handlers"
"github.com/gin-gonic/gin"
swaggerfiles "github.com/swaggo/files"
Expand All @@ -22,6 +23,7 @@ func RegisterRoutes(handlersManager *handlers.Manager) {
healthGroup.OPTIONS("", statusOK)
healthGroup.HEAD("", statusOK)

docs.SwaggerInfo.Version = handlersManager.APIVersion()
root.GET("/swagger", func(c *gin.Context) {
c.Redirect(http.StatusMovedPermanently, "/swagger/index.html")
})
Expand Down
Loading

0 comments on commit 16c18a5

Please sign in to comment.