Beispiel #1
0
def invite_user(data):
    if data['invited_user'] == data['username']:
        send({'msg': "Cannot invite yourself!"})
        raise ApplicationError("Can't invite yourself", 404)
    else:
        check = False
        if not search_and_invite(data['username'], data['invited_user'],
                                 data['room']):
            send({'msg': "User does not exist!"})
            raise ApplicationError("User doesn't exist", 404)
Beispiel #2
0
    def find_by_name(name):
        result = None
        mapped_names = {}
        mapped_images = {}

        with SQLite() as db:
            result = db.execute("SELECT * FROM VAs WHERE name = ?", name)
        va = result.fetchone()
        if va is None:
            raise ApplicationError("No character found", 404)

        with SQLite() as db:
            characters = db.execute(
                "SELECT characters.name, characters.image FROM VAs JOIN characters ON VAs.name = characters.VA WHERE VAs.name = ?",
                name).fetchall()

            anime = db.execute(
                "SELECT anime.title, anime.image FROM VAs JOIN characters ON VAs.name = characters.VA JOIN anime ON anime.title = characters.anime WHERE VAs.name = ?",
                name).fetchall()

        f = 0

        for i, j in zip(characters, anime):
            for i1, j1 in zip(i, j):
                if f == 1:
                    mapped_images[i1] = j1
                    break
                mapped_names[i1] = j1
                f = 1

        filename = ''.join(name)
        path = "./images/" + filename + ".jpg"

        return VA(*va, mapped_names, mapped_images, path)
Beispiel #3
0
 def update_choice(self, choice):
     result = None
     with SQLite() as db:
         result = db.execute("UPDATE user SET choice = ? WHERE id = ?",
                             (choice, self.id))
     if result.rowcount == 0:
         raise ApplicationError("No user present", 404)
Beispiel #4
0
 def update_rating_by_name(rating, name):
     result = None
     with SQLite() as db:
         result = db.execute("UPDATE user SET rating = ? WHERE name = ?",
                             (rating, name))
     if result.rowcount == 0:
         raise ApplicationError("No user present", 404)
Beispiel #5
0
    def find_by_title(title):
        result = None
        mapped_names = {}
        mapped_images = {}

        with SQLite() as db:
            result = db.execute("SELECT * FROM anime WHERE title = ?", title)

        anime = result.fetchone()

        if anime is None:
            raise ApplicationError("Anime not found", 404)

        with SQLite() as db:
            characters = db.execute(
                "SELECT characters.name, characters.image FROM anime JOIN characters ON anime.title = characters.anime WHERE title = ?",
                title).fetchall()

            #            characters = db.execute("SELECT characters.name, characters.image FROM characters WHERE anime = ?", title).fetchall()

            VAs = db.execute(
                "SELECT VAs.name, VAs.image FROM anime JOIN characters ON anime.title = characters.anime JOIN VAs ON VAs.name = characters.VA WHERE title = ?",
                title).fetchall()

        f = 0

        for i, j in zip(characters, VAs):
            for i1, j1 in zip(i, j):
                if f == 1:
                    mapped_images[i1] = j1
                    break
                mapped_names[i1] = j1
                f = 1

        return Anime(*anime, mapped_names, mapped_images)
Beispiel #6
0
 def delete(question_tag_id):
     result = None
     with SQLite() as db:
         result = db.execute("DELETE FROM question_tag WHERE id = ?",
                             (question_tag_id, ))
     if result.rowcount == 0:
         raise ApplicationError("No value present", 404)
Beispiel #7
0
 def create_user(user, password, email, address, phone_number):
     result = None
     with SQLite() as db:
         result = db.execute("INSERT INTO user (username, password, email, address, phone_number) VALUES (?, ?, ?, ?, ?)",
                 (user, password, email, address, phone_number,))
     if result.rowcount == 0:
         raise ApplicationError("No value present", 404)
Beispiel #8
0
 def update_match(match, name):
     result = None
     with SQLite() as db:
         result = db.execute("UPDATE user SET match = ? WHERE name = ?",
                             (match, name))
     if result.rowcount == 0:
         raise ApplicationError("No user present", 404)
Beispiel #9
0
 def update_rating(self, rating):
     result = None
     with SQLite() as db:
         result = db.execute("UPDATE user SET rating = ? WHERE id = ?",
                             (rating, self.id))
     if result.rowcount == 0:
         raise ApplicationError("No user present", 404)
Beispiel #10
0
 def update_answer_by_content(answer, content):
     result = None
     with SQLite() as db:
         result = db.execute(
             "UPDATE question SET answer = ? WHERE content = ?",
             (answer, content))
     if result.rowcount == 0:
         raise ApplicationError("No question present", 404)
 def find_by_anime(anime):
     result = None
     with SQLite() as db:
         result = db.execute("SELECT * FROM characters WHERE anime = ?",
                             anime)
     characters = result.fetchall()
     if characters is None:
         raise ApplicationError("No characters found", 404)
     return [Character(*row) for row in characters]
 def find_by_name(name):
     result = None
     with SQLite() as db:
         result = db.execute("SELECT * FROM characters WHERE name = ?",
                             name)
     character = result.fetchone()
     if character is None:
         raise ApplicationError("No character found", 404)
     return Character(*character)
Beispiel #13
0
 def find_by_email(email):
     result = None
     with SQLite() as db:
         result = db.execute("SELECT * FROM user WHERE email = ?",
                             (email, ))
     user = result.fetchone()
     if user is None:
         raise ApplicationError(
             "User with email {} not found".format(email), 404)
     return User(*user)
Beispiel #14
0
    def find_by_studio(studio):
        result = None
        with SQLite() as db:
            result = db.execute("SELECT * FROM anime WHERE studio = ?",
                                (studio, ))

        anime = result.fetchall()
        if anime is None:
            raise ApplicationError("Anime not found", 404)
        return anime
Beispiel #15
0
 def find_by_id(id):
     result = None
     with SQLite() as db:
         result = db.execute(
             "SELECT user_id, title, description, price, date, isActive, buyer FROM ads WHERE id = ?",
             (id, ))
     ad = result.fetchone()
     if ad is None:
         raise ApplicationError("Ad with id {} not found".format(ad), 404)
     return Ad(*ad)
Beispiel #16
0
 def find_by_username(username):
     result = None
     with SQLite() as db:
         result = db.execute(
                 "SELECT id, email, password, username, address, phone_number FROM user WHERE username = ?",
                 (username,))
     user = result.fetchone()
     if user is None:
         raise ApplicationError(
                 "Post with name {} not found".format(username), 404)
     return User(*user)
Beispiel #17
0
 def find_by_name(name):
     result = None
     with SQLite() as db:
         result = db.execute(
                 "SELECT is_private, name, id FROM rooms WHERE name = ?",
                 (name,))
     room = result.fetchone()
     if room is None:
         raise ApplicationError(
                 "Room with name {} not found".format(name), 404)
     return Room(*room)
Beispiel #18
0
 def find(question_id):
     result = None
     with SQLite() as db:
         result = db.execute(
             "SELECT content, answer, user, category, id FROM question WHERE id = ?",
             (question_id, ))
     question = result.fetchone()
     if question is None:
         raise ApplicationError(
             "Question with id {} not found".format(question_id), 404)
     return Question(*question)
Beispiel #19
0
 def find(user_id):
     result = None
     with SQLite() as db:
         result = db.execute(
             "SELECT email, password, name, adress, mobile_number, id FROM user WHERE id = ?",
             (user_id, ))
     user = result.fetchone()
     if user is None:
         raise ApplicationError("User with id {} not found".format(user_id),
                                404)
     return User(*user)
Beispiel #20
0
 def find_by_room(room_name):
     result = None
     with SQLite() as db:
         result = db.execute(
             "SELECT room_name, username, id FROM invites WHERE room_name = ?",
             (room_name, ))
     invite = result.fetchone()
     if invite is None:
         raise ApplicationError(
             "Invite for room {} not found".format(room_name), 404)
     return Invite(*invite)
Beispiel #21
0
 def find_by_name(name):
     result = None
     with SQLite() as db:
         result = db.execute(
             "SELECT name, password, room, description, picture_location, id FROM user WHERE name = ?",
             (name, ))
     user = result.fetchone()
     if user is None:
         raise ApplicationError("User with name {} not found".format(name),
                                404)
     return User(*user)
Beispiel #22
0
 def find(post_id):
     result = None
     with SQLite() as db:
         result = db.execute(
             "SELECT title, content, id FROM post WHERE id = ?",
             (post_id, ))
     post = result.fetchone()
     if post is None:
         raise ApplicationError("Post with id {} not found".format(post_id),
                                404)
     return Post(*post)
Beispiel #23
0
 def find_by_email(email):
     result = None
     with SQLite() as db:
         result = db.execute(
                 "SELECT username, password,  email, address, phone_number, user_id FROM user WHERE email = ?",
                 (email,))
     user = result.fetchone()
     if user is None:
         raise ApplicationError(
                 "User with name {} not found".format(username), 404)
     return User(*user)
Beispiel #24
0
 def find(question_tag_id):
     result = None
     with SQLite() as db:
         result = db.execute(
             "SELECT question_id, tag_id, id FROM question_tag WHERE id = ?",
             (question_tag_id, ))
     tag = result.fetchone()
     if tag is None:
         raise ApplicationError(
             "Tag with id {} not found".format(question_tag_id), 404)
     return Question_tag(*tag)
Beispiel #25
0
 def find(ad_id):
     result = None
     with SQLite() as db:
         result = db.execute(
             "SELECT title, content, price, release_date, is_active, buyer_id, creator_id, id FROM ad WHERE id = ?",
             (ad_id, ))
     ad = result.fetchone()
     if ad is None:
         raise ApplicationError("Ad with id {} not found".format(ad_id),
                                404)
     return Ad(*ad)
Beispiel #26
0
 def find_by_id(id):
     result = None
     with SQLite() as db:
         result = db.execute(
                 "SELECT id, email, username, password, adress or phone FROM user WHERE id = ?",
                 (id,))
     user = result.fetchone()
     if user is None:
         raise ApplicationError(
                 "Post with name {} not found".format(username), 404)
     return User(*user)
Beispiel #27
0
 def find(user_id):
     result = None
     with SQLite() as db:
         result = db.execute(
                 "SELECT username, password, id FROM user WHERE id = ?",
                 (user_id,))
     user = result.fetchone()
     if user is None:
         raise ApplicationError(
                 "Post with id {} not found".format(user_id), 404)
     return User(*user)
Beispiel #28
0
    def find_by_id(ad_id):
        result = None
        with SQLite() as db:
            result = db.execute(
                "SELECT creator_id, title, desc, price, date, buyer, is_available, ad_id FROM ad WHERE ad_id = ?",
                (ad_id, ))

        ad = result.fetchone()
        if ad is None:
            raise ApplicationError("Ad with id {} not found".format(ad_id),
                                   404)
        return Ad(*ad)
Beispiel #29
0
    def find_all_purchased(creator_id):
        result = None
        with SQLite() as db:
            result = db.execute(
                "SELECT ad_id, title, desc, price, date, buyer FROM ad WHERE (creator_id = ? AND is_available = ?)",
                (creator_id, 0))

        ad = result.fetchall()
        if ad is None:
            raise ApplicationError(
                "User with id {} has no ads".format(creator_id), 404)
        return ad
Beispiel #30
0
    def edit(user_id, part_to_edit, value):
        if part_to_edit=="email" or part_to_edit=="password":
            raise ApplicationError("You can't change your email or password",404)
        elif part_to_edit=="username":
            with SQLite() as db:
                result = db.execute(
                    "UPDATE user SET username = ? WHERE id = ?;",
                    (value, user_id,))

        elif part_to_edit=="address":
            with SQLite() as db:
                result = db.execute(
                    "UPDATE user SET address = ? WHERE id = ?;",
                    (value, user_id,))

        elif part_to_edit=="phone_number":
            with SQLite() as db:
                result = db.execute(
                    "UPDATE user SET phone_number = ? WHERE id = ?;",
                    (value, user_id,))   
        else:
            raise ApplicationError("{} doesnt exist".format(part_to_edit),404)