Spaces:
Sleeping
Sleeping
Download src/usecases/routine_usecase.py from exploreshree/jarvis-backend: direct link, hf CLI and curl.
- Browser
- Download file 1.31 kB
-
https://huggingface.co/spaces/exploreshree/jarvis-backend/resolve/main/src/usecases/routine_usecase.py
- Command line
-
hf download hf://spaces/exploreshree/jarvis-backend/src/usecases/routine_usecase.py
-
curl -L -o routine_usecase.py https://huggingface.co/spaces/exploreshree/jarvis-backend/resolve/main/src/usecases/routine_usecase.py
1.31 kB
| from src.infrastructure.repositories.routine_repository import RoutineRepository | |
| from src.domain.schemas.routine import RoutineCreate | |
| from fastapi import HTTPException | |
| class RoutineUseCase: | |
| def __init__(self, repository: RoutineRepository): | |
| self.repository = repository | |
| def _format_routine(self, d: dict): | |
| if "_id" in d: | |
| d["id"] = str(d.pop("_id")) | |
| return d | |
| async def create_routine(self, routine_in: RoutineCreate): | |
| data = routine_in.dict() | |
| routine = await self.repository.create(data) | |
| return self._format_routine(routine) | |
| async def get_all_routines(self, assigned_to: str = None, date_str: str = None): | |
| routines = await self.repository.get_all(assigned_to, date_str) | |
| return [self._format_routine(r) for r in routines] | |
| async def update_routine_status(self, routine_id: str, status: str): | |
| valid_statuses = ["PENDING", "WAITING", "DONE", "MISSED", "ABANDONED"] | |
| if status not in valid_statuses: | |
| raise HTTPException(status_code=400, detail="Invalid status") | |
| success = await self.repository.update_status(routine_id, status) | |
| if not success: | |
| raise HTTPException(status_code=404, detail="Routine not found") | |
| return {"msg": "Status updated successfully"} | |