Skip to content

Commit

Permalink
Added doc string to repositories
Browse files Browse the repository at this point in the history
  • Loading branch information
niklastheman committed Feb 21, 2024
1 parent 393427c commit 1338055
Show file tree
Hide file tree
Showing 9 changed files with 241 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,13 @@ def __init__(self, database: Database, collection: str):
super().__init__(database, collection)

def get(self, id: str, use_typing: bool = False) -> Client:
"""Get an entity by id
param id: The id of the entity
type: str
param use_typing: Whether to return the entity as a typed object or as a dict
type: bool
return: The entity
"""
response = super().get(id, use_typing=use_typing)
return Client.from_dict(response) if use_typing else response

Expand All @@ -49,6 +56,22 @@ def delete(self, id: str) -> bool:
raise NotImplementedError("Delete not implemented for ClientRepository")

def list(self, limit: int, skip: int, sort_key: str, sort_order=pymongo.DESCENDING, use_typing: bool = False, **kwargs) -> Dict[int, List[Client]]:
"""List entities
param limit: The maximum number of entities to return
type: int
param skip: The number of entities to skip
type: int
param sort_key: The key to sort by
type: str
param sort_order: The order to sort by
type: pymongo.DESCENDING | pymongo.ASCENDING
param use_typing: Whether to return the entities as typed objects or as dicts
type: bool
param kwargs: Additional query parameters
type: dict
example: {"key": "models"}
return: A dictionary with the count and the result
"""
response = super().list(limit, skip, sort_key or "last_seen", sort_order, use_typing=use_typing, **kwargs)

result = [Client.from_dict(item) for item in response['result']] if use_typing else response['result']
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,14 @@ def __init__(self, database: Database, collection: str):
super().__init__(database, collection)

def get(self, id: str, use_typing: bool = False) -> Combiner:
"""Get an entity by id
param id: The id of the entity
type: str
description: The id of the entity, can be either the id or the name (property)
param use_typing: Whether to return the entity as a typed object or as a dict
type: bool
return: The entity
"""
if ObjectId.is_valid(id):
id_obj = ObjectId(id)
document = self.database[self.collection].find_one({'_id': id_obj})
Expand All @@ -81,6 +89,22 @@ def delete(self, id: str) -> bool:
raise NotImplementedError("Delete not implemented for CombinerRepository")

def list(self, limit: int, skip: int, sort_key: str, sort_order=pymongo.DESCENDING, use_typing: bool = False, **kwargs) -> Dict[int, List[Combiner]]:
"""List entities
param limit: The maximum number of entities to return
type: int
param skip: The number of entities to skip
type: int
param sort_key: The key to sort by
type: str
param sort_order: The order to sort by
type: pymongo.DESCENDING | pymongo.ASCENDING
param use_typing: Whether to return the entities as typed objects or as dicts
type: bool
param kwargs: Additional query parameters
type: dict
example: {"key": "models"}
return: A dictionary with the count and the result
"""
response = super().list(limit, skip, sort_key or "updated_at", sort_order, use_typing=use_typing, **kwargs)

result = [Combiner.from_dict(item) for item in response['result']] if use_typing else response['result']
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,14 @@ def __init__(self, database: Database, collection: str):
super().__init__(database, collection)

def get(self, id: str, use_typing: bool = False) -> Model:
"""Get an entity by id
param id: The id of the entity
type: str
description: The id of the entity, can be either the id or the model (property)
param use_typing: Whether to return the entity as a typed object or as a dict
type: bool
return: The entity
"""
kwargs = {"key": "models"}
if ObjectId.is_valid(id):
id_obj = ObjectId(id)
Expand All @@ -59,6 +67,22 @@ def delete(self, id: str) -> bool:
raise NotImplementedError("Delete not implemented for ModelRepository")

def list(self, limit: int, skip: int, sort_key: str, sort_order=pymongo.DESCENDING, use_typing: bool = False, **kwargs) -> Dict[int, List[Model]]:
"""List entities
param limit: The maximum number of entities to return
type: int
param skip: The number of entities to skip
type: int
param sort_key: The key to sort by
type: str
param sort_order: The order to sort by
type: pymongo.DESCENDING | pymongo.ASCENDING
param use_typing: Whether to return the entities as typed objects or as dicts
type: bool
param kwargs: Additional query parameters
type: dict
example: {"key": "models"}
return: A dictionary with the count and the result
"""
kwargs['key'] = "models"

response = super().list(limit, skip, sort_key or "committed_at", sort_order, use_typing=use_typing, **kwargs)
Expand All @@ -70,6 +94,16 @@ def list(self, limit: int, skip: int, sort_key: str, sort_order=pymongo.DESCENDI
}

def list_descendants(self, id: str, limit: int, use_typing: bool = False) -> List[Model]:
"""List descendants
param id: The id of the entity
type: str
description: The id of the entity, can be either the id or the model (property)
param limit: The maximum number of entities to return
type: int
param use_typing: Whether to return the entities as typed objects or as dicts
type: bool
return: A list of entities
"""
kwargs = {"key": "models"}
if ObjectId.is_valid(id):
id_obj = ObjectId(id)
Expand Down Expand Up @@ -103,6 +137,16 @@ def list_descendants(self, id: str, limit: int, use_typing: bool = False) -> Lis
return result

def list_ancestors(self, id: str, limit: int, use_typing: bool = False) -> List[Model]:
"""List ancestors
param id: The id of the entity
type: str
description: The id of the entity, can be either the id or the model (property)
param limit: The maximum number of entities to return
type: int
param use_typing: Whether to return the entities as typed objects or as dicts
type: bool
return: A list of entities
"""
kwargs = {"key": "models"}
if ObjectId.is_valid(id):
id_obj = ObjectId(id)
Expand Down Expand Up @@ -134,5 +178,11 @@ def list_ancestors(self, id: str, limit: int, use_typing: bool = False) -> List[
return result

def count(self, **kwargs) -> int:
"""Count entities
param kwargs: Additional query parameters
type: dict
example: {"key": "models"}
return: The count (int)
"""
kwargs['key'] = "models"
return super().count(**kwargs)
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,16 @@ def __init__(self, database: Database, collection: str):
super().__init__(database, collection)

def get(self, id: str, use_typing: bool = False) -> Package:
"""Get an entity by id
param id: The id of the entity
type: str
description: The id of the entity, can be either the id or the model (property)
param use_typing: Whether to return the entity as a typed object or as a dict
type: bool
description: Whether to return the entities as typed objects or as dicts.
If True, and active property will be set based on the active package.
return: The entity
"""
document = self.database[self.collection].find_one({'id': id})

if document is None:
Expand All @@ -69,6 +79,11 @@ def get(self, id: str, use_typing: bool = False) -> Package:
return Package.from_dict(document, response_active)

def get_active(self, use_typing: bool = False) -> Package:
"""Get the active entity
param use_typing: Whether to return the entity as a typed object or as a dict
type: bool
return: The entity
"""
response = self.database[self.collection].find_one({'key': 'active'})

if response is None:
Expand All @@ -86,6 +101,24 @@ def delete(self, id: str) -> bool:
raise NotImplementedError("Delete not implemented for PackageRepository")

def list(self, limit: int, skip: int, sort_key: str, sort_order=pymongo.DESCENDING, use_typing: bool = False, **kwargs) -> Dict[int, List[Package]]:
"""List entities
param limit: The maximum number of entities to return
type: int
param skip: The number of entities to skip
type: int
param sort_key: The key to sort by
type: str
param sort_order: The order to sort by
type: pymongo.DESCENDING | pymongo.ASCENDING
param use_typing: Whether to return the entities as typed objects or as dicts
type: bool
description: Whether to return the entities as typed objects or as dicts.
If True, and active property will be set based on the active package.
param kwargs: Additional query parameters
type: dict
example: {"key": "models"}
return: A dictionary with the count and the result
"""
kwargs["key"] = "package_trail"

response = super().list(limit, skip, sort_key or "committed_at", sort_order, use_typing=True, **kwargs)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ def get(self, id: str, use_typing: bool = False) -> T:
param id: The id of the entity
type: str
param use_typing: Whether to return the entity as a typed object or as a dict
type: bool
return: The entity
"""
id_obj = ObjectId(id)
Expand Down Expand Up @@ -67,4 +68,10 @@ def list(self, limit: int, skip: int, sort_key: str, sort_order=pymongo.DESCENDI
}

def count(self, **kwargs) -> int:
"""Count entities
param kwargs: Additional query parameters
type: dict
example: {"key": "models"}
return: The count (int)
"""
return self.database[self.collection].count_documents(kwargs)
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,13 @@ def __init__(self, database: Database, collection: str):
super().__init__(database, collection)

def get(self, id: str, use_typing: bool = False) -> Round:
"""Get an entity by id
param id: The id of the entity
type: str
param use_typing: Whether to return the entity as a typed object or as a dict
type: bool
return: The entity
"""
response = super().get(id, use_typing=use_typing)
return Round.from_dict(response) if use_typing else response

Expand All @@ -44,6 +51,23 @@ def delete(self, id: str) -> bool:
raise NotImplementedError("Delete not implemented for RoundRepository")

def list(self, limit: int, skip: int, sort_key: str, sort_order=pymongo.DESCENDING, use_typing: bool = False, **kwargs) -> Dict[int, List[Round]]:
"""List entities
param limit: The maximum number of entities to return
type: int
description: The maximum number of entities to return
param skip: The number of entities to skip
type: int
description: The number of entities to skip
param sort_key: The key to sort by
type: str
description: The key to sort by
param sort_order: The order to sort by
type: pymongo.DESCENDING
description: The order to sort by
param use_typing: Whether to return the entity as a typed object or as a dict
type: bool
return: The entities
"""
response = super().list(limit, skip, sort_key or "round_id", sort_order, use_typing=use_typing, **kwargs)

result = [Round.from_dict(item) for item in response['result']] if use_typing else response['result']
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,14 @@ def __init__(self, database: Database, collection: str):
super().__init__(database, collection)

def get(self, id: str, use_typing: bool = False) -> Session:
"""Get an entity by id
param id: The id of the entity
type: str
description: The id of the entity, can be either the id or the session_id (property)
param use_typing: Whether to return the entity as a typed object or as a dict
type: bool
return: The entity
"""
if ObjectId.is_valid(id):
id_obj = ObjectId(id)
document = self.database[self.collection].find_one({'_id': id_obj})
Expand All @@ -51,6 +59,27 @@ def delete(self, id: str) -> bool:
raise NotImplementedError("Delete not implemented for SessionRepository")

def list(self, limit: int, skip: int, sort_key: str, sort_order=pymongo.DESCENDING, use_typing: bool = False, **kwargs) -> Dict[int, List[Session]]:
"""List entities
param limit: The maximum number of entities to return
type: int
description: The maximum number of entities to return
param skip: The number of entities to skip
type: int
description: The number of entities to skip
param sort_key: The key to sort by
type: str
description: The key to sort by
param sort_order: The order to sort by
type: pymongo.DESCENDING
description: The order to sort by
param use_typing: Whether to return the entity as a typed object or as a dict
type: bool
description: Whether to return the entities as typed objects or as dicts.
param kwargs: Additional query parameters
type: dict
description: Additional query parameters
return: The entities
"""
response = super().list(limit, skip, sort_key or "session_id", sort_order, use_typing=use_typing, **kwargs)

result = [Session.from_dict(item) for item in response['result']] if use_typing else response['result']
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,14 @@ def __init__(self, database: Database, collection: str):
super().__init__(database, collection)

def get(self, id: str, use_typing: bool = False) -> Status:
"""Get an entity by id
param id: The id of the entity
type: str
description: The id of the entity, can be either the id or the status (property)
param use_typing: Whether to return the entity as a typed object or as a dict
type: bool
return: The entity
"""
response = super().get(id, use_typing=use_typing)
return Status.from_dict(response) if use_typing else response

Expand All @@ -64,6 +72,23 @@ def delete(self, id: str) -> bool:
raise NotImplementedError("Delete not implemented for StatusRepository")

def list(self, limit: int, skip: int, sort_key: str, sort_order=pymongo.DESCENDING, use_typing: bool = False, **kwargs) -> Dict[int, List[Status]]:
"""List entities
param limit: The maximum number of entities to return
type: int
description: The maximum number of entities to return
param skip: The number of entities to skip
type: int
description: The number of entities to skip
param sort_key: The key to sort by
type: str
description: The key to sort by
param sort_order: The order to sort by
type: pymongo.DESCENDING
description: The order to sort by
param use_typing: Whether to return the entities as typed objects or as dicts
type: bool
description: Whether to return the entities as typed objects or as dicts.
"""
response = super().list(limit, skip, sort_key or "timestamp", sort_order, use_typing=use_typing, **kwargs)

result = [Status.from_dict(item) for item in response['result']] if use_typing else response['result']
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,14 @@ def __init__(self, database: Database, collection: str):
super().__init__(database, collection)

def get(self, id: str, use_typing: bool = False) -> Validation:
"""Get an entity by id
param id: The id of the entity
type: str
description: The id of the entity, can be either the id or the validation (property)
param use_typing: Whether to return the entity as a typed object or as a dict
type: bool
return: The entity
"""
response = super().get(id, use_typing=use_typing)
return Validation.from_dict(response) if use_typing else response

Expand All @@ -61,6 +69,24 @@ def delete(self, id: str) -> bool:
raise NotImplementedError("Delete not implemented for ValidationRepository")

def list(self, limit: int, skip: int, sort_key: str, sort_order=pymongo.DESCENDING, use_typing: bool = False, **kwargs) -> Dict[int, List[Validation]]:
"""List entities
param limit: The maximum number of entities to return
type: int
description: The maximum number of entities to return
param skip: The number of entities to skip
type: int
description: The number of entities to skip
param sort_key: The key to sort by
type: str
description: The key to sort by
param sort_order: The order to sort by
type: pymongo.DESCENDING
description: The order to sort by
param use_typing: Whether to return the entities as typed objects or as dicts
type: bool
description: Whether to return the entities as typed objects or as dicts
return: A dictionary with the count and a list of entities
"""
response = super().list(limit, skip, sort_key or "timestamp", sort_order, use_typing=use_typing, **kwargs)

result = [Validation.from_dict(item) for item in response['result']] if use_typing else response['result']
Expand Down

0 comments on commit 1338055

Please sign in to comment.