Example #1
0
 def test_get_join_by_user_1(self) -> None:
     """
     test get_join_by_user: user exists
     """
     Join.create_join(Join(self.user, self.event))
     joins = Join.get_join_by_user(self.user)
     events = [join.event for join in joins]
     self.assertListEqual(events, [self.event])
Example #2
0
 def test_get_join_by_user_2(self) -> None:
     """
     test get_join_by_user: user doesn't exist
     """
     Join.create_join(Join(self.user, self.event))
     joins = Join.get_join_by_user('')
     events = [join.event for join in joins]
     self.assertListEqual(events, [])
Example #3
0
    def get_all_event_liked_by_user(email: str):
        """

        :param email: Email of user
        :return: A list of events which is liked by user.
        """
        joins = Join.get_join_by_user(email)
        joined_events = set(join.event for join in joins)

        cnx = db_connector.get_connection()
        cursor = cnx.cursor()
        query = ("SELECT * FROM `event` WHERE `id` "
                 "IN (SELECT `event` FROM `like` WHERE `user` = '" + email +
                 "');")
        cursor.execute(query)
        events = []
        for (event_id, name, host, address, longitude, latitude, zipcode,
             event_time, description, image, num_likes, category) in cursor:
            new_event = Event(user=host,
                              name=name,
                              address=address,
                              longitude=longitude,
                              latitude=latitude,
                              zipcode=zipcode,
                              event_time=datetime.datetime.strptime(
                                  str(event_time), "%Y-%m-%d %H:%M:%S"))
            new_event.event_id = event_id
            new_event.description = description
            new_event.image = image
            new_event.num_likes = num_likes
            new_event.liked = True
            new_event.category = category
            if event_id in joined_events:
                new_event.attended = True
            events.append(new_event)
        cursor.close()
        cnx.close()
        return events