11import logging
22from datetime import datetime , timedelta
3+ from typing import Any , List
4+ from uuid import UUID
35
46import jwt
57from fastapi import APIRouter , Depends , HTTPException , Request , status
2931async def sign_in (
3032 response : Response ,
3133 payload : SignInInputSchema ,
32- ):
34+ ) -> None :
3335 """This method is used to sign in.
3436
3537 :params response: a response object.
@@ -62,8 +64,8 @@ async def sign_in(
6264@router .post ("/sign-out" )
6365async def sign_out (
6466 response : Response ,
65- _ : str = Depends (get_user_id ),
66- ):
67+ _ : UUID | int = Depends (get_user_id ),
68+ ) -> None :
6769 """This method is used to sign out.
6870
6971 :params response: a response object.
@@ -75,15 +77,15 @@ async def sign_out(
7577
7678@router .get ("/me" )
7779async def me (
78- user_id : str = Depends (get_user_id ),
79- ):
80+ user_id : UUID | int = Depends (get_user_id ),
81+ ) -> Any :
8082 """This method is used to get current user.
8183
8284 :params user_id: a user id.
8385 :return: A user object.
8486 """
8587 model = settings .ADMIN_USER_MODEL
86- admin_model = get_admin_model (model )
88+ admin_model : Any = get_admin_model (model )
8789 return await admin_model .get_obj (user_id )
8890
8991
@@ -95,8 +97,8 @@ async def list(
9597 sort_by : str = "-created_at" ,
9698 offset : int | None = 0 ,
9799 limit : int | None = 10 ,
98- _ : str = Depends (get_user_id ),
99- ):
100+ _ : UUID | int = Depends (get_user_id ),
101+ ) -> dict [ str , int | List [ Any ]] :
100102 """This method is used to get a list of objects.
101103
102104 :params request: a request object.
@@ -132,9 +134,9 @@ async def list(
132134@router .get ("/retrieve/{model}/{id}" )
133135async def get (
134136 model : str ,
135- id : str ,
136- _ : str = Depends (get_user_id ),
137- ):
137+ id : UUID | int ,
138+ _ : UUID | int = Depends (get_user_id ),
139+ ) -> Any :
138140 """This method is used to get an object.
139141
140142 :params model: a name of model.
@@ -154,8 +156,8 @@ async def get(
154156async def add (
155157 model : str ,
156158 payload : dict ,
157- _ : str = Depends (get_user_id ),
158- ):
159+ _ : UUID | int = Depends (get_user_id ),
160+ ) -> Any :
159161 """This method is used to add an object.
160162
161163 :params model: a name of model.
@@ -165,19 +167,16 @@ async def add(
165167 admin_model = get_admin_model (model )
166168 if not admin_model :
167169 raise HTTPException (status .HTTP_404_NOT_FOUND , detail = f"{ model } model is not registered." )
168- obj = await admin_model .save_model (None , payload )
169- if not obj :
170- raise HTTPException (status .HTTP_404_NOT_FOUND , detail = f"{ model } not found." )
171- return obj
170+ return await admin_model .save_model (None , payload )
172171
173172
174173@router .patch ("/change/{model}/{id}" )
175174async def change (
176175 model : str ,
177- id : str ,
176+ id : UUID | int ,
178177 payload : dict ,
179- _ : str = Depends (get_user_id ),
180- ):
178+ _ : UUID | int = Depends (get_user_id ),
179+ ) -> Any :
181180 """This method is used to change an object.
182181
183182 :params model: a name of model.
@@ -201,7 +200,7 @@ async def export(
201200 payload : ExportSchema ,
202201 search : str | None = None ,
203202 sort_by : str = "-created_at" ,
204- _ : str = Depends (get_user_id ),
203+ _ : UUID | int = Depends (get_user_id ),
205204):
206205 """This method is used to export a list of objects.
207206
@@ -237,9 +236,9 @@ async def export(
237236@router .delete ("/delete/{model}/{id}" )
238237async def delete (
239238 model : str ,
240- id : str ,
241- user_id : str = Depends (get_user_id ),
242- ):
239+ id : UUID | int ,
240+ user_id : UUID | int = Depends (get_user_id ),
241+ ) -> UUID | int :
243242 """This method is used to delete an object.
244243
245244 :params model: a name of model.
@@ -249,16 +248,16 @@ async def delete(
249248 admin_model = get_admin_model (model )
250249 if not admin_model :
251250 raise HTTPException (status .HTTP_404_NOT_FOUND , detail = f"{ model } model is not registered." )
252- if user_id == id :
251+ if str ( user_id ) == str ( id ) and model == settings . ADMIN_USER_MODEL :
253252 raise HTTPException (status .HTTP_403_FORBIDDEN , detail = "You cannot delete yourself." )
254253 await admin_model .delete_model (id )
255254 return id
256255
257256
258257@router .get ("/configuration" )
259258async def configuration (
260- user_id : str | None = Depends (get_user_id_or_none ),
261- ):
259+ user_id : UUID | int | None = Depends (get_user_id_or_none ),
260+ ) -> ConfigurationSchema :
262261 """This method is used to get a configuration.
263262
264263 :params user_id: an id of user.
0 commit comments