Skip to content

Commit db1c63c

Browse files
feat: Add sort by id to all somple apis and Add status to node simple response
1 parent 8b24892 commit db1c63c

File tree

8 files changed

+14
-3
lines changed

8 files changed

+14
-3
lines changed

app/db/crud/admin.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ async def load_admin_attrs(admin: Admin):
4141
AdminsSortingOptionsSimple = Enum(
4242
"AdminsSortingOptionsSimple",
4343
{
44+
"id": Admin.id.asc(),
45+
"-id": Admin.id.desc(),
4446
"username": Admin.username.asc(),
4547
"-username": Admin.username.desc(),
4648
},

app/db/crud/core.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
CoreSortingOptionsSimple = Enum(
1111
"CoreSortingOptionsSimple",
1212
{
13+
"id": CoreConfig.id.asc(),
14+
"-id": CoreConfig.id.desc(),
1315
"name": CoreConfig.name.asc(),
1416
"-name": CoreConfig.name.desc(),
1517
},

app/db/crud/group.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
GroupsSortingOptionsSimple = Enum(
1212
"GroupsSortingOptionsSimple",
1313
{
14+
"id": Group.id.asc(),
15+
"-id": Group.id.desc(),
1416
"name": Group.name.asc(),
1517
"-name": Group.name.desc(),
1618
},

app/db/crud/node.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@
3434
NodeSortingOptionsSimple = Enum(
3535
"NodeSortingOptionsSimple",
3636
{
37+
"id": Node.id.asc(),
38+
"-id": Node.id.desc(),
3739
"name": Node.name.asc(),
3840
"-name": Node.name.desc(),
3941
},
@@ -171,7 +173,7 @@ async def get_nodes_simple(
171173
Returns:
172174
Tuple of (list of (id, name) tuples, total_count).
173175
"""
174-
stmt = select(Node.id, Node.name)
176+
stmt = select(Node.id, Node.name, Node.status)
175177

176178
if search:
177179
search_value = search.strip()

app/db/crud/user.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,8 @@ async def get_existing_usernames(db: AsyncSession, usernames: Sequence[str]) ->
136136
UsersSortingOptionsSimple = Enum(
137137
"UsersSortingOptionsSimple",
138138
{
139+
"id": User.id.asc(),
140+
"-id": User.id.desc(),
139141
"username": User.username.asc(),
140142
"-username": User.username.desc(),
141143
},

app/models/node.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,7 @@ class NodeSimple(BaseModel):
217217

218218
id: int
219219
name: str
220+
status: NodeStatus
220221
model_config = ConfigDict(from_attributes=True)
221222

222223

app/operation/node.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ async def get_nodes_simple(
143143
skip_pagination=all,
144144
)
145145

146-
nodes = [NodeSimple(id=row[0], name=row[1]) for row in rows]
146+
nodes = [NodeSimple(id=row[0], name=row[1], status=row[2]) for row in rows]
147147

148148
return NodesSimpleResponse(nodes=nodes, total=total)
149149

tests/api/test_node.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -427,7 +427,7 @@ async def test_get_nodes_simple_basic(access_token):
427427
assert "total" in data
428428

429429
for node in data["nodes"]:
430-
assert set(node.keys()) == {"id", "name"}
430+
assert set(node.keys()) == {"id", "name", "status"}
431431

432432
response_names = [n["name"] for n in data["nodes"]]
433433
for name in names:

0 commit comments

Comments
 (0)