add to tasks service
This commit is contained in:
@@ -36,7 +36,9 @@ class Date(BaseModel):
|
|||||||
@model_validator(mode="after")
|
@model_validator(mode="after")
|
||||||
def check_dates(self):
|
def check_dates(self):
|
||||||
if self.date_from and self.date_to and self.date_to < self.date_from:
|
if self.date_from and self.date_to and self.date_to < self.date_from:
|
||||||
raise HTTPException(status_code=422, detail="date_to cannot be less than date_from")
|
raise HTTPException(
|
||||||
|
status_code=422, detail="date_to cannot be less than date_from"
|
||||||
|
)
|
||||||
return self
|
return self
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -18,9 +18,16 @@ async def get_tasks(
|
|||||||
user: ActiveUser,
|
user: ActiveUser,
|
||||||
page: PaginationTasksDep,
|
page: PaginationTasksDep,
|
||||||
status: StatusTaskDep,
|
status: StatusTaskDep,
|
||||||
date: DateDep,
|
date_filter: DateDep,
|
||||||
):
|
):
|
||||||
result = await UserService(session).get_user_with_tasks(user.id)
|
result = await UserService(session).get_user_with_tasks(
|
||||||
|
user_id=user.id,
|
||||||
|
status=status.status,
|
||||||
|
limit=page.limit,
|
||||||
|
offset=page.page,
|
||||||
|
date_to=date_filter.date_to,
|
||||||
|
date_from=date_filter.date_from,
|
||||||
|
)
|
||||||
return result
|
return result
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
from datetime import date
|
||||||
from fastapi import HTTPException
|
from fastapi import HTTPException
|
||||||
|
|
||||||
from src.schemas.users import User, UserUpdate, UserWithTasks
|
from src.schemas.users import User, UserUpdate, UserWithTasks
|
||||||
@@ -39,7 +40,16 @@ class UserService(BaseService):
|
|||||||
await self.session.commit()
|
await self.session.commit()
|
||||||
return User.model_validate(user)
|
return User.model_validate(user)
|
||||||
|
|
||||||
async def get_user_with_tasks(self, user_id: int):
|
async def get_user_with_tasks(
|
||||||
|
self,
|
||||||
|
user_id: int,
|
||||||
|
status: str | None,
|
||||||
|
limit: int | None,
|
||||||
|
offset: int | None,
|
||||||
|
date_to: date | None,
|
||||||
|
date_from: date | None,
|
||||||
|
):
|
||||||
|
print(type(status), status)
|
||||||
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.")
|
||||||
|
|||||||
Reference in New Issue
Block a user