1919
2020
2121def get_orm_session ():
22+ """
23+ Dependency function to yield a scoped SQLAlchemy ORM session.
24+
25+ Yields:
26+ OrmSession: An instance of a scoped SQLAlchemy ORM session.
27+ """
2228 orm_session = OrmSession ()
2329 try :
2430 yield orm_session
@@ -31,12 +37,22 @@ def get_orm_session():
3137@api_router .post (
3238 "/players/" ,
3339 status_code = status .HTTP_201_CREATED ,
34- summary = "Creates a new Player" ,
40+ summary = "Creates a new Player"
3541)
3642def post (
3743 player_model : PlayerModel = Body (...),
38- orm_session : Session = Depends (get_orm_session ),
44+ orm_session : Session = Depends (get_orm_session )
3945):
46+ """
47+ Endpoint to create a new player.
48+
49+ Args:
50+ player_model (PlayerModel): The data model representing a Player.
51+ orm_session (Session): The SQLAlchemy ORM session.
52+
53+ Raises:
54+ HTTPException: HTTP 409 Conflict error if the Player already exists.
55+ """
4056 player = player_service .retrieve_by_id (orm_session , player_model .id )
4157
4258 if player :
@@ -59,6 +75,15 @@ def post(
5975def get_all (
6076 orm_session : Session = Depends (get_orm_session )
6177):
78+ """
79+ Endpoint to retrieve all players.
80+
81+ Args:
82+ orm_session (Session): The SQLAlchemy ORM session.
83+
84+ Returns:
85+ List[PlayerModel]: A list of data models representing all players.
86+ """
6287 players = player_service .retrieve_all (orm_session )
6388
6489 return players
@@ -72,9 +97,22 @@ def get_all(
7297)
7398@cache (expire = CACHING_TIME_IN_SECONDS )
7499def get_by_id (
75- player_id : int = Path (..., title = "The Id of the Player" ),
100+ player_id : int = Path (..., title = "The ID of the Player" ),
76101 orm_session : Session = Depends (get_orm_session )
77102):
103+ """
104+ Endpoint to retrieve a Player by its ID.
105+
106+ Args:
107+ player_id (int): The ID of the Player to retrieve.
108+ orm_session (Session): The SQLAlchemy ORM session.
109+
110+ Returns:
111+ PlayerModel: A data model representing the Player.
112+
113+ Raises:
114+ HTTPException: Not found error if the Player with the specified ID does not exist.
115+ """
78116 player = player_service .retrieve_by_id (orm_session , player_id )
79117
80118 if not player :
@@ -94,6 +132,19 @@ def get_by_squad_number(
94132 squad_number : int = Path (..., title = "The Squad Number of the Player" ),
95133 orm_session : Session = Depends (get_orm_session )
96134):
135+ """
136+ Endpoint to retrieve a Player by its Squad Number.
137+
138+ Args:
139+ squad_number (int): The Squad Number of the Player to retrieve.
140+ orm_session (Session): SQLAlchemy ORM session.
141+
142+ Returns:
143+ PlayerModel: A data model representing the Player.
144+
145+ Raises:
146+ HTTPException: HTTP 404 Not Found error if the Player with the specified Squad Number does not exist.
147+ """
97148 player = player_service .retrieve_by_squad_number (orm_session , squad_number )
98149
99150 if not player :
@@ -110,11 +161,21 @@ def get_by_squad_number(
110161 summary = "Updates an existing Player"
111162)
112163def put (
113- player_id : int = Path (..., title = "The Id of the Player" ),
164+ player_id : int = Path (..., title = "The ID of the Player" ),
114165 player_model : PlayerModel = Body (...),
115- orm_session : Session = Depends (get_orm_session ),
116-
166+ orm_session : Session = Depends (get_orm_session )
117167):
168+ """
169+ Endpoint to entirely update an existing Player.
170+
171+ Args:
172+ player_id (int): The ID of the Player to update.
173+ player_model (PlayerModel): The data model representing the Player to update.
174+ orm_session (Session): The SQLAlchemy ORM session.
175+
176+ Raises:
177+ HTTPException: HTTP 404 Not Found error if the player with the specified ID does not exist.
178+ """
118179 player = player_service .retrieve_by_id (orm_session , player_id )
119180
120181 if not player :
@@ -133,13 +194,23 @@ def put(
133194 summary = "Deletes an existing Player"
134195)
135196def delete (
136- player_id : int = Path (..., title = "The Id of the Player" ),
197+ player_id : int = Path (..., title = "The ID of the Player" ),
137198 orm_session : Session = Depends (get_orm_session )
138199):
200+ """
201+ Endpoint to delete an existing Player.
202+
203+ Args:
204+ player_id (int): The ID of the Player to delete.
205+ orm_session (Session): The SQLAlchemy ORM session.
206+
207+ Raises:
208+ HTTPException: HTTP 404 Not Found error if the Player with the specified ID does not exist.
209+ """
139210 player = player_service .retrieve_by_id (orm_session , player_id )
140211
141212 if not player :
142- raise HTTPException (status_code = status .HTTP_404_NOT_FOUND , detail = "Player not found" )
213+ raise HTTPException (status_code = status .HTTP_404_NOT_FOUND )
143214
144215 player_service .delete (orm_session , player_id )
145216
0 commit comments