1
from typing import Any, Optional
3
from starlette.requests import Request
5
from app.basic.store.models.store_models import Store
6
from app.basic.store.schemas.store_schemas import StoreCreateScheme, StoreUpdateScheme, StoreFilter
7
from core.permissions import permit
8
from core.service.base import BaseService, UpdateSchemaType, ModelType, FilterSchemaType, CreateSchemaType
11
class StoreService(BaseService[Store, StoreCreateScheme, StoreUpdateScheme, StoreFilter]):
12
def __init__(self, request: Request):
13
super(StoreService, self).__init__(request, Store,StoreCreateScheme, StoreUpdateScheme)
16
async def update(self, id: Any, obj: UpdateSchemaType) -> Optional[ModelType]:
17
return await super(StoreService, self).update(id, obj)
20
async def list(self, _filter: FilterSchemaType, size: int):
21
return await super(StoreService, self).list(_filter, size)
23
@permit('store_create')
24
async def create(self, obj: CreateSchemaType) -> ModelType:
25
return await super(StoreService, self).create(obj)
27
@permit('store_delete')
28
async def delete(self, id: Any) -> None:
29
return await super(StoreService, self).delete(id)
31
@permit('assign_store')
32
async def assign_store(self, store_id: Any) -> None:
33
store_entity = await self.get(store_id)
34
user_entity = await self.env['user'].service.get(self.user.user_id)
35
user_entity.store_id = store_entity.id
36
self.session.add(user_entity)
37
await self.session.commit()
40
'detail': 'User has been assigned the store'