Skip to content

Commit d11078c

Browse files
author
jehua-tech
committed
Rename endpoints to be more descriptive
1 parent 30a9301 commit d11078c

File tree

3 files changed

+23
-17
lines changed

3 files changed

+23
-17
lines changed

gs/backend/api/v1/aro/endpoints/user.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,29 +3,29 @@
33
from fastapi import APIRouter, HTTPException
44

55
from gs.backend.api.v1.aro.models.requests import UserRequest
6-
from gs.backend.api.v1.aro.models.responses import UserResponse, UsersResponse
6+
from gs.backend.api.v1.aro.models.responses import AllUsersResponse, UserResponse
77
from gs.backend.data.data_wrappers.aro_wrapper.aro_user_data_wrapper import (
88
add_user,
99
delete_user_by_id,
10-
get_all_users,
1110
update_user_by_id,
1211
)
12+
from gs.backend.data.data_wrappers.aro_wrapper.aro_user_data_wrapper import get_all_users as get_all_db_users
1313

1414
aro_user_router = APIRouter(tags=["ARO", "User Information"])
1515

1616

17-
@aro_user_router.get("/", response_model=UsersResponse)
18-
async def get_users() -> UsersResponse:
17+
@aro_user_router.get("/get_all_users", response_model=AllUsersResponse)
18+
async def get_all_users() -> AllUsersResponse:
1919
"""
2020
Gets all users
2121
2222
:return: all users
2323
"""
24-
users = get_all_users()
25-
return UsersResponse(data=users)
24+
users = get_all_db_users()
25+
return AllUsersResponse(data=users)
2626

2727

28-
@aro_user_router.post("/", response_model=UserResponse)
28+
@aro_user_router.post("/create_user", response_model=UserResponse)
2929
def create_user(payload: UserRequest) -> UserResponse:
3030
"""
3131
Creates a user with the given payload
@@ -44,7 +44,7 @@ def create_user(payload: UserRequest) -> UserResponse:
4444
return UserResponse(data=user)
4545

4646

47-
@aro_user_router.put("/{userid}", response_model=UserResponse)
47+
@aro_user_router.put("/update_user/{userid}", response_model=UserResponse)
4848
def update_user(userid: str, payload: UserRequest) -> UserResponse:
4949
"""
5050
Modifies the user’s info based on the payload
@@ -65,15 +65,15 @@ def update_user(userid: str, payload: UserRequest) -> UserResponse:
6565
raise HTTPException(status_code=404, detail=str(e)) from e
6666

6767

68-
@aro_user_router.delete("/{userid}", response_model=UsersResponse)
69-
def delete_user(userid: str) -> UsersResponse:
68+
@aro_user_router.delete("/delete_user/{userid}", response_model=AllUsersResponse)
69+
def delete_user(userid: str) -> AllUsersResponse:
7070
"""
7171
Deletes a user based on the user ID
7272
:param userid: The unique identifier of the user to be deleted
7373
:return: returns the user deleted
7474
"""
7575
try:
7676
users = delete_user_by_id(UUID(userid))
77-
return UsersResponse(data=users)
77+
return AllUsersResponse(data=users)
7878
except ValueError as e:
7979
raise HTTPException(status_code=404, detail=str(e)) from e

gs/backend/api/v1/aro/models/responses.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
from gs.backend.data.tables.aro_user_tables import AROUsers
44

55

6-
class UsersResponse(BaseModel):
6+
class AllUsersResponse(BaseModel):
77
"""
88
The users response model.
99
"""

python_test/test_aro_user_api.py

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,9 @@ def user2_data():
3535
# Test creating user1
3636
@pytest.fixture
3737
def test_user1_creation(client, user1_data):
38-
response = client.post("/api/v1/aro/user/", json=user1_data, headers={"Content-Type": "application/json"})
38+
response = client.post(
39+
"/api/v1/aro/user/create_user", json=user1_data, headers={"Content-Type": "application/json"}
40+
)
3941

4042
assert response.status_code == 200
4143
user = response.json()["data"]
@@ -51,7 +53,9 @@ def test_user1_creation(client, user1_data):
5153
# Test creating user2
5254
@pytest.fixture
5355
def test_user2_creation(client, user2_data):
54-
response = client.post("/api/v1/aro/user/", json=user2_data, headers={"Content-Type": "application/json"})
56+
response = client.post(
57+
"/api/v1/aro/user/create_user", json=user2_data, headers={"Content-Type": "application/json"}
58+
)
5559

5660
assert response.status_code == 200
5761
user = response.json()["data"]
@@ -75,7 +79,9 @@ def test_user1_update(client, test_user1_creation):
7579
"last_name": "Smith",
7680
"phone_number": "234567890",
7781
}
78-
res = client.put(f"/api/v1/aro/user/{user_id}", json=update_data, headers={"Content-Type": "application/json"})
82+
res = client.put(
83+
f"/api/v1/aro/user/update_user/{user_id}", json=update_data, headers={"Content-Type": "application/json"}
84+
)
7985

8086
assert res.status_code == 200
8187
updated_user = res.json()["data"]
@@ -91,7 +97,7 @@ def test_user1_update(client, test_user1_creation):
9197
# Test getting all users (after creating user1 and user2, and updating user1 to ensure creation and update work oncorrect user objects)
9298
@pytest.fixture
9399
def test_get_users(client, test_user1_update, test_user2_creation):
94-
res = client.get("/api/v1/aro/user/")
100+
res = client.get("/api/v1/aro/user/get_all_users")
95101

96102
assert res.status_code == 200
97103
all_users = res.json()["data"]
@@ -119,7 +125,7 @@ def test_get_users(client, test_user1_update, test_user2_creation):
119125
# Test deleting user1 (after test_get_users to ensure both users exist)
120126
def test_user1_deletion(client, test_user1_update, test_user2_creation, test_get_users):
121127
user_id = test_user1_update["id"]
122-
res = client.delete(f"/api/v1/aro/user/{user_id}", headers={"Content-Type": "application/json"})
128+
res = client.delete(f"/api/v1/aro/user/delete_user/{user_id}", headers={"Content-Type": "application/json"})
123129

124130
assert res.status_code == 200
125131
all_users = res.json()["data"]

0 commit comments

Comments
 (0)