Exemple #1
0
 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()
Exemple #2
0
 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)
Exemple #3
0
    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()
Exemple #4
0
 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)
Exemple #5
0
 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)
Exemple #6
0
 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()
Exemple #7
0
    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()
Exemple #8
0
 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()
Exemple #9
0
 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
Exemple #10
0
    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
Exemple #11
0
 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()
Exemple #12
0
 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()
Exemple #13
0
    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
Exemple #14
0
    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
Exemple #15
0
 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
Exemple #16
0
 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)
Exemple #17
0
 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)
Exemple #18
0
 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
Exemple #19
0
 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
Exemple #20
0
 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