インターフェースにオプションのuserIdを追加します。渡された場合はそのuserIdを使用し、渡されない場合はトークン内のIDを使用します。
This commit is contained in:
@@ -1,9 +1,9 @@
|
|||||||
from fastapi import Request,Depends, APIRouter, UploadFile,HTTPException,File
|
from fastapi import Query, Request,Depends, APIRouter, UploadFile,HTTPException,File
|
||||||
from app.db import Base,engine
|
from app.db import Base,engine
|
||||||
from app.db.session import get_db
|
from app.db.session import get_db
|
||||||
from app.db.crud import *
|
from app.db.crud import *
|
||||||
from app.db.schemas import *
|
from app.db.schemas import *
|
||||||
from typing import List
|
from typing import List, Optional
|
||||||
from app.core.auth import get_current_active_user,get_current_user
|
from app.core.auth import get_current_active_user,get_current_user
|
||||||
from app.core.apiexception import APIException
|
from app.core.apiexception import APIException
|
||||||
|
|
||||||
@@ -233,16 +233,17 @@ async def domain_delete(
|
|||||||
|
|
||||||
@r.get(
|
@r.get(
|
||||||
"/domain",
|
"/domain",
|
||||||
response_model=List[Domain],
|
# response_model=List[Domain],
|
||||||
response_model_exclude_none=True,
|
response_model_exclude_none=True,
|
||||||
)
|
)
|
||||||
async def userdomain_details(
|
async def userdomain_details(
|
||||||
request: Request,
|
request: Request,
|
||||||
|
userId: Optional[int] = Query(None, alias="userId"),
|
||||||
user=Depends(get_current_user),
|
user=Depends(get_current_user),
|
||||||
db=Depends(get_db),
|
db=Depends(get_db),
|
||||||
):
|
):
|
||||||
try:
|
try:
|
||||||
domains = get_domain(db, user.id)
|
domains = get_domain(db, userId if userId is not None else user.id)
|
||||||
return domains
|
return domains
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
raise APIException('platform:domain',request.url._url,f"Error occurred while get user({user.id}) domain:",e)
|
raise APIException('platform:domain',request.url._url,f"Error occurred while get user({user.id}) domain:",e)
|
||||||
@@ -285,11 +286,14 @@ async def userdomain_delete(
|
|||||||
)
|
)
|
||||||
async def get_useractivedomain(
|
async def get_useractivedomain(
|
||||||
request: Request,
|
request: Request,
|
||||||
|
userId: Optional[int] = Query(None, alias="userId"),
|
||||||
user=Depends(get_current_user),
|
user=Depends(get_current_user),
|
||||||
db=Depends(get_db),
|
db=Depends(get_db),
|
||||||
):
|
):
|
||||||
try:
|
try:
|
||||||
domain = get_activedomain(db, user.id)
|
# domain = get_activedomain(db, user.id)
|
||||||
|
|
||||||
|
domain = get_activedomain(db, userId if userId is not None else user.id)
|
||||||
return domain
|
return domain
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
raise APIException('platform:activedomain',request.url._url,f"Error occurred while get user({user.id}) activedomain:",e)
|
raise APIException('platform:activedomain',request.url._url,f"Error occurred while get user({user.id}) activedomain:",e)
|
||||||
@@ -301,11 +305,12 @@ async def get_useractivedomain(
|
|||||||
async def update_activeuserdomain(
|
async def update_activeuserdomain(
|
||||||
request: Request,
|
request: Request,
|
||||||
domainid:int,
|
domainid:int,
|
||||||
|
userId: Optional[int] = Query(None, alias="userId"),
|
||||||
user=Depends(get_current_user),
|
user=Depends(get_current_user),
|
||||||
db=Depends(get_db),
|
db=Depends(get_db),
|
||||||
):
|
):
|
||||||
try:
|
try:
|
||||||
domain = active_userdomain(db, user.id,domainid)
|
domain = active_userdomain(db, userId if userId is not None else user.id,domainid)
|
||||||
return domain
|
return domain
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
raise APIException('platform:activedomain',request.url._url,f"Error occurred while update user({user.id}) activedomain:",e)
|
raise APIException('platform:activedomain',request.url._url,f"Error occurred while update user({user.id}) activedomain:",e)
|
||||||
|
|||||||
Reference in New Issue
Block a user