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)
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
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)
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)
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)
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)
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)
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)
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)
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)
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)
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)
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)
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)
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)
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
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)
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)
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)
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)
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)
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)
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)
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)
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)
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)
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)
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)
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)
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)