def create_task(): data = loads(request.data) if 'title' in data: task = Task(title=data['title'], created=datetime.now()) db.session.add(task) db.session.commit() schema = TaskSchema() output = schema.dump(task) response = create_response(output, 201) else: output = {'error': 'The title cannot be null or empty'} response = create_response(output, 400) return response
def get_ipv4(): try: r = get('http://169.254.169.254/latest/meta-data/public-ipv4', timeout=3) except RequestException: ipv4 = 'IP desconocida' else: ipv4 = r.text if r.status_code == 200 else 'IP desconocida' return create_response({'ipv4': ipv4})
def healthcheck(): return create_response({'status': 'Remember The Bread is up and running'})
def delete_task(task_id): task = Task.query.filter(Task.id == task_id).first() if task is not None: db.session.delete(task) db.session.commit() return create_response(None, 204)
def list_tasks(): tasks = Task.query.order_by(Task.created.desc()).all() schema = TaskSchema(many=True) output = schema.dump(tasks) return create_response(output)