diff --git a/api/swagger/swagger-v1.yaml b/api/swagger/swagger-v1.yaml index 57ded4d4..ecc67ee8 100644 --- a/api/swagger/swagger-v1.yaml +++ b/api/swagger/swagger-v1.yaml @@ -3464,6 +3464,11 @@ paths: type: array items: type: string + - name: query + in: query + description: Search by the coin name or ticker + schema: + type: string - name: offset in: query description: The number of items to skip. Useful for pagination (page number @@ -5048,11 +5053,16 @@ components: coin: type: object required: + - name - mint - decimals - owner_id - created_at properties: + name: + type: string + description: The coin name + example: "Bonk Inu" ticker: type: string description: The coin symbol diff --git a/api/v1_coin.go b/api/v1_coin.go index 92d03251..0db2a47d 100644 --- a/api/v1_coin.go +++ b/api/v1_coin.go @@ -14,7 +14,8 @@ func (app *ApiServer) v1Coin(c *fiber.Ctx) error { } sql := ` - SELECT + SELECT + artist_coins.name, artist_coins.ticker, artist_coins.mint, artist_coins.decimals, diff --git a/api/v1_coins.go b/api/v1_coins.go index 01654b57..4c1ee7ef 100644 --- a/api/v1_coins.go +++ b/api/v1_coins.go @@ -14,9 +14,11 @@ type GetArtistCoinsQueryParams struct { OwnerIds []trashid.HashId `query:"owner_id"` Limit int `query:"limit" default:"50" validate:"min=1,max=100"` Offset int `query:"offset" default:"0" validate:"min=0"` + Query string `query:"query"` } type ArtistCoin struct { + Name string `json:"name"` Ticker string `json:"ticker"` Mint string `json:"mint"` Decimals int `json:"decimals"` @@ -45,9 +47,17 @@ func (app *ApiServer) v1Coins(c *fiber.Ctx) error { if len(queryParams.Tickers) > 0 { tickerFilter = `AND artist_coins.ticker = ANY(@tickers)` } + queryFilter := "" + if queryParams.Query != "" { + queryFilter = `AND ( + artist_coins.ticker ILIKE '%' || @query || '%' OR + artist_coins.name ILIKE '%' || @query || '%' + )` + } sql := ` - SELECT + SELECT + artist_coins.name, artist_coins.ticker, artist_coins.mint, artist_coins.decimals, @@ -61,6 +71,7 @@ func (app *ApiServer) v1Coins(c *fiber.Ctx) error { ` + mintFilter + ` ` + ownerIdFilter + ` ` + tickerFilter + ` + ` + queryFilter + ` ORDER BY artist_coins.ticker = '$AUDIO' DESC, artist_coins.created_at ASC @@ -74,6 +85,7 @@ func (app *ApiServer) v1Coins(c *fiber.Ctx) error { "owner_ids": queryParams.OwnerIds, "limit": queryParams.Limit, "offset": queryParams.Offset, + "query": queryParams.Query, }) if err != nil { return err diff --git a/ddl/migrations/0157_artist_coin_names.sql b/ddl/migrations/0157_artist_coin_names.sql new file mode 100644 index 00000000..37ae8864 --- /dev/null +++ b/ddl/migrations/0157_artist_coin_names.sql @@ -0,0 +1,2 @@ +ALTER TABLE artist_coins + ADD COLUMN name TEXT NOT NULL DEFAULT ''; \ No newline at end of file diff --git a/sql/01_schema.sql b/sql/01_schema.sql index d896248f..2791a0a5 100644 --- a/sql/01_schema.sql +++ b/sql/01_schema.sql @@ -5757,7 +5757,8 @@ CREATE TABLE public.artist_coins ( created_at timestamp without time zone DEFAULT CURRENT_TIMESTAMP NOT NULL, logo_uri text, description text, - website text + website text, + name text DEFAULT ''::text NOT NULL );