Initial commit
This commit is contained in:
@@ -0,0 +1,55 @@
|
||||
from typing import Union, List
|
||||
from uuid import UUID
|
||||
|
||||
from auth.models import AuthPropertyModel
|
||||
from auth.utils.mongo import use_auth_collection
|
||||
from core.models.base import DELETED_AT_QUERY
|
||||
from core.utils.app_context import use_user
|
||||
from core.utils.crudify import mongo_inserter, mongo_updater, mongo_find_one, mongo_soft_deleter
|
||||
|
||||
COLLECTION_PROPERTY = 'property'
|
||||
|
||||
|
||||
class PropertyRepository:
|
||||
@staticmethod
|
||||
async def create(_input: AuthPropertyModel) -> dict:
|
||||
return await mongo_inserter(_input, COLLECTION_PROPERTY, client=use_auth_collection,
|
||||
getter=PropertyRepository.get)
|
||||
|
||||
@staticmethod
|
||||
async def update(_id: UUID, _input: AuthPropertyModel) -> bool:
|
||||
return await mongo_updater(_input,
|
||||
_id,
|
||||
COLLECTION_PROPERTY,
|
||||
client=use_auth_collection,
|
||||
getter=PropertyRepository.get)
|
||||
|
||||
@staticmethod
|
||||
async def get(_input: Union[UUID, str]) -> AuthPropertyModel:
|
||||
"""
|
||||
get argument from args
|
||||
Args:
|
||||
_input: Union[UUID,str]
|
||||
Returns:
|
||||
AuthPropertyModel
|
||||
"""
|
||||
q = {'key': _input} if isinstance(_input, str) else {'_id': _input} if isinstance(_input, UUID) else _input
|
||||
q['owner_id'] = use_user().id
|
||||
result = await mongo_find_one(q, COLLECTION_PROPERTY, client=use_auth_collection)
|
||||
return AuthPropertyModel(**result)
|
||||
|
||||
@staticmethod
|
||||
async def fetch() -> List[AuthPropertyModel]:
|
||||
q = {}
|
||||
q['owner_id'] = use_user().id
|
||||
result = await use_auth_collection(COLLECTION_PROPERTY) \
|
||||
.find({**q, **DELETED_AT_QUERY}) \
|
||||
.to_list(100)
|
||||
return [AuthPropertyModel(**x) for x in result]
|
||||
|
||||
@staticmethod
|
||||
async def delete(_input: Union[UUID, str]) -> bool:
|
||||
q = {'key': _input} if isinstance(_input, str) else {'_id': _input}
|
||||
q['owner_id'] = use_user().id
|
||||
result = await mongo_soft_deleter(q, COLLECTION_PROPERTY, client=use_auth_collection)
|
||||
return result
|
||||
Reference in New Issue
Block a user