def insertReactionJson(self, json): rdate = json['rdate'] reaction = json['reaction'] pid = json['pid'] uid = json['uid'] if rdate and reaction and pid and uid: dao = ReactionsDAO() rid = dao.insert(rdate, reaction, pid, uid) result = self.build_reaction_attributes(rid, rdate, reaction, pid, uid) return jsonify(Reaction=result), 201 else: return jsonify(Error="Unexpected attributes in post request"), 400
def updatereaction(self, rid, form): dao = ReactionsDAO() if not dao.getReactionsById(rid): return jsonify(Error="reaction not found."), 404 else: if len(form) != 2: return jsonify(Error="Malformed update request"), 400 else: rdate = form['rdate'] reaction = form['reaction'] if rdate and reaction: dao.update(rid, rdate, reaction) result = self.build_reaction_attributes( rid, rdate, reaction) return jsonify(reaction=result), 200 else: return jsonify( Error="Unexpected attributes in update request"), 400
def insertReaction(self, form): print("form: ", form) if len(form) != 4: return jsonify(Error="Malformed post request"), 400 else: rdate = form['rdate'] reaction = form['reaction'] pid = form['pid'] uid = form['uid'] if rdate and reaction and pid and uid: dao = ReactionsDAO() rid = dao.insert(rdate, reaction, pid, uid) result = self.build_reaction_attributes( rid, rdate, reaction, pid, uid) return jsonify(Reaction=result), 201 else: return jsonify( Error="Unexpected attributes in post request"), 400
def searchreaction(self, args): id = args.get("id") date = args.get("date") dao = ReactionsDAO() reactions_list = [] if (len(args) == 2) and id and date: reactions_list = dao.getReactionsByIdAndDate(id, date) elif (len(args) == 1) and id: reactions_list = dao.getReactionsById(id) elif (len(args) == 1) and date: reactions_list = dao.getReactionsBydate(date) else: return jsonify(Error="Malformed query string"), 400 result_list = [] for row in reactions_list: result = self.build_reaction_dict(row) result_list.append(result) return jsonify(Reactions=result_list)
def getCountByReactionId(self): dao = ReactionsDAO() result = dao.getCountByReactionId() #print(self.build_reaction_counts(result)) return jsonify(reactionCounts=self.build_reaction_counts(result)), 200
def deleteReactionByPidAndUid(self, pid, uid): dao = ReactionsDAO() dao.deleteReactionByPidAndUid(pid, uid) return jsonify(DeleteStatus="OK"), 200