Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Spruce - Angela F. #48

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 12 additions & 5 deletions app/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,22 @@
migrate = Migrate()
load_dotenv()


def create_app(test_config=None):
app = Flask(__name__)
app.url_map.strict_slashes = False
app.config["SQLALCHEMY_TRACK_MODIFICATIONS"] = False

if test_config is None:
app.config["SQLALCHEMY_DATABASE_URI"] = os.environ.get(
"SQLALCHEMY_DATABASE_URI")
"SQLALCHEMY_DATABASE_URI"
)
else:
app.config["TESTING"] = True
app.config["SQLALCHEMY_DATABASE_URI"] = os.environ.get(
"SQLALCHEMY_TEST_DATABASE_URI")
"SQLALCHEMY_TEST_DATABASE_URI"
)


# import models for Alembic Setup
from app.models.customer import Customer
from app.models.video import Video
Expand All @@ -31,6 +33,11 @@ def create_app(test_config=None):
db.init_app(app)
migrate.init_app(app, db)

#Register Blueprints Here
# Register Blueprints Here
from .routes import rentals_bp, videos_bp, customers_bp

app.register_blueprint(rentals_bp)
app.register_blueprint(videos_bp)
app.register_blueprint(customers_bp)

return app
return app
17 changes: 16 additions & 1 deletion app/models/customer.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,19 @@
from app import db


class Customer(db.Model):
id = db.Column(db.Integer, primary_key=True)
id = db.Column(db.Integer, primary_key=True)
name = db.Column(db.String)
postal_code = db.Column(db.String)
phone = db.Column(db.String)
registered_at = db.Column(db.DateTime, nullable=True)
rentals = db.relationship("Rental", backref="customer", lazy=True)

def customer_information(self):
return {
"id": self.id,
"name": self.name,
"postal_code": self.postal_code,
"phone": self.phone,
"registered_at": self.registered_at,
}
7 changes: 6 additions & 1 deletion app/models/rental.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
from app import db


class Rental(db.Model):
id = db.Column(db.Integer, primary_key=True)
id = db.Column(db.Integer, primary_key=True)
customer_id = db.Column(db.Integer, db.ForeignKey("customer.id"))
video_id = db.Column(db.Integer, db.ForeignKey("video.id"))
due_date = db.Column(db.DateTime)
checked_out = db.Column(db.Boolean, default=False)
16 changes: 15 additions & 1 deletion app/models/video.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,18 @@
from app import db


class Video(db.Model):
id = db.Column(db.Integer, primary_key=True)
id = db.Column(db.Integer, primary_key=True)
title = db.Column(db.String)
release_date = db.Column(db.DateTime)
total_inventory = db.Column(db.Integer)
available_inventory = db.Column(db.Integer)
rentals = db.relationship("Rental", backref="video", lazy=True)

def video_information(self):
return {
"id": self.id,
"title": self.title,
"release_date": self.release_date,
"total_inventory": self.total_inventory,
}
Loading