def on_get(self, req, resp, expense_id): """ Implements class contract for GET """ try: expense = ExpenseAService.select_expense(self.session.user, unicode(expense_id)) except ResourceNotFoundException: raise falcon.HTTPNotFound() resp.status = falcon.HTTP_200 resp.body = serializers.EXPENSE_ENTITY_SERIALIZER.dumps(expense, many=False).data
def on_post(self, req, resp): """ Implements the class contract for POST. """ request_data = ExpenseHandler.get_json_payload(req) try: date, amount, name, category = serializers.EXPENSE_ENTITY_SERIALIZER.load(request_data).data except ValidationError as ex: raise falcon.HTTPBadRequest( 'Bad Request', ValidationUtil.construct_error_string(ex) ) resp.status = falcon.HTTP_200 resp.body = json.dumps({ 'uri': '/expenses/%s' % ExpenseAService.create_expense(self.session.user, date, amount, name, category) })
def on_get(self, req, resp): """ Implements the class contract for GET. """ try: limit = req.params.get('limit', 10) limit = ValidationUtil.validate_positive_integer('limit', limit) offset = req.params.get('offset', 0) offset = ValidationUtil.validate_positive_integer('offset', offset) except ValidationError as ex: raise falcon.HTTPBadRequest( 'Bad Request', ValidationUtil.construct_error_string(ex) ) expenses = ExpenseAService.select_expenses(self.session.user, limit, offset) result = serializers.EXPENSE_ENTITY_SERIALIZER.dumps(expenses, many=True).data resp.status = falcon.HTTP_200 resp.body = result