Commit 4f516ae0 authored by Arthur Diniz's avatar Arthur Diniz 🇧🇷

Add blueprint to providers and images

Signed-off-by: Arthur Diniz's avatarArthur Diniz <>
parent ba699b66
Pipeline #53964 passed with stages
in 4 minutes and 30 seconds
import os
from flask import Flask
from flask import Flask, Blueprint
from flask_sqlalchemy import SQLAlchemy
from flask_script import Manager, Server
from flask_migrate import Migrate, MigrateCommand
......@@ -24,7 +24,8 @@ manager.add_command('runserver', server)
seeder = FlaskSeeder()
seeder.init_app(app, db)
from app.controllers import default
from app.controllers import provider
from app.controllers import image
from app.models import Provider, Image
from app.provider.views import provider_blueprint
from app.image.views import image_blueprint
from app import app
from app import db
from flask import render_template, Blueprint
from flask import request, jsonify
from app.models import Image, image_schema, images_schema
from app import db
image_blueprint = Blueprint("image", __name__)
def image(id):
image = Image.query.get(id)
return render_template('image.html',
# endpoint to create new image
@app.route("/api/image", methods=["POST"])
@image_blueprint.route("/api/image", methods=["POST"])
def add_image():
name = request.json['name']
arch = request.json['arch']
......@@ -36,7 +45,7 @@ def add_image():
# endpoint to show all images
@app.route("/api/image", methods=["GET"])
@image_blueprint.route("/api/image", methods=["GET"])
def get_image():
all_images = Image.query.all()
result = images_schema.dump(all_images)
......@@ -44,14 +53,14 @@ def get_image():
# endpoint to get image detail by id
@app.route("/api/image/<id>", methods=["GET"])
@image_blueprint.route("/api/image/<id>", methods=["GET"])
def image_detail(id):
image = Image.query.get(id)
return image_schema.jsonify(image)
# endpoint to update image
@app.route("/api/image/<id>", methods=["PUT"])
@image_blueprint.route("/api/image/<id>", methods=["PUT"])
def image_update(id):
image = Image.query.get(id)
name = request.json['name']
......@@ -79,7 +88,7 @@ def image_update(id):
# endpoint to delete image
@app.route("/api/image/<id>", methods=["DELETE"])
@image_blueprint.route("/api/image/<id>", methods=["DELETE"])
def image_delete(id):
image = Image.query.get(id)
from app import app
from app import db
from flask import render_template, Blueprint
from flask import request, jsonify
from app.models import Provider, provider_schema, providers_schema
from app.models import Provider, Image, provider_schema, providers_schema
from app import db
provider_blueprint = Blueprint("provider", __name__)
def index():
all_providers = Provider.query.all()
return render_template('home.html',
def provider(id):
provider = Provider.query.get(id)
all_images_from_providers = Image.query.filter_by(provider_id=id).all()
return render_template('provider.html',
# endpoint to create new provider
@app.route("/api/provider", methods=["POST"])
@provider_blueprint.route("/api/provider", methods=["POST"])
def add_provider():
name = request.json['name']
body = request.json['body']
......@@ -18,7 +37,7 @@ def add_provider():
# endpoint to show all providers
@app.route("/api/provider", methods=["GET"])
@provider_blueprint.route("/api/provider", methods=["GET"])
def get_provider():
all_providers = Provider.query.all()
result = providers_schema.dump(all_providers)
......@@ -26,14 +45,14 @@ def get_provider():
# endpoint to get provider detail by id
@app.route("/api/provider/<id>", methods=["GET"])
@provider_blueprint.route("/api/provider/<id>", methods=["GET"])
def provider_detail(id):
provider = Provider.query.get(id)
return provider_schema.jsonify(provider)
# endpoint to update provider
@app.route("/api/provider/<id>", methods=["PUT"])
@provider_blueprint.route("/api/provider/<id>", methods=["PUT"])
def provider_update(id):
provider = Provider.query.get(id)
name = request.json['name']
......@@ -47,7 +66,7 @@ def provider_update(id):
# endpoint to delete provider
@app.route("/api/provider/<id>", methods=["DELETE"])
@provider_blueprint.route("/api/provider/<id>", methods=["DELETE"])
def provider_delete(id):
provider = Provider.query.get(id)
......@@ -2,6 +2,7 @@ from app import app, db
from flask.cli import FlaskGroup
import sys
import unittest
from app.models import Provider, Image
cli = FlaskGroup(app)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment