Beispiel #1
0
    def getAllMessages(self):
        result = messageDAO().getAllMessages()
        mapped_result = []
        for r in result:
            mapped_result.append(self.mapToMsgDict(r))

        return jsonify(Messages=mapped_result)
Beispiel #2
0
 def getHashtagMessages(self, gid):
     result = messageDAO().getHashtagMessages(gid)
     mapped_result = []
     if not result:
         return jsonify(Error="NOT FOUND"), 404
     else:
         for r in result:
             mapped_result.append(self.mapToMsgDict(r))
         return jsonify(Messages=mapped_result)
Beispiel #3
0
 def getConversation(self, uid1, uid2):
     result = messageDAO().getConversation(uid1, uid2)
     mapped_result = []
     if not result:
         return jsonify(Error="NOT FOUND"), 404
     else:
         for r in result:
             mapped_result.append(self.mapToMsgDict(r))
         return jsonify(Messages=mapped_result)
Beispiel #4
0
    def getMessageByDate(self, date):
        result = messageDAO().getMessageByDate(date)
        mapped_result = []
        if not result:
            return jsonify(Error="NOT FOUND"), 404
        else:
            for r in result:
                mapped_result.append(self.mapToMsgDict(r))

            return jsonify(Messages=mapped_result)
Beispiel #5
0
    def getAllMessageBySenderId(self, uid):

        result = messageDAO().getAllMessageByUserId(uid)
        mapped_result = []
        if not result:
            return jsonify(Error="NOT FOUND"), 404
        else:
            for r in result:
                mapped_result.append(self.mapToMsgDict(r))

            return jsonify(Messages=mapped_result)
Beispiel #6
0
    def insertCredentialsJSON(self, json):

        uid = json.get('uid')

        mdate = json.get('mdate')

        minfo = json.get('minfo')

        if uid and mdate and minfo:
            mid = messageDAO().insert(mdate, minfo, uid)
            mapped_result = self.buildMsgDict(mid, mdate, minfo, uid)
            return jsonify(User=mapped_result), 201
        else:
            return jsonify(Error="Unexpected attributes in post request"), 404
Beispiel #7
0
 def insert(self, form):
     if len(form) != 4:
         return jsonify(Error="Malformed post request"), 400
     else:
         mdate = form['mdate']
         minfo = form['minfo']
         uid = form['uid']
         if mdate and minfo and uid:
             dao = messageDAO()
             mid = dao.insert(mdate, minfo, uid)
             result = self.build_messages_attributes(mid, mdate, minfo, uid)
             return jsonify(Message=result), 201
         else:
             return jsonify(
                 Error="Unexpected attributes in post request"), 400
Beispiel #8
0
 def updateMessages(self, uid, form):
     dao = messageDAO()
     if not dao.getAllMessageByUserId(uid):
         return jsonify(Error="User not found."), 404
     else:
         if len(form) != 4:
             return jsonify(Error="Malformed update request"), 400
         else:
             mid = form['mid']
             mdate = form['mdate']
             minfo = form['minfo']
             uid = form['uid']
             if mid and mdate and minfo and uid:
                 dao.update(mid, mdate, minfo, uid)
                 result = self.build_messages_attributes(
                     mid, mdate, minfo, uid)
                 return jsonify(Message=result), 201
             else:
                 return jsonify(
                     Error="Unexpected attributes in update request"), 400