...
 
Commits (2)
......@@ -8,6 +8,10 @@ stages:
variables:
DOCKER_TLS_CERTDIR: ""
cache:
paths:
- ~/.cache/pip/
lint-flake8:
image: python:3.7
stage: Static Analysis
......
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
......@@ -21,6 +21,9 @@ manager.add_command('db', MigrateCommand)
manager.add_command('runserver', server)
from finder.controllers import default
from finder.controllers import provider
from finder.controllers import image
from finder.models import Provider, Image
from finder.provider.views import provider_blueprint
from finder.image.views import image_blueprint
app.register_blueprint(provider_blueprint)
app.register_blueprint(image_blueprint)
from flask import render_template, Blueprint
from flask import request, jsonify
from finder.models import Image, image_schema, images_schema
from finder import db
image_blueprint = Blueprint("image", __name__)
@image_blueprint.route("/image/<id>")
def image(id):
image = Image.query.get(id)
return render_template('image.html',
Image=image,
Provider=image.provider)
# endpoint to create new image
@image_blueprint.route("/api/image", methods=["POST"])
def add_image():
name = request.json['name']
arch = request.json['arch']
release = request.json['release']
img_type = request.json['img_type']
vendor = request.json['vendor']
version = request.json['version']
job_url = request.json['job_url']
package = request.json['package']
created_at = request.json['created_at']
provider_id = request.json['provider_id']
new_image = Image(name,
arch,
release,
img_type,
vendor,
version,
job_url,
package,
created_at,
provider_id)
db.session.add(new_image)
db.session.commit()
return image_schema.jsonify(new_image)
# endpoint to show all images
@image_blueprint.route("/api/image", methods=["GET"])
def get_image():
all_images = Image.query.all()
result = images_schema.dump(all_images)
return jsonify(result.data)
# endpoint to get image detail by id
@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
@image_blueprint.route("/api/image/<id>", methods=["PUT"])
def image_update(id):
image = Image.query.get(id)
name = request.json['name']
arch = request.json['arch']
release = request.json['release']
img_type = request.json['img_type']
vendor = request.json['vendor']
version = request.json['version']
job_url = request.json['job_url']
package = request.json['package']
created_at = request.json['created_at']
image.name = name
image.arch = arch
image.release = release
image.img_type = img_type
image.vendor = vendor
image.version = version
image.job_url = job_url
image.package = package
image.created_at = created_at
db.session.commit()
return image_schema.jsonify(image)
# endpoint to delete image
@image_blueprint.route("/api/image/<id>", methods=["DELETE"])
def image_delete(id):
image = Image.query.get(id)
db.session.delete(image)
db.session.commit()
return image_schema.jsonify(image)
from flask import render_template, Blueprint
from flask import request, jsonify
from finder.models import Provider, Image, provider_schema, providers_schema
from finder import db
provider_blueprint = Blueprint("provider", __name__)
@provider_blueprint.route("/")
def index():
all_providers = Provider.query.all()
return render_template('home.html',
len=len(all_providers),
Providers=all_providers)
@provider_blueprint.route("/provider/<id>")
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',
Provider=provider,
len=len(all_images_from_providers),
Images=all_images_from_providers)
# endpoint to create new provider
@provider_blueprint.route("/api/provider", methods=["POST"])
def add_provider():
name = request.json['name']
body = request.json['body']
new_provider = Provider(name, body)
db.session.add(new_provider)
db.session.commit()
return provider_schema.jsonify(new_provider)
# endpoint to show all providers
@provider_blueprint.route("/api/provider", methods=["GET"])
def get_provider():
all_providers = Provider.query.all()
result = providers_schema.dump(all_providers)
return jsonify(result.data)
# endpoint to get provider detail by id
@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
@provider_blueprint.route("/api/provider/<id>", methods=["PUT"])
def provider_update(id):
provider = Provider.query.get(id)
name = request.json['name']
body = request.json['body']
provider.name = name
provider.body = body
db.session.commit()
return provider_schema.jsonify(provider)
# endpoint to delete provider
@provider_blueprint.route("/api/provider/<id>", methods=["DELETE"])
def provider_delete(id):
provider = Provider.query.get(id)
db.session.delete(provider)
db.session.commit()
return provider_schema.jsonify(provider)
......@@ -2,6 +2,7 @@ from finder import app, db
from flask.cli import FlaskGroup
import sys
import unittest
from finder.models import Provider, Image
cli = FlaskGroup(app)
......