add to tasks service

This commit is contained in:
IluaAir
2025-08-29 22:10:15 +03:00
parent 07f14b0564
commit bd9786c14c
3 changed files with 23 additions and 4 deletions

View File

@@ -36,7 +36,9 @@ class Date(BaseModel):
@model_validator(mode="after")
def check_dates(self):
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

View File

@@ -18,9 +18,16 @@ async def get_tasks(
user: ActiveUser,
page: PaginationTasksDep,
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

View File

@@ -1,3 +1,4 @@
from datetime import date
from fastapi import HTTPException
from src.schemas.users import User, UserUpdate, UserWithTasks
@@ -39,7 +40,16 @@ class UserService(BaseService):
await self.session.commit()
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)
if user is None:
raise HTTPException(status_code=404, detail="User not found.")