def get_person(self, person_id, person_type=None): logging.info("Get person %s" % person_id) with self._database_engine.new_session() as session: dao = PersonDAOFabric(session).get_dao(type=person_type) member = dao.get(person_id) member_data = member.to_dict() return member_data
def list_people(self, person_type=None): logging.info("Get people") with self._database_engine.new_session() as session: dao = PersonDAOFabric(session).get_dao(type=person_type) members = dao.get_all() members_data = [member.to_dict() for member in members] return members_data
def search_person(self, firstname, lastname, person_type=None): logging.info("Search person %s %s" % (firstname, lastname)) # Query database with self._database_engine.new_session() as session: dao = PersonDAOFabric(session).get_dao(type=person_type) member = dao.get_by_name(firstname, lastname) return member.to_dict()
def delete_sport_person(self, person_id, sport_id): logging.info("Delete sport %s from user %s" % (person_id, sport_id)) with self._database_engine.new_session() as session: dao = PersonDAOFabric(session).get_dao() person = dao.get(person_id) sport = SportDAO(session).get(sport_id) person.delete_sport(sport, session) return person.to_dict()
def add_sport_person(self, person_id, sport_id, level): logging.info("Add sport %s to person %s" % (sport_id, person_id)) with self._database_engine.new_session() as session: dao = PersonDAOFabric(session).get_dao() person = dao.get(person_id) sport = SportDAO(session).get(sport_id) person.add_sport(sport, level, session) return person.to_dict()
def _update_person(self, member_id, member_data, person_type=None): logging.info("Update %s with data: %s" % (member_id, str(member_data))) with self._database_engine.new_session() as session: dao = PersonDAOFabric(session).get_dao(type=person_type) person = dao.get(member_id) person = dao.update(person, member_data) return person.to_dict()
def create_person(self, data, person_type=None): logging.info("Create member with data %s" % str(data)) self._check_person_data(data) try: with self._database_engine.new_session() as session: # Save member in database dao = PersonDAOFabric(session).get_dao(type=person_type) member = dao.create(data) member_data = member.to_dict() return member_data except Error as e: # log error logging.error("An Error occured (%s)" % str(e)) raise e
def delete_person(self, member_id, person_type=None): logging.info("Delete person %s" % member_id) with self._database_engine.new_session() as session: dao = PersonDAOFabric(session).get_dao(type=person_type) member = dao.get(member_id) dao.delete(member)