def get(self, _to): messages = MessageModel.find_all(_to) counter = Counter.find_counter(_to) count = 0 if counter is not None: count = counter.count all = [] if messages: # TODO: FIX THIS TO SEND DATE TIME all = [m.json() for m in messages] return {'messages': all, 'count': count}, 200
def delete(self, _to): counter = Counter.find_counter(_to=_to) print("delete: counter:", counter) if counter is None: return {'message': "The counter doesn't exist"}, 404 try: counter.delete_from_db() except: return { "message": "An error occurred while deleting the item (count) in the database." }, 500 return {"message": "Count Deleted"}, 200
def post(self, _to): data = self.parser.parse_args() counter = Counter.find_counter(_to=_to) count = data["increase_by"] print("coutner", counter) print("count", count) if counter is not None: print("eyo") count += counter.count counter.delete_from_db() thought = Counter(_to, count) try: thought.save_to_db() except: return { "message": "An error occurred while saving the item (count) to the database." }, 500 return {"message": "Count increased"}, 200