Skip to content

Commit 6cea259

Browse files
authored
feat(indexer): add sorting by ending time (#1072)
* feat(indexer): add sorting by ending time * typos
1 parent b6f1068 commit 6cea259

File tree

4 files changed

+62
-2
lines changed

4 files changed

+62
-2
lines changed

.typos.toml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,12 @@ extend-ignore-identifiers-re = [
99
"^[a-zA-Z0-9_]{47}$",
1010
"^[a-zA-Z0-9_]{49}$",
1111
"^[a-zA-Z0-9_]{56,}$",
12-
"^packageid$",
1312
]
1413

14+
[default.extend-words]
15+
packageid = "packageid"
16+
pont = "pont"
17+
1518
[files]
1619
extend-exclude = [
1720
"scripts/init/labels-to-block.txt",

indexer/README.md

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,3 +84,48 @@ Returns all names that a specific address has bid on.
8484
```bash
8585
curl http://localhost:3030/auctions/0x111111111504e9350e635d65cd38ccd2c029434c6a3a480d8947a9ba6a15b215
8686
```
87+
88+
### Get Auctions
89+
90+
```
91+
GET /auctions
92+
```
93+
94+
Returns a paginated list of all auctions, with optional filtering and sorting.
95+
96+
**Parameters:**
97+
98+
- `page` (optional): Page number (0-based, default: 0)
99+
- `pageSize` (optional): Number of items per page (default: 50, max: 100)
100+
- `sort` (optional): Sort order (`asc` or `desc`, default: `asc`)
101+
- `sortBy` (optional): Sort field (`name`, `bid`, or `ending`, default: `name`)
102+
- `search` (optional): Search term to filter names
103+
- `status` (optional): Filter by auction status (`active`, `finished`, or `claimed`)
104+
105+
**Response:**
106+
107+
```json
108+
{
109+
"names": [
110+
"thoralf.iota",
111+
"branmuffins.iota",
112+
"brah.iota",
113+
"114514.iota",
114+
"pont.iota",
115+
"ulim1408.iota",
116+
"space.iota",
117+
"cards.iota",
118+
"iot.iota",
119+
"dex.iota"
120+
],
121+
"page": 0,
122+
"pageSize": 10,
123+
"totalItems": 391
124+
}
125+
```
126+
127+
**Example with sorting by ending time:**
128+
129+
```bash
130+
curl http://localhost:3030/auctions?sortBy=ending&sort=asc&pageSize=10
131+
```

indexer/src/db/mod.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ pub enum AuctionSortBy {
3131
#[default]
3232
Name,
3333
Bid,
34+
Ending,
3435
}
3536

3637
impl std::str::FromStr for AuctionSortBy {
@@ -40,8 +41,9 @@ impl std::str::FromStr for AuctionSortBy {
4041
Ok(match s {
4142
"name" => AuctionSortBy::Name,
4243
"bid" => AuctionSortBy::Bid,
44+
"ending" => AuctionSortBy::Ending,
4345
_ => Err(anyhow::anyhow!(
44-
"Invalid sort by descriptor. Expected `name` or `bid`, found `{s}`"
46+
"Invalid sort by descriptor. Expected `name`, `bid`, or `ending`, found `{s}`"
4547
))?,
4648
})
4749
}

indexer/src/db/queries.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,16 @@ pub fn get_auctions(
206206
(SortOrder::Desc, AuctionSortBy::Bid) => {
207207
query.order((dsl::max(bids::bid).desc(), names::id.desc()))
208208
}
209+
(SortOrder::Asc, AuctionSortBy::Ending) => query.order((
210+
// Put already ended auctions at the end when sorting ascending
211+
auctions::expiration_timestamp
212+
.gt(now.timestamp_millis())
213+
.desc(),
214+
auctions::expiration_timestamp.asc(),
215+
)),
216+
(SortOrder::Desc, AuctionSortBy::Ending) => {
217+
query.order(auctions::expiration_timestamp.desc())
218+
}
209219
};
210220
Ok(query
211221
.load::<(Name, Option<i64>)>(conn)?

0 commit comments

Comments
 (0)