def insert(self, category: dict) -> PublicID: """ Insert a single category into the system. Args: category (dict): Raw data of the category. Notes: If no public id was given, the database manager will auto insert the next available ID. Returns: int: The Public ID of the new inserted category """ if isinstance(category, CategoryModel): category = CategoryModel.to_json(category) return self._insert(self.collection, resource=category)
def update(self, public_id: Union[PublicID, int], category: Union[CategoryModel, dict]): """ Update a existing category in the system. Args: public_id (int): PublicID of the category in the system. category: New category data Notes: If a CategoryModel instance was passed as type argument, \ it will be auto converted via the model `to_json` method. """ if isinstance(category, CategoryModel): category = CategoryModel.to_json(category) update_result = self._update(self.collection, filter={'public_id': public_id}, resource=category) if update_result.matched_count != 1: raise ManagerUpdateError(f'Something happened during the update!') return update_result