This commit is contained in:
암냥 2025-09-13 16:24:39 +09:00
commit 5f8600d9ae
3 changed files with 14 additions and 15 deletions

View file

@ -48,21 +48,20 @@ async def login_user(login_data: UserLogin) -> dict:
if not user: if not user:
raise HTTPException( raise HTTPException(
status_code= status_code=status.HTTP_401_UNAUTHORIZED,
detail= detail="User account is not exist"
) )
if not user.is_active: if not user.is_active:
raise HTTPException( raise HTTPException(
status_code=, detail="" status_code=status.HTTP_401_UNAUTHORIZED, detail="User account is incative"
) )
access_token = access_token = create_access_token(data={"sub": user.username})
return {"access_token": access_token, "token_type": "bearer"} return {"access_token": access_token, "token_type": "bearer"}
@router.get("/profile/{username}", response_model=UserResponse) @router.get("/profile/{username}", response_model=UserResponse)
async def get_user_profile(username: str) -> UserResponse: async def get_user_profile(username: str) -> UserResponse:
user = await user_service.get_user_by_username(username) user = await user_service.get_user_by_username(username)

View file

@ -7,27 +7,27 @@ class StoreService:
async def get_dotory_by_id(self, user_id: int): async def get_dotory_by_id(self, user_id: int):
async with httpx.AsyncClient() as client: async with httpx.AsyncClient() as client:
response = await client.get(f"{self.SERVER_URL}/") response = await client.get(f"{self.SERVER_URL}/api/dotory/{user_id}")
response_json = response.json() response_json = response.json()
return return response_json["dotory"]
async def register_user(self, user_id: int): async def register_user(self, user_id: int):
async with httpx.AsyncClient() as client: async with httpx.AsyncClient() as client:
response = await client.post( response = await client.post(
f"{self.SERVER_URL}/", json={"user_id": user_id} f"{self.SERVER_URL}/api/dotory", json={"user_id": user_id}
) )
return return response.json()
async def buy_product(self, product_id: int, user_id: int): async def buy_product(self, product_id: int, user_id: int):
async with httpx.AsyncClient() as client: async with httpx.AsyncClient() as client:
response = await client.post( response = await client.post(
f"{self.SERVER_URL}/", json={"user_id": user_id} f"{self.SERVER_URL}/api/buy/{product_id}", json={"user_id": user_id}
) )
return return response.json()
async def update_user_dotory(self, user_id: int, dotoryNum: int): async def update_user_dotory(self, user_id: int, dotoryNum: int):
async with httpx.AsyncClient() as client: async with httpx.AsyncClient() as client:
response = await client.put( response = await client.put(
f"{self.SERVER_URL}/", json={"num": dotoryNum} f"{self.SERVER_URL}/api/dotory/{user_id}", json={"num": dotoryNum}
) )
return return response.json()["dotory"]

View file

@ -106,8 +106,8 @@ class UserService:
return User(**row) return User(**row)
async def authenticate_user(self, username: str, password: str) -> Optional[User]: async def authenticate_user(self, username: str, password: str) -> Optional[User]:
user = user = await self.get_user_by_username(username)
if user and : if user and user.verify_password(password):
return user return user
return None return None