66
77from futuramaapi .repositories import INT32 , FilterStatementKwargs
88from futuramaapi .repositories .session import get_async_session
9- from futuramaapi .routers .exceptions import ModelExistsError , ModelNotFoundError , UnauthorizedResponse
9+ from futuramaapi .routers .exceptions import ModelNotFoundError , UnauthorizedResponse
1010
1111from .dependencies import from_form_signature , from_signature , from_token , password_from_form_data
1212from .schemas import (
1515 PasswordChange ,
1616 User ,
1717 UserAlreadyActivatedError ,
18- UserCreateRequest ,
1918 UserPasswordChangeRequest ,
2019 UserSearchResponse ,
2120 UserUpdateRequest ,
2726)
2827
2928
30- @router .post (
31- "" ,
32- status_code = status .HTTP_201_CREATED ,
33- response_model = User ,
34- name = "user" ,
35- )
36- async def create_user (
37- data : UserCreateRequest ,
38- session : AsyncSession = Depends (get_async_session ), # noqa: B008
39- ) -> User :
40- """Create User.
41-
42- The user add endpoint is an API function allowing the creation of new user accounts.
43- It receives user details via HTTP requests, validates the information,
44- and stores it in the system's database.
45- This endpoint is essential for user registration and onboarding.
46-
47- Please note that currently endpoint is not protected.
48- However, if there are a lot of spam requests, the endpoint will be blocked or limited.
49- """
50- try :
51- return await User .create (session , data )
52- except ModelExistsError :
53- raise HTTPException (
54- status_code = status .HTTP_422_UNPROCESSABLE_ENTITY ,
55- detail = "User already exists." ,
56- ) from None
57-
58-
59- @router .get (
60- "/me" ,
61- responses = {
62- status .HTTP_401_UNAUTHORIZED : {
63- "model" : UnauthorizedResponse ,
64- },
65- },
66- name = "user_me" ,
67- )
68- async def get_me (
69- user : Annotated [User , Depends (from_token )],
70- ) -> User :
71- """Get user details.
72-
73- Retrieve authenticated user profile information, including username, email, and account details.
74- Personalize user experiences within the application using the JSON response containing user-specific data.
75- """
76- return user
77-
78-
7929@router .get (
8030 "/activate" ,
8131 include_in_schema = False ,
@@ -101,29 +51,6 @@ async def activate_user(
10151 ) from None
10252
10353
104- @router .put (
105- "" ,
106- responses = {
107- status .HTTP_401_UNAUTHORIZED : {
108- "model" : UnauthorizedResponse ,
109- },
110- },
111- name = "update_user" ,
112- )
113- async def update_user (
114- user : Annotated [User , Depends (from_token )],
115- data : UserUpdateRequest ,
116- session : AsyncSession = Depends (get_async_session ), # noqa: B008
117- ) -> User :
118- """Update user details.
119-
120- This endpoint is crucial for users to manage and maintain accurate profile information,
121- often including authentication and authorization checks for security.
122- """
123- await user .update (session , data )
124- return user
125-
126-
12754@router .post (
12855 "/confirmations/resend" ,
12956 responses = {
@@ -207,6 +134,8 @@ async def change_user_password(
207134@router .post (
208135 "/links" ,
209136 name = "generate_user_link" ,
137+ description = "This endpoint is deprecated and will be removed in version 1.12.1. Please use `/api/links` instead." ,
138+ deprecated = True ,
210139)
211140async def create_user_link (
212141 data : LinkCreateRequest ,
@@ -228,6 +157,8 @@ async def create_user_link(
228157 status_code = status .HTTP_200_OK ,
229158 response_model = Page [Link ],
230159 name = "user_links" ,
160+ description = "This endpoint is deprecated and will be removed in version 1.12.1. Please use `/api/links` instead." ,
161+ deprecated = True ,
231162)
232163async def get_user_links (
233164 user : Annotated [User , Depends (from_token )],
@@ -249,6 +180,9 @@ async def get_user_links(
249180 status_code = status .HTTP_200_OK ,
250181 response_model = Link ,
251182 name = "user_link" ,
183+ description = "This endpoint is deprecated and will be removed in version 1.12.1. "
184+ "Please use `/api/links/{link_id}` instead." ,
185+ deprecated = True ,
252186)
253187async def get_user_link (
254188 link_id : Annotated [
@@ -302,34 +236,3 @@ async def search_user(
302236 },
303237 )
304238 return await UserSearchResponse .paginate (session , filter_params = filter_params )
305-
306-
307- @router .get (
308- "" ,
309- status_code = status .HTTP_200_OK ,
310- response_model = Page [UserSearchResponse ],
311- name = "users" ,
312- )
313- async def get_users (
314- query : Annotated [
315- str | None ,
316- Query (
317- alias = "query" ,
318- description = "Search by username." ,
319- max_length = 128 ,
320- ),
321- ] = None ,
322- session : AsyncSession = Depends (get_async_session ), # noqa: B008
323- ) -> UserSearchResponse :
324- """Get users.
325-
326- Retrieve users. Search by username.
327- """
328- filter_params : FilterStatementKwargs = FilterStatementKwargs (
329- offset = 0 ,
330- limit = 20 ,
331- extra = {
332- "query" : query ,
333- },
334- )
335- return await UserSearchResponse .paginate (session , filter_params = filter_params )
0 commit comments