Added FilmFormat and Location MVC to the api and modified the .gitignore to ignore compiled python files
This commit is contained in:
parent
1f2f6070ef
commit
999fea97a7
@@ -0,0 +1,40 @@
|
||||
from flask import request, jsonify
|
||||
import uuid
|
||||
from ..app import db
|
||||
from .models import Location
|
||||
|
||||
def list_all_location_controller():
|
||||
locations = Location.query.all()
|
||||
response = []
|
||||
for location in locations: response.append(location.toDict())
|
||||
return jsonify(response)
|
||||
|
||||
def create_location_controller():
|
||||
request_form = request.form.to_dict()
|
||||
print(request_form)
|
||||
new_location = Location(
|
||||
name = request_form['name'],
|
||||
)
|
||||
db.session.add(new_location)
|
||||
db.session.commit()
|
||||
response = Location.query.all()
|
||||
return(jsonify(request_form))
|
||||
|
||||
def retrieve_location_controller(location_id):
|
||||
response = Location.query.get(location_id).toDict()
|
||||
print(response)
|
||||
return jsonify(response)
|
||||
|
||||
def update_location_controller(location_id):
|
||||
request_form = request.form.to_dict()
|
||||
location = Location.query.get(location_id)
|
||||
location.name = request_form['name']
|
||||
|
||||
db.session.commit()
|
||||
response = Location.query.get(location_id).toDict()
|
||||
return jsonify(response)
|
||||
|
||||
def delete_location_controller(location_id):
|
||||
Location.query.filter_by(id=location_id).delete()
|
||||
db.session.commit()
|
||||
return f"FilmManufacturer with ID= {location_id} was removed successfully"
|
||||
@@ -0,0 +1,13 @@
|
||||
from sqlalchemy import inspect
|
||||
|
||||
from ..app import db
|
||||
|
||||
class Location(db.Model):
|
||||
id = db.Column(db.Integer(),primary_key=True,nullable=False,unique=True, autoincrement=True)
|
||||
name = db.Column(db.String(255))
|
||||
|
||||
def toDict(self):
|
||||
return {
|
||||
c.key: getattr(self,c.key) for c in inspect(self).mapper.column_attrs
|
||||
}
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
from flask import request
|
||||
|
||||
from ..app import app
|
||||
from .controllers import list_all_location_controller,create_location_controller,retrieve_location_controller,update_location_controller,delete_location_controller
|
||||
|
||||
@app.route("/Location",methods=["GET","POST"])
|
||||
def list_all_create_locations():
|
||||
if request.method == 'GET' : return list_all_location_controller()
|
||||
if request.method == 'POST' : return create_location_controller()
|
||||
|
||||
@app.route("/Location/<location_id>",methods=["GET","PUT","DELETE"])
|
||||
def retrieve_update_delete_locations(filmformat_id):
|
||||
if request.method == 'GET' : return retrieve_location_controller(filmformat_id)
|
||||
if request.method == 'PUT' : return update_location_controller(filmformat_id)
|
||||
if request.method == "DELETE": return delete_location_controller(filmformat_id)
|
||||
Reference in New Issue
Block a user