File tree 4 files changed +37
-2
lines changed
4 files changed +37
-2
lines changed Original file line number Diff line number Diff line change 1
1
from fastapi import APIRouter
2
2
3
- from . import auth
4
- from . import roles
3
+ from . import auth , roles , users
5
4
6
5
router = APIRouter (prefix = "/v1" )
7
6
8
7
router .include_router (auth .router )
9
8
router .include_router (roles .router )
9
+ router .include_router (users .router )
Original file line number Diff line number Diff line change
1
+ from .routes import router
2
+
3
+ __all__ = (router ,)
Original file line number Diff line number Diff line change
1
+ from typing import List
2
+ from pydantic import BaseModel
3
+
4
+
5
+ class UserResponse (BaseModel ):
6
+ id : str
7
+ username : str
8
+ discriminator : str
9
+ avatar : str
10
+ app : bool
11
+ roles : List [str ]
Original file line number Diff line number Diff line change
1
+ from fastapi import APIRouter
2
+
3
+ from .models import UserResponse
4
+
5
+ from api .models import User , UserRole
6
+ from api .dependencies import authorization
7
+
8
+
9
+ router = APIRouter (prefix = "/users" )
10
+
11
+
12
+ @router .get (
13
+ "/@me" ,
14
+ response_model = UserResponse ,
15
+ responses = {401 : {"description" : "Unauthorized" }},
16
+ )
17
+ async def get_current_user (user : User = authorization ()):
18
+ query = """SELECT role_id FROM userroles WHERE user_id = $1;"""
19
+ roles = [record ["role_id" ] for record in await UserRole .pool .fetch (query , user .id )]
20
+
21
+ return {** user .as_dict (), "roles" : roles }
You can’t perform that action at this time.
0 commit comments