48 lines
1.4 KiB
Python
48 lines
1.4 KiB
Python
--- public_api/app.py ---
|
|
from flask import Flask, jsonify
|
|
from flask_sqlalchemy import SQLAlchemy
|
|
|
|
app = Flask(__name__)
|
|
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///../db.sqlite'
|
|
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
|
|
|
|
db = SQLAlchemy(app)
|
|
|
|
class Artiste(db.Model):
|
|
id = db.Column(db.Integer, primary_key=True)
|
|
nom = db.Column(db.String(100), nullable=False)
|
|
|
|
class Galerie(db.Model):
|
|
id = db.Column(db.Integer, primary_key=True)
|
|
nom = db.Column(db.String(100), nullable=False)
|
|
|
|
class Oeuvre(db.Model):
|
|
id = db.Column(db.Integer, primary_key=True)
|
|
titre = db.Column(db.String(200), nullable=False)
|
|
exposee = db.Column(db.Boolean, default=False)
|
|
|
|
@app.route("/", methods=["GET"])
|
|
def index():
|
|
return "Public API", 200
|
|
|
|
@app.route("/artistes", methods=["GET"])
|
|
def get_artistes():
|
|
artistes = Artiste.query.all()
|
|
return jsonify([{"id": a.id, "nom": a.nom} for a in artistes]), 200
|
|
|
|
@app.route("/galeries", methods=["GET"])
|
|
def get_galeries():
|
|
galeries = Galerie.query.all()
|
|
return jsonify([{"id": g.id, "nom": g.nom} for g in galeries]), 200
|
|
|
|
@app.route("/oeuvres", methods=["GET"])
|
|
def get_oeuvres():
|
|
oeuvres = Oeuvre.query.filter_by(exposee=True).all()
|
|
return jsonify([{"id": o.id, "titre": o.titre} for o in oeuvres]), 200
|
|
|
|
if __name__ == "__main__":
|
|
with app.app_context():
|
|
db.create_all()
|
|
app.run(port=5001)
|
|
|