Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions api/swagger/swagger-v1.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion api/v1_coin.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
14 changes: 13 additions & 1 deletion api/v1_coins.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down Expand Up @@ -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,
Expand All @@ -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
Expand All @@ -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
Expand Down
2 changes: 2 additions & 0 deletions ddl/migrations/0157_artist_coin_names.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
ALTER TABLE artist_coins
ADD COLUMN name TEXT NOT NULL DEFAULT '';
3 changes: 2 additions & 1 deletion sql/01_schema.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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
);


Expand Down
Loading