Coverage for fastid / apps / use_cases.py: 100%

21 statements  

« prev     ^ index     » next       coverage.py v7.13.1, created at 2026-10-18 16:37 +0000

1from fastid.apps.exceptions import AppNotFoundError 

2from fastid.apps.models import App 

3from fastid.apps.schemas import AppCreate, AppUpdate 

4from fastid.cache.dependencies import CacheDep 

5from fastid.core.base import UseCase 

6from fastid.database.dependencies import UOWDep 

7from fastid.database.exceptions import NoResultFoundError 

8from fastid.database.utils import UUIDv7 

9 

10 

11class AppUseCases(UseCase): 

12 def __init__(self, uow: UOWDep, cache: CacheDep) -> None: 

13 self.uow = uow 

14 self.cache = cache 

15 

16 async def register(self, dto: AppCreate) -> App: 

17 app = App.from_dto(dto) 

18 await self.uow.apps.add(app) 

19 await self.uow.commit() 

20 return app 

21 

22 async def get(self, app_id: UUIDv7) -> App: 

23 try: 

24 return await self.uow.apps.get(app_id) 

25 except NoResultFoundError as e: 

26 raise AppNotFoundError from e 

27 

28 async def update(self, app: App, app_update: AppUpdate) -> App: 

29 app.merge_model(app_update) 

30 await self.uow.commit() 

31 return app 

32 

33 async def delete(self, app: App) -> App: 

34 app = await self.uow.apps.delete(app) 

35 await self.uow.commit() 

36 return app