Untitled

mail@pastecode.io avatar
unknown
plain_text
a month ago
1.1 kB
2
Indexable
Never
import json

from flask import Flask, request, Response

app = Flask(__name__)

@app.route("/api/v1/films/<int:id>", methods=["GET"])
def get_film(id):
    from database import get_film
    film = get_film(id)
    if film is None:
        return Response(status=404)
    return Response(json.dumps(film), mimetype="application/json")

@app.route("/api/v1/films/<int:id>", methods=["DELETE"])
def delete_film(id):
    from database import delete_film
    delete_film(id)
    return Response(status=200)

@app.route("/api/v1/categories", methods=["GET"])
def get_categories():
    from database import get_categories
    categories = get_categories()
    return Response(json.dumps(categories), mimetype="application/json")

@app.route("/api/v1/categories", methods=["POST"])
def create_category():
    from database import create_category
    data = request.get_json()
    if "name" not in data:
        return Response(status=422)
    category = create_category(data["name"])
    return Response(json.dumps(category), mimetype="application/json")

if __name__ == "__main__":
    app.run()
Leave a Comment