Skip to content

Commit

Permalink
Merge pull request #1303 from consolelabs/fix/update-get-vaults-api
Browse files Browse the repository at this point in the history
fix: update get vaults API
  • Loading branch information
anhnh12 authored Jan 4, 2024
2 parents d496e8b + 1ec71cd commit 1cdfd2b
Show file tree
Hide file tree
Showing 8 changed files with 37 additions and 51 deletions.
17 changes: 2 additions & 15 deletions docs/docs.go
Original file line number Diff line number Diff line change
Expand Up @@ -5999,21 +5999,11 @@ const docTemplate = `{
"name": "coin_gecko_id",
"in": "query"
},
{
"type": "integer",
"name": "page",
"in": "query"
},
{
"type": "string",
"name": "profileID",
"in": "query"
},
{
"type": "integer",
"name": "size",
"in": "query"
},
{
"type": "string",
"description": "profile ID",
Expand Down Expand Up @@ -6308,12 +6298,12 @@ const docTemplate = `{
{
"type": "string",
"default": "false",
"name": "noFetchAmount",
"name": "no_fetch_amount",
"in": "query"
},
{
"type": "string",
"name": "vaultId",
"name": "vault_id",
"in": "query"
}
],
Expand Down Expand Up @@ -11295,9 +11285,6 @@ const docTemplate = `{
"items": {
"$ref": "#/definitions/response.CoinMarketItemData"
}
},
"metadata": {
"$ref": "#/definitions/response.PaginationResponse"
}
}
},
Expand Down
17 changes: 2 additions & 15 deletions docs/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -5991,21 +5991,11 @@
"name": "coin_gecko_id",
"in": "query"
},
{
"type": "integer",
"name": "page",
"in": "query"
},
{
"type": "string",
"name": "profileID",
"in": "query"
},
{
"type": "integer",
"name": "size",
"in": "query"
},
{
"type": "string",
"description": "profile ID",
Expand Down Expand Up @@ -6300,12 +6290,12 @@
{
"type": "string",
"default": "false",
"name": "noFetchAmount",
"name": "no_fetch_amount",
"in": "query"
},
{
"type": "string",
"name": "vaultId",
"name": "vault_id",
"in": "query"
}
],
Expand Down Expand Up @@ -11287,9 +11277,6 @@
"items": {
"$ref": "#/definitions/response.CoinMarketItemData"
}
},
"metadata": {
"$ref": "#/definitions/response.PaginationResponse"
}
}
},
Expand Down
16 changes: 4 additions & 12 deletions docs/swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3032,14 +3032,14 @@ definitions:
type: string
usd:
type: number
usd_14d_change:
type: number
usd_1h_change:
type: number
usd_1y_change:
type: number
usd_7d_change:
type: number
usd_14d_change:
type: number
usd_24h_change:
type: number
usd_24h_vol:
Expand Down Expand Up @@ -3125,8 +3125,6 @@ definitions:
items:
$ref: '#/definitions/response.CoinMarketItemData'
type: array
metadata:
$ref: '#/definitions/response.PaginationResponse'
type: object
response.GetWelcomeChannelConfigResponse:
properties:
Expand Down Expand Up @@ -8253,15 +8251,9 @@ paths:
- in: query
name: coin_gecko_id
type: string
- in: query
name: page
type: integer
- in: query
name: profileID
type: string
- in: query
name: size
type: integer
- description: profile ID
in: path
name: id
Expand Down Expand Up @@ -8562,10 +8554,10 @@ paths:
parameters:
- default: "false"
in: query
name: noFetchAmount
name: no_fetch_amount
type: string
- in: query
name: vaultId
name: vault_id
type: string
produces:
- application/json
Expand Down
1 change: 1 addition & 0 deletions pkg/entities/vault.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ func (e *Entity) GetVaults(req request.GetVaultsRequest) ([]model.Vault, error)
SolanaWallet: req.SolanaAddress,
Threshold: req.Threshold,
UserProfileID: req.ProfileID,
VaultIDs: req.VaultIDs,
}

// query db
Expand Down
15 changes: 14 additions & 1 deletion pkg/handler/vault/vault.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package vault

import (
"errors"
"net/http"
"strconv"
"strings"
Expand Down Expand Up @@ -71,10 +72,22 @@ func (h *Handler) GetVaults(c *gin.Context) {
var req request.GetVaultsRequest
if err := c.BindQuery(&req); err != nil {
h.log.Error(err, "[handler.GetVaults] BindQuery() failed")
c.JSON(http.StatusBadRequest, response.CreateResponse[any](nil, nil, nil, nil))
c.JSON(http.StatusBadRequest, response.CreateResponse[any](nil, nil, err, nil))
return
}

// bind vault IDs
if req.VaultIDsRaw != "" {
req.VaultIDs = strings.Split(req.VaultIDsRaw, ",")
for _, vid := range req.VaultIDs {
if _, err := strconv.Atoi(vid); err != nil {
h.log.Error(err, "[handler.GetVaults] invalid vault_ids")
c.JSON(http.StatusBadRequest, response.CreateResponse[any](nil, nil, errors.New("invalid vault_ids"), nil))
return
}
}
}

vault, err := h.entities.GetVaults(req)
if err != nil {
h.log.Fields(logger.Fields{"req": req}).Error(err, "[handler.GetVaults] entity.GetVaults() failed")
Expand Down
3 changes: 3 additions & 0 deletions pkg/repo/vault/pg.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,5 +59,8 @@ func (pg *pg) List(q ListQuery) (vaults []model.Vault, err error) {
if q.Threshold != "" {
db = db.Where("vaults.threshold = ?", q.Threshold)
}
if len(q.VaultIDs) > 0 {
db = db.Where("vaults.id IN ?", q.VaultIDs)
}
return vaults, db.Preload("VaultTreasurers").Preload("DiscordGuild").Find(&vaults).Error
}
1 change: 1 addition & 0 deletions pkg/repo/vault/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@ type ListQuery struct {
EvmWallet string
SolanaWallet string
Threshold string
VaultIDs []string
}
18 changes: 10 additions & 8 deletions pkg/request/vault.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,15 +100,17 @@ type MochiPayVaultRequest struct {
}

type GetVaultsRequest struct {
GuildID string `form:"guild_id"`
ProfileID string `form:"profile_id"`
EvmAddress string `form:"evm_address"`
SolanaAddress string `form:"solana_address"`
Threshold string `form:"threshold"`
NoFetchAmount string `form:"no_fetch_amount" default:"false"`
GuildID string `json:"guild_id" form:"guild_id"`
ProfileID string `json:"profile_id" form:"profile_id"`
EvmAddress string `json:"evm_addres" form:"evm_address"`
SolanaAddress string `json:"solana_address" form:"solana_address"`
Threshold string `json:"threshold" form:"threshold"`
NoFetchAmount string `json:"no_fetch_amount" form:"no_fetch_amount" default:"false"`
VaultIDsRaw string `json:"vault_ids" form:"vault_ids"`
VaultIDs []string `json:"-" form:"-"`
}

type GetVaultRequest struct {
VaultId string `uri:"vault_id"`
NoFetchAmount string `form:"no_fetch_amount" default:"false"`
VaultId string `json:"vault_id" uri:"vault_id"`
NoFetchAmount string `json:"no_fetch_amount" form:"no_fetch_amount" default:"false"`
}

0 comments on commit 1cdfd2b

Please sign in to comment.