def get(self, id): user = User.get(id=id) if not user: return Response(status=404) complaints = Complaint.select(lambda c: c.complainer == user) return jsonify(list(c.to_dict() for c in complaints))
def get(self, user_id): user = User.get(id=user_id) if not user: return Response(status=404) subscriptions = list( map(lambda s: s.to_dict(), user.subscribed_opencalls)) return jsonify(subscriptions)
def seed_database(dump_filename): # reading the json file data = json.load(open(dump_filename, 'r')) # going through the list of customers for record in data['User']: User(id=record['id'], login=record['login'], password=record['password']) for record in data['Label']: Label(id=record['id'], name=record['name']) for record in data['City']: City(id=record['id'], name=record['name']) for record in data['Complaint']: labels = select(l for l in Label if l.id in record['labels']) city = City.get(id=record['city']) subscribers = select(u for u in User if u.id in record['subscribers']) Complaint(title=record['title'], description=record['description'], complainer=User.get(id=record['complainer']), city=city, subscribers=subscribers, labels=labels) for record in data['OpenCall']: labels = select(l for l in Label if l.id in record['labels']) city = City.get(id=record['city']) subscribers = select(u for u in User if u.id in record['subscribers']) OpenCall(title=record['title'], description=record['description'], creator=User.get(id=record['creator']), city=city, subscribers=subscribers, labels=labels) for record in data['Vote']: Vote(user=User.get(id=record['user']), complaint=Complaint.get(id=record['complaint']), is_upvote=record['is_upvote'])
def post(self, user_id, c_id): opencall = OpenCall.get(id=c_id) if not opencall: return Response(status=404) user = User.get(id=user_id) if not user: return Response(status=404) opencall.subscribed_opencalls.add(user) commit() return Response(status=200)
def post(self, user_id, c_id): complaint = Complaint.get(id=c_id) if not complaint: return Response(status=404) user = User.get(id=user_id) if not user: return Response(status=404) complaint.subscribed_complaints.add(user) commit() return Response(status=200)
def post(self, id): data = json.loads(request.data) labels = select(l for l in Label if l.id in data['labels']) city = City.get(id=data['city']) if not city: return Response(status=404) opencall = OpenCall(title=data['title'], description=data['description'], creator=User.get(id=data['creator']), city=city, labels=labels) commit() return jsonify(opencall.to_dict())
def post(self, id): data = json.loads(request.data) labels = select(l for l in Label if l.id in data['labels']) city = City.get(id=data['city']) if not city: return Response(status=404) complaint = Complaint(title=data['title'], description=data['description'], complainer=User.get(id=data['complainer']), city=city, labels=labels) commit() return jsonify(complaint.to_dict_sums())
def delete(self, user_id, c_id): complaint = Complaint.get(id=c_id) if not complaint: return Response(status=404) user = User.get(id=user_id) if not user: return Response(status=404) vote = Vote.select( lambda v: v.user == user and v.complaint == complaint) vote.delete() commit() return Response(status=200)
def post(self, user_id, c_id): complaint = Complaint.get(id=c_id) if not complaint: return Response(status=404) user = User.get(id=user_id) if not user: return Response(status=404) data = json.loads(request.data) is_upvote = data['is_upvote'] vote = Vote(user=user, complaint=complaint, is_upvote=is_upvote) commit() return jsonify(vote.to_dict())
def post(self, user_id, c_id): complaint = Complaint.get(id=c_id) if not complaint: return Response(status=404) user = User.get(id=user_id) if not user: return Response(status=404) data = json.loads(request.data) text = data['text'] feedback = ComplaintFeedback(user=user, complaint=complaint, text=text) commit() return jsonify(feedback.to_dict())
def post(self, user_id, o_id): opencall = OpenCall.get(id=o_id) if not opencall: return Response(status=404) user = User.get(id=user_id) if not user: return Response(status=404) data = json.loads(request.data) text = data['text'] feedback = OpenCallFeedback(user=user, opencall=opencall, text=text) commit() return jsonify(feedback.to_dict())
def get(self, user_id): user = User.get(id=user_id) if not user: return Response(status=404) upvotes = select(c for c in Complaint if user in c.votes.user and True in c.votes.is_upvote) downvotes = select( c for c in Complaint if user in c.votes.user and False in c.votes.is_upvote) other = Complaint.select( lambda c: c not in upvotes and c not in downvotes) upvote_dict = [u.to_dict_vote(True) for u in upvotes] downvote_dict = [u.to_dict_vote(False) for u in downvotes] other_dict = [u.to_dict_vote(None) for u in other] return jsonify(upvote_dict + downvote_dict + other_dict)
def get(self, id): user = User.get(id=id) if not user: return Response(status=404) return jsonify(user.to_dict())