Exemplo n.º 1
0
 def delete_lesson(self, member_id: str, lesson_id: str):
     with self._database_engine.new_session() as session:
         member_dao = MemberDAO(session)
         member = member_dao.get(member_id)
         lesson_dao = LessonDAO(session)
         lesson = lesson_dao.get(lesson_id)
         member_dao.delete_lesson(member, lesson, session)
Exemplo n.º 2
0
    def search_member(self, firstname, lastname):

        # Query database
        with self._database_engine.new_session() as session:
            member_dao = MemberDAO(session)
            member = member_dao.get_by_name(firstname, lastname)
            return member.to_dict()
Exemplo n.º 3
0
 def update_member(self, member_id: str, member_data: dict):
     self._check_profile_data(member_data, update=True)
     with self._database_engine.new_session() as session:
         member_dao = MemberDAO(session)
         member = member_dao.get(member_id)
         member = member_dao.update(member, member_data)
         return member.to_dict()
Exemplo n.º 4
0
 def search_member(self, email):
     # Query database
     with self._database_engine.new_session() as session:
         member_dao = MemberDAO(session)
         member = member_dao.get_by_email(email)
         if member == None:
             return None
         return member.to_dict()
Exemplo n.º 5
0
 def create_member(self, data):
     self.check_data(data)
     try:
         with self._database_engine.new_session() as session:
             # Save member in database
             member = MemberDAO(session).create(data)
             member_data = member.to_dict()
             return member_data
     except Error as e:
         return None
Exemplo n.º 6
0
 def create_member(self, data: dict):
     self._check_profile_data(data)
     try:
         with self._database_engine.new_session() as session:
             # Save sport in database
             member = MemberDAO(session).create(data)
             member_data = member.to_dict()
             return member_data
     except Error as e:
         # log error
         raise e
Exemplo n.º 7
0
    def create_member(self, data):

        self._check_profile_data(data)
        try:
            with self._database_engine.new_session() as session:
                # Save member in database
                member = MemberDAO(session).create(data)
                member_data = member.to_dict()
                return member_data
        except Error as e:
            # log error
            print("An Error occured (%s)" % str(e))
            raise e
Exemplo n.º 8
0
 def list_members(self):
     # Permit to attribute the "Session" class to the new session
     with self._database_engine.new_session() as session:
         members = MemberDAO(session).get_all()
         # To_dict is function  defined in model/mapping/member.py
         members_data = [member.to_dict() for member in members]
     return members_data
Exemplo n.º 9
0
    def get_dao(self, type=None):
        if type is None:
            return PersonDAO(self._database_session)

        if type == 'member':
            return MemberDAO(self._database_session)
        else:
            return PersonDAO(self._database_session)
Exemplo n.º 10
0
    def list_members(self):

        with self._database_engine.new_session() as session:
            members = MemberDAO(session).get_all()
            members_data = [member.to_dict() for member in members]

        ## ou
        session = self._database_engine.new_session()
        with session:
            members = MemberDAO(session).get_all()
            members_data = [member.to_dict() for member in members]

        ## ou alors
        session = self._database_engine.new_session()
        members = MemberDAO(session).get_all()
        members_data = [member.to_dict() for member in members]

        session.commit()
        session.close()

        return members_data
Exemplo n.º 11
0
    def delete_member(self, member_id):

        with self._database_engine.new_session() as session:
            member_dao = MemberDAO(session)
            member = member_dao.get(member_id)
            member_dao.delete(member)
Exemplo n.º 12
0
 def get_member(self, member_id):
     with self._database_engine.new_session() as session:
         member = MemberDAO(session).get(member_id)
         member_data = member.to_dict()
     return member_data
Exemplo n.º 13
0
 def list_members(self):
     with self._database_engine.new_session() as session:
         members = MemberDAO(session).get_all()
         members_data = [member.to_dict() for member in members]
     return members_data
Exemplo n.º 14
0
 def get_member_by_name(self, firstname: str, lastname: str):
     with self._database_engine.new_session() as session:
         member = MemberDAO(session).get_by_name(firstname, lastname)
         member_data = member.to_dict()
     return member_data
Exemplo n.º 15
0
 def update_member(self, member_id, member_data):
     with self._database_engine.new_session() as session:
         member_dao = MemberDAO(session)
         member = member_dao.get(member_id)
         member = member_dao.update(member, member_data)
         return member.to_dict()