def update_sport(self, sport_id: str, sport_data: dict): self._check_profile_data(sport_data, update=True) with self._database_engine.new_session() as session: sport_dao = SportDAO(session) sport = sport_dao.get(sport_id) sport = sport_dao.update(sport, sport_data) return sport.to_dict()
def delete_sport_lesson(self, lesson_id: str, sport_id: str): with self._database_engine.new_session() as session: lesson_dao = LessonDAO(session) lesson = lesson_dao.get(lesson_id) sport_dao = SportDAO(session) sport = sport_dao.get(sport_id) lesson_dao.delete_sport(lesson, sport, session)
def search_sport(self, name): # Query database with self._database_engine.new_session() as session: sport_dao = SportDAO(session) sport = sport_dao.get_by_name(name) return sport.to_dict()
def add_person_sport(self, person_id, sport_id, level): with self._database_engine.new_session() as session: person_dao = PersonDAO(session) person = person_dao.get(person_id) sport_dao = SportDAO(session) sport = sport_dao.get(sport_id) person.add_sport(sport, level, session)
def delete_person_sport(self, person_id, sport_id): with self._database_engine.new_session() as session: person_dao = PersonDAO(session) person = person_dao.get(person_id) sport_dao = SportDAO(session) sport = sport_dao.get(sport_id) person.delete_sport(sport, session)
def search_sport(self, name): logging.info("Search sport %s" % name) # Query database with self._database_engine.new_session() as session: dao = SportDAO(session) sport = dao.get_by_name(name) return sport.to_dict()
def update_sport(self, sport_id, sport_data): with self._database_engine.new_session() as session: sport_dao = SportDAO(session) sport = sport_dao.get(sport_id) sport = sport_dao.update(sport, sport_data) return sport.to_dict()
def update_sport(self, sport_id, sport_data): logging.info("Update sport %s with data: %s" % (sport_id, str(sport_data))) self._check_sport_data(sport_data, update=True) with self._database_engine.new_session() as session: dao = SportDAO(session) sport = dao.get(sport_id) sport = dao.update(sport, sport_data) return sport.to_dict()
def create_sport(self, data): self._check_sport_data(data) try: with self._database_engine.new_session() as session: dao = SportDAO(session) sport = dao.create(data) sport_data = sport.to_dict() return sport_data except Error as e: raise e
def create_sport(self, data): try: with self._database_engine.new_session() as session: # Save sport in database sport = SportDAO(session).create(data) sport_data = sport.to_dict() return sport_data except Error as e: # log error raise e
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 create_sport(self, data): logging.info("Create sport with data %s" % str(data)) self._check_sport_data(data) sport_name = data['name'] sports = self.list_sports() if sport_name in [sport['name'] for sport in sports]: raise Error("Sport '%s' already exist" % sport_name) try: with self._database_engine.new_session() as session: # Save member in database dao = SportDAO(session) sport = dao.create(data) sport_data = sport.to_dict() return sport_data except Error as e: # log error logging.error("An Error occured (%s)" % str(e)) raise e
def list_sports(self): with self._database_engine.new_session() as session: sports = SportDAO(session).get_all() sports_data = [sport.to_dict() for sport in sports] ## ou session = self._database_engine.new_session() with session: sports = SportDAO(session).get_all() sports_data = [sport.to_dict() for sport in sports] ## ou alors session = self._database_engine.new_session() sports = SportDAO(session).get_all() sports_data = [sport.to_dict() for sport in sports] session.commit() session.close() return sports_data
def get_sport(self, sport_id): logging.info("Get sport %s" % sport_id) with self._database_engine.new_session() as session: sport = SportDAO(session).get(sport_id) sport_data = sport.to_dict() return sport_data
def delete_sport(self, sport_id): with self._database_engine.new_session() as session: dao = SportDAO(session) sport = dao.get(sport_id) dao.delete(sport)
def delete_sport(self, sport_id): logging.info("Delete person %s" % sport_id) with self._database_engine.new_session() as session: dao = SportDAO(session) sport = dao.get(sport_id) dao.delete(sport)
def get_sport(self, sport_id): with self._database_engine.new_session() as session: sport = SportDAO(session).get(sport_id) sport_data = sport.to_dict() return sport_data
def list_sports(self): with self._database_engine.new_session() as session: sports = SportDAO(session).get_all() sports_data = [sport.to_dict() for sport in sports] return sports_data
def get_sport_by_name(self, name: str): with self._database_engine.new_session() as session: sport = SportDAO(session).get_by_name(name) sport_data = sport.to_dict() return sport_data