add user with tasks and endpoint
This commit is contained in:
@@ -26,7 +26,7 @@ class UsersRepo(BaseRepo):
|
|||||||
.where(self.model.id == user_id)
|
.where(self.model.id == user_id)
|
||||||
.options(
|
.options(
|
||||||
selectinload(self.model.tasks).load_only(
|
selectinload(self.model.tasks).load_only(
|
||||||
TasksORM.id, TasksORM.title, TasksORM.due_date
|
TasksORM.id, TasksORM.title, TasksORM.due_date, TasksORM.priority
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -4,11 +4,19 @@ from typing import Literal
|
|||||||
from pydantic import BaseModel, ConfigDict
|
from pydantic import BaseModel, ConfigDict
|
||||||
|
|
||||||
|
|
||||||
class TaskADDRequest(BaseModel):
|
class TaskShort(BaseModel):
|
||||||
title: str
|
title: str
|
||||||
description: str | None = None
|
|
||||||
due_date: date | None = None
|
due_date: date | None = None
|
||||||
priority: Literal["low", "medium", "high", "critical"] = "medium"
|
priority: Literal["low", "medium", "high", "critical"] = "medium"
|
||||||
|
model_config = ConfigDict(from_attributes=True)
|
||||||
|
|
||||||
|
|
||||||
|
class TaskWithId(TaskShort):
|
||||||
|
id: int
|
||||||
|
|
||||||
|
|
||||||
|
class TaskADDRequest(TaskShort):
|
||||||
|
description: str | None = None
|
||||||
|
|
||||||
|
|
||||||
class Task(TaskADDRequest):
|
class Task(TaskADDRequest):
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ from typing import Annotated
|
|||||||
|
|
||||||
from pydantic import BaseModel, BeforeValidator, ConfigDict, EmailStr
|
from pydantic import BaseModel, BeforeValidator, ConfigDict, EmailStr
|
||||||
|
|
||||||
|
from src.schemas.tasks import TaskWithId
|
||||||
from src.schemas.validators import ensure_password
|
from src.schemas.validators import ensure_password
|
||||||
|
|
||||||
|
|
||||||
@@ -25,6 +26,10 @@ class UserWithHashedPass(User):
|
|||||||
hashed_password: str
|
hashed_password: str
|
||||||
|
|
||||||
|
|
||||||
|
class UserWithTasks(User):
|
||||||
|
tasks: list[TaskWithId]
|
||||||
|
|
||||||
|
|
||||||
class UserRequest(BaseModel):
|
class UserRequest(BaseModel):
|
||||||
username: str
|
username: str
|
||||||
password: str
|
password: str
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
from fastapi import HTTPException
|
from fastapi import HTTPException
|
||||||
|
|
||||||
from src.schemas.users import User, UserUpdate
|
from src.schemas.users import User, UserUpdate, UserWithTasks
|
||||||
from src.services.base import BaseService
|
from src.services.base import BaseService
|
||||||
|
|
||||||
|
|
||||||
@@ -43,3 +43,4 @@ class UserService(BaseService):
|
|||||||
user = await self.session.user.get_one_with_load(user_id)
|
user = await self.session.user.get_one_with_load(user_id)
|
||||||
if user is None:
|
if user is None:
|
||||||
raise HTTPException(status_code=404, detail="User not found.")
|
raise HTTPException(status_code=404, detail="User not found.")
|
||||||
|
return UserWithTasks.model_validate(user)
|
||||||
|
|||||||
Reference in New Issue
Block a user