forked from AdaGold/retro-video-store
-
Notifications
You must be signed in to change notification settings - Fork 15
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
Ocelots - Larissa and Soumya #19
Open
smysh
wants to merge
68
commits into
ada-ac2:main
Choose a base branch
from
ctlaultdel:main
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 11 commits
Commits
Show all changes
68 commits
Select commit
Hold shift + click to select a range
6665a56
Wave 0:Setup added migrations folder
smysh 75fb009
Registered /customers blueprint
ctlaultdel 9f10b69
Added customer class attributes and datatypes
ctlaultdel 4f2d3d4
Updated migrations with new customer class columns and datatypes
ctlaultdel ee5ccc7
Added routes for customers blueprint
ctlaultdel 7a0dfb3
Updated customer attributes and added class methods
ctlaultdel c56bda9
Added routes for displaying all customers, one customer by id, and po…
ctlaultdel 2c78b55
Upgraded migrations to reflect changes in customer attributes
ctlaultdel d9b1bca
Added update_attr() method which allows a value of a customer instanc…
ctlaultdel 15505c1
Added delete_a_customer route and modify_a_customer route
ctlaultdel 7f6d6be
added compare_type=True to Migrations
ctlaultdel 86c9e70
Got default datetime working for registered_at customer data
ctlaultdel 7b92a0f
Refactored routes to make use of customer methods
ctlaultdel 037e36f
Added return True boolean to customer.update_attr() if update successful
ctlaultdel c278adb
added video model and to_dict() and from_dict() methods.
smysh 35d93a4
added video blueprint and registered it with the app.
smysh 9a17221
Merge pull request #1 from ctlaultdel/LA-costumer-model
ctlaultdel 7da4e5b
added routes to get and create videos.
smysh f8a9bed
Merge remote-tracking branch 'origin' into ss-videos-model
smysh 5041c29
moved routes to separate routes folder. Refactored validate_customer_…
smysh 020dece
fix an issue that was making some tests fail.
smysh 5e365e6
Some more refactoring to create separate validate_request_attributes …
smysh 95c0283
Merge pull request #2 from ctlaultdel/ss-videos-model
ctlaultdel 9af0ef6
Wave 1 tests passing. Further refactored to combine validate_post_req…
smysh 8b60f76
Merge pull request #3 from ctlaultdel/ss-videos-model
ctlaultdel 8d9c65d
Merge pull request #4 from ada-ac2/main
ctlaultdel f04affb
imported classes and blueprint for rentals endpoint
ctlaultdel 6fa6a57
added customers/customer_id/rentals endpoint
ctlaultdel 774e714
Reinitialized migrations
ctlaultdel 5021439
New module for rentals routes
ctlaultdel 26e19a8
Set up all attributes for models
ctlaultdel 67f05df
refactor
ctlaultdel 46d9040
added clauses to_dict method to return more info about customer and v…
ctlaultdel f8ddbc0
added display_rentals_by_customer_id endpoint
ctlaultdel 74f2bd9
added available inventory to video model.
smysh 29f62dc
added route to checkout video using POST /rentals/checkout
smysh 5d28269
added route for video check-in. Also added updates to video_check_out…
smysh e1a734c
added status to rental model.
smysh 9f9f2d4
Wave 1 tests are passing with these fixes.
smysh 4259c63
Wave 2 video checkout tests are passing with these changes.
smysh 4f60d99
updated rental check_in to add more checks.
smysh df45839
added getting rentals by video_id.
smysh 5664ef5
Made some fixes so Wave 2 all tests are passing.
smysh aea5f0c
Merge pull request #5 from ctlaultdel/ss-videos-model
smysh 4225112
Merge branch 'main' into LA-wave2
ctlaultdel fcc26ba
Merge pull request #6 from ctlaultdel/LA-wave2
ctlaultdel b76799b
modified id to customer_id in response and included videos_checked_ou…
ctlaultdel 0cf86e6
corrected key error problem in wave 1 and wave 2 tests'
ctlaultdel 5733651
LA-wave-03-partial
ctlaultdel 643624e
Fixed typo
ctlaultdel 577623c
updated migrations.
smysh 3a03c90
fixed issue where rentals was showing checked in videos also.
smysh 82e861a
LA-sort-and-count-queries-working
ctlaultdel 7e5be26
Merge branch 'main' of https://github.com/ctlaultdel/retro-video-stor…
smysh c0e359f
fixes after merge.
smysh 719c105
LA-pagination-feature-working
ctlaultdel 9661d76
Merge branch 'main' of https://github.com/ctlaultdel/retro-video-stor…
smysh 353fb08
bug fixing for merges.
smysh 496aa80
added customer id to response in get rentals.
smysh 27e5bb5
comment out optional Wav4 tests.
smysh 6dceb47
validate request args count and page_num are int type.
smysh 237305f
bug fix for customer query.
smysh 5234714
Merge pull request #7 from ctlaultdel/ss-videos-model
ctlaultdel d7477d7
Co-authored-by: Larissa Ault <ctlaultdel@users.noreply.github.com>
smysh 59ffd97
Merge pull request #8 from ctlaultdel/ss-videos-model
ctlaultdel ae23326
Added requirements and Procfile for heroku deployment
ctlaultdel ce4084d
Refroze the dependencies while in activated venv
ctlaultdel 842ccdd
Deleted extra line
ctlaultdel File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,69 @@ | ||
from app import db | ||
from flask import Blueprint, jsonify, make_response, abort, request | ||
from ..models.rental import Rental | ||
from ..models.customer import Customer | ||
from ..models.video import Video | ||
from ..routes.customer_routes import validate_model | ||
from ..routes.customer_routes import validate_request | ||
|
||
# ~~~~~~ initialize rentals blueprint ~~~~~~ | ||
rentals_bp = Blueprint("rentals", __name__, url_prefix="/rentals") | ||
rentals_bp = Blueprint("rentals", __name__, url_prefix="/rentals") | ||
|
||
@rentals_bp.route("/check-out", methods=["POST"]) | ||
def checkout_video(): | ||
reqs = {"customer_id", "video_id"} | ||
request_body = validate_request(request, reqs) | ||
|
||
video_id = request_body["video_id"] | ||
video = validate_model(Video, video_id) | ||
|
||
customer_id = request_body["customer_id"] | ||
customer = validate_model(Customer, customer_id) | ||
|
||
if video and customer: | ||
if video.available_inventory<=0: | ||
return make_response(jsonify({"message": f"Could not perform checkout"}), 400) | ||
|
||
new_rental = Rental.from_dict(request_body) | ||
|
||
new_rental.customer = customer | ||
new_rental.customer.videos_checked_out_count += 1 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Great example making use of the relationships you've set up, to be able to cleanly use SQLAlchemy's OOP interface! |
||
|
||
new_rental.video = video | ||
new_rental.video.available_inventory -= 1 | ||
|
||
db.session.add(new_rental) | ||
db.session.commit() | ||
|
||
return make_response(jsonify(new_rental.to_dict()), 200) | ||
else: | ||
return make_response(jsonify({"message": f"Video {video_id} or Customer {customer_id} are invalid"}), 404) | ||
|
||
@rentals_bp.route("/check-in", methods=["POST"]) | ||
def checkin_video(): | ||
reqs = {"customer_id", "video_id"} | ||
request_body = validate_request(request, reqs) | ||
|
||
video_id = request_body["video_id"] | ||
video = validate_model(Video, video_id) | ||
|
||
customer_id = request_body["customer_id"] | ||
customer = validate_model(Customer, customer_id) | ||
|
||
if video and customer: | ||
rental = Rental.query.filter_by(video_id=video_id, customer_id=customer_id).first() | ||
if not rental: | ||
return make_response(jsonify({"message": f"No outstanding rentals for customer {customer_id} and video {video_id}"}), 400) | ||
|
||
if rental.status == "checked_in": | ||
return make_response(jsonify({"message": f"Cannot check_in video already checked_in"}), 400) | ||
|
||
rental.status = "checked_in" | ||
rental.customer.videos_checked_out_count -= 1 | ||
rental.video.available_inventory += 1 | ||
|
||
db.session.commit() | ||
return make_response(jsonify(rental.to_dict()), 200) | ||
else: | ||
# if not found error out | ||
return make_response(jsonify({"message": f"Video {video_id} or Customer {customer_id} are not found"}), 400) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 30 additions & 0 deletions
30
migrations/versions/7f3a3cc43a5c_added_status_to_rental_and_available_.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
"""added status to rental and available_inventory to video models. | ||
|
||
Revision ID: 7f3a3cc43a5c | ||
Revises: 8b1b64498a3f | ||
Create Date: 2023-01-07 16:24:54.863815 | ||
|
||
""" | ||
from alembic import op | ||
import sqlalchemy as sa | ||
|
||
|
||
# revision identifiers, used by Alembic. | ||
revision = '7f3a3cc43a5c' | ||
down_revision = '8b1b64498a3f' | ||
branch_labels = None | ||
depends_on = None | ||
|
||
|
||
def upgrade(): | ||
# ### commands auto generated by Alembic - please adjust! ### | ||
op.add_column('rentals', sa.Column('status', sa.String(), nullable=True)) | ||
op.add_column('video', sa.Column('available_inventory', sa.Integer(), nullable=True)) | ||
# ### end Alembic commands ### | ||
|
||
|
||
def downgrade(): | ||
# ### commands auto generated by Alembic - please adjust! ### | ||
op.drop_column('video', 'available_inventory') | ||
op.drop_column('rentals', 'status') | ||
# ### end Alembic commands ### |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice job setting up the relationships, here