class MessageNonCheckApi(Resource): def __init__(self): self.message_model = Messages() def get(self, you_id): result = self.message_model.check_new_messages(session['id'], you_id, checker=False) if result: for r in result: r['message_date'] = str(r['message_date']) return {'new_messages': result}, 200 else: return {}, 204
class MessageApi(Resource): def __init__(self): self.message_model = Messages() def get(self, you_id): result = self.message_model.check_new_messages(session['id'], you_id, checker=True) if result: for r in result: r['message_date'] = str(r['message_date']) return {'new_messages': result}, 200 else: return {}, 204 def post(self, you_id): result = self.message_model.add_new_message(session['id'], you_id, request.form['message']) if result: return {'id': session['id'], 'message_date': result}, 201 else: return {}, 204