Beispiel #1
0
def getMessageByID(mID):
    # This method return the message requested by its ID
    row = dao.getMessageInfo(mID)
    if not row:
        return jsonify(Error="Message not found"), 404
    message = Dic.build_message_dict(row)
    return jsonify(Message=message)
Beispiel #2
0
def addUser(json):
    #This method adds a need user of the app to the system
    if len(json) != 7:
        return jsonify(Error="Missing information for registration")
    else:
        fname = json['fname']
        lname = json['lname']
        pseudonym = json['pseudonym']
        username = json['username']
        password = json['password']
        uemail = json['uemail']
        uphone = json['uphone']

        if fname and lname and pseudonym and username and password and uemail and uphone:
            test = dao.getUserByUsernameOrEmail(username, uemail)
            if test:
                return jsonify(Error='User already exists.')
            uid = dao.addUser(fname, lname, pseudonym)
            void = dao.addCredentials(uid, username, password, uemail, uphone)
            utime = dao.addActivity(uid)
            if uid:
                result = DictionaryBuilder.build_user_dict(
                    [uid, fname, lname, utime, pseudonym])
                return jsonify(User=result)
            else:
                return jsonify(Error='InsertFailed')
        else:
            return jsonify(Error='Unexpected attributes in post request'), 400
Beispiel #3
0
def getUserMessages(uID):
    result = dao.getAllUserMessages(uID)
    if not result:
        return jsonify(Error="No Messages Found")
    mapped_result = []
    for r in result:
        mapped_result.append(Dic.build_message_dict(r))
    return jsonify(UserMessages=mapped_result)
Beispiel #4
0
def getUserReactions(uID):
    result = dao.getAllReactionsByUser(uID)
    if not result:
        return jsonify(Error="No Reactions Found")
    mapped_result = []
    for r in result:
        mapped_result.append(Dic.build_reacted_dict(r))
    return jsonify(UserReactions=mapped_result)
Beispiel #5
0
def getAllActiveChats():
    result = dao.getAllActiveChats()
    if not result:
        return jsonify(Error="No Chats Found")
    mapped_result = []
    for r in result:
        mapped_result.append(Dic.build_chat_dict(r))
    return jsonify(Chats=mapped_result)
Beispiel #6
0
def getChatAsMember(uID):
    result = dao.getChatAsMember(uID)
    if not result:
        return jsonify(Error="No Chats Found")
    mapped_result = []
    for r in result:
        mapped_result.append(Dic.build_participants_dict(r))
    return jsonify(MemberChats=mapped_result)
Beispiel #7
0
def getAllTopicsByUser(uID):
    result = dao.getAllTopicsByUser(uID)
    if not result:
        return jsonify(Error="No Topics Found")
    mapped_result = []
    for r in result:
        mapped_result.append(Dic.build_topic_dict(r))
    return jsonify(UserTopics=mapped_result)
Beispiel #8
0
def getAllTopics():
    rows = dao.getAllTopics()
    if not rows:
        return jsonify(Error="No topics"), 404
    result = []
    for row in rows:
        result.append(Dic.build_topic_dict(row))
    return jsonify(Topics=result)
Beispiel #9
0
def getUsersCreatedBetween(bDate, aDate):
    result = dao.getUsersCreatedBetween(bDate, aDate)
    if not result:
        return jsonify(Error="No Users Found")
    mapped_result = []
    for r in result:
        mapped_result.append(DictionaryBuilder.build_user_dict(r))
    return jsonify(UserCreated=mapped_result)
Beispiel #10
0
def getAllLikes():
    rows = dao.getAllLikes()
    if not rows:
        return jsonify(Error="No reaction"), 404
    result = []
    for row in rows:
        result.append(Dic.build_reacted_dict(row))
    return jsonify(Reacts=result)
Beispiel #11
0
def getUserByNameAndEmail(fName, lName, uemail):
    result = dao.getUserByNameAndEmail(fName, lName, uemail)
    if not result:
        return jsonify(Error="No User Found")
    mapped_result = []
    for r in result:
        mapped_result.append(DictionaryBuilder.build_credential_dict(r))
    return jsonify(Users=mapped_result)
Beispiel #12
0
def getChatByID(cID):
    # This method will return the determined chat by its ID
    desired_chat = dao.getChatByID(cID)
    if not desired_chat:
        return jsonify(Error=" Chat not found"), 404

    chat = Dic.build_chat_dict(desired_chat)
    return jsonify(Chat=chat)
Beispiel #13
0
def getUserContacts(uID):
    result = dao.getUserContacts(uID)
    if not result:
        return jsonify(Error="No Contacts Found")
    mapped_result = []
    for r in result:
        mapped_result.append(DictionaryBuilder.build_contact_dict(r))
    return jsonify(UserContacts=mapped_result)
Beispiel #14
0
def getAllCredentials():
    result = dao.getAllCredentials()
    if not result:
        return jsonify(Error="No Credentials Found")
    mapped_result = []
    for r in result:
        mapped_result.append(DictionaryBuilder.build_credential_dict(r))
    return jsonify(Credentials=mapped_result)
Beispiel #15
0
def getAllActivity():
    result = dao.getAllActivity()
    if not result:
        return jsonify(Error="No Activity Found")
    mapped_result = []
    for r in result:
        mapped_result.append(DictionaryBuilder.build_activity_dict(r))
    return jsonify(Activity=mapped_result)
Beispiel #16
0
def usersPerDayHelper(day, oneday):
    usersinday = []
    topics = dao.getUsersPerDay(day - oneday, day)
    for row in topics:
        result = DictionaryBuilder.build_dash_user_dict(row)
        print(result)
        usersinday.append(result)
    return usersinday
Beispiel #17
0
def getTopTopics():
    toptopics = []
    topics = dao.getTopTopics()
    for row in topics:
        result = Dic.build_dash_topic_dict(row)
        print(result)
        toptopics.append(result)
    return jsonify(Topics=toptopics)
Beispiel #18
0
def getMembersByChatID(cid):
    result = dao.getMembersByChatID(cid)
    if not result:
        return jsonify(Error="No Members Found")
    mapped_result = []
    for r in result:
        mapped_result.append(DictionaryBuilder.build_user_dict(r))
    return jsonify(Users=mapped_result)
Beispiel #19
0
def getAllMessages():
    rows = dao.getAllMessages()
    if not rows:
        return jsonify(Error="No Message found"), 404
    result = []
    for row in rows:
        result.append(Dic.build_extended_message_dict(row))
    return jsonify(Messages=result)
Beispiel #20
0
def getUserByEmailAndPassword(uemail, password):
    result = dao.getUserByEmailAndPassword(uemail, password)
    if not result:
        return jsonify(Error="No User Found")
    mapped_result = []
    for r in result:
        mapped_result.append(DictionaryBuilder.build_credential_dict(r))
    return jsonify(Users=mapped_result)
Beispiel #21
0
def getChatAsAdmin(uID):
    result = dao.getChatsAsAdmin(uID)
    if not result:
        return jsonify(Error="No Chats Found")
    mapped_result = []
    for r in result:
        mapped_result.append(Dic.build_chat_dict(r))
    return jsonify(AdminChats=mapped_result)
Beispiel #22
0
def getAllMedias():
    rows = dao.getAllMedia()
    if not rows:
        return jsonify(Error="No media"), 404
    result = []
    for row in rows:
        result.append(Dic.build_media_dict(row))
    return jsonify(Medias=result)
Beispiel #23
0
def getActiveUsers():
    result = dao.getAllUsersByActivity()
    if not result:
        return jsonify(Error="No Active Users Found")
    mapped_result = []
    for r in result:
        mapped_result.append(DictionaryBuilder.build_user_dict(r))
    return jsonify(ActiveUsers=mapped_result)
Beispiel #24
0
def getUsersByDislikedMessage(mid):
    result = dao.getUsersByDislikedMessage(mid)
    if not result:
        return jsonify(Error="No Users Found")
    mapped_result = []
    for r in result:
        mapped_result.append(DictionaryBuilder.build_user_dict(r))
    return jsonify(Users=mapped_result)
Beispiel #25
0
def getMessageMedia(mID):
    # This method return the reaction of a determined message
    rows = dao.getMessageMedia(mID)
    if not rows:
        return jsonify(Error="Message does not contain Media"), 404
    result = []
    for row in rows:
        result.append(Dic.build_media_dict(row))
    return jsonify(Media=result)
Beispiel #26
0
def getChatTopicByID(cid):
    media = dao.getAllTopicsInChat(cid)
    if not media:
        return jsonify(Error="No Topic Found")
    result_list = []
    for row in media:
        result = Dic.build_topic_dict(row)
        result_list.append(result)
    return jsonify(Topic=result_list)
Beispiel #27
0
def getAllReactionsInMessage(mID):
    # This method return the reaction of a determined message
    rows = dao.getAllReactionsInMessage(mID)
    if not rows:
        return jsonify(Error="Message does not contain reaction"), 404
    result = []
    for row in rows:
        result.append(Dic.build_reacted_dict(row))
    return jsonify(Reaction=result)
Beispiel #28
0
def getMessageTopics(mID):
    # This method return the reaction of a determined message
    rows = dao.getAllTopicsInMessage(mID)
    if not rows:
        return jsonify(Error="Message does not contain Topics"), 404
    result = []
    for row in rows:
        result.append(Dic.build_topic_dict(row))
    return jsonify(Topics=result)
Beispiel #29
0
def getAllMediaByUser(uid):
    media = dao.getAllMediaByUser(uid)
    if not media:
        return jsonify(Error="No Media Found")
    result_list = []
    for row in media:
        result = Dic.build_media_dict(row)
        result_list.append(result)
    return jsonify(Media=result_list)
Beispiel #30
0
def getAllChatactiveMessages(cID):
    # This method will return the messages in a determined  chat
    chat_messages = dao.getAllChatActiveMessages(cID, 'false')
    if not chat_messages:
        return jsonify(Error="No Messages Found")
    result_messages = []
    for row in chat_messages:
        result = Dic.build_message_dict(row)
        result_messages.append(result)
    return jsonify(Messages=result_messages)