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

Ocelots - Megan M & Xuan Hien Pham #11

Open
wants to merge 32 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
e5e4a0c
Set up envoirnment and DB for first wave
maple-megan333 Jan 3, 2023
15e74ab
Updated to seperate routes
maple-megan333 Jan 4, 2023
8c993d0
First models complete.
maple-megan333 Jan 4, 2023
cac0747
Made dictionary methods for models!
maple-megan333 Jan 4, 2023
3443973
CRUD for video
HienXuanPham Jan 4, 2023
1e54c81
working on customer
maple-megan333 Jan 4, 2023
b80a7c1
Merge branch 'main' of https://github.com/maple-megan333/retro-video-…
maple-megan333 Jan 4, 2023
4ffae47
Post and get complete
maple-megan333 Jan 4, 2023
30850f7
customer deleted completed
maple-megan333 Jan 4, 2023
d08fca4
Finished put method!
maple-megan333 Jan 4, 2023
3622132
Updated database and added Video Model.
maple-megan333 Jan 5, 2023
08ab095
modify video_routes to pass all tests in test_wave_01
HienXuanPham Jan 5, 2023
1d76b94
Tweaked rentals and started rental Routes.
maple-megan333 Jan 5, 2023
6462e46
passed first 3 rental tests!
maple-megan333 Jan 5, 2023
75476aa
bacref > back_populates
maple-megan333 Jan 5, 2023
109796c
videos back_populate upgrade.
maple-megan333 Jan 5, 2023
01a8a85
passed all checkout tests.
maple-megan333 Jan 5, 2023
12840e7
dynamic calculation of available inventory added.
maple-megan333 Jan 5, 2023
879db46
rentals passes all checkin methods!
maple-megan333 Jan 5, 2023
f9d491c
finished rentals by video
maple-megan333 Jan 5, 2023
2b45c78
Wave 2 complete
maple-megan333 Jan 5, 2023
fc894c5
working through wave 3
maple-megan333 Jan 6, 2023
73105b0
trying to do current tests.
maple-megan333 Jan 6, 2023
53fa5b6
continuing ot try and debug.
maple-megan333 Jan 6, 2023
b406f87
cleaned up
maple-megan333 Jan 6, 2023
b11a185
still tryiing to debug videos_routes.
maple-megan333 Jan 6, 2023
c4471a2
morning debugging.
maple-megan333 Jan 6, 2023
894e2f0
passes wave 3 minus history!
maple-megan333 Jan 6, 2023
25e2c5f
created refactor branch and added routes history for customer and video
HienXuanPham Jan 9, 2023
a88658c
gunicorn on my system
maple-megan333 Jan 9, 2023
b05a5bf
finsihed deploying on personal heroku
maple-megan333 Jan 9, 2023
ae1a7e7
finsiehd deploying personal heroku
maple-megan333 Jan 9, 2023
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
Prev Previous commit
Next Next commit
working through wave 3
Co-authored-by: HienXuanPham <HienXuanPham@users.noreply.github.com>
  • Loading branch information
maple-megan333 and HienXuanPham committed Jan 6, 2023
commit fc894c53d431dfb00a87d04aa7c3ccaa653333e3
67 changes: 65 additions & 2 deletions app/routes/video_routes.py
Original file line number Diff line number Diff line change
@@ -5,6 +5,68 @@
from app.routes.rental_routes import query_rentals
from flask import Blueprint, jsonify, abort, make_response, request

def custom_query(cls, approvedsortinig, filters=None):
#list of accepted sort paramas
valid_sort=set(approvedsortinig)
custom_querys=None

#getting sort and pagnation args, with defults and types
sort=request.args.get('sort', 'id')
page = request.args.get('page',1,type=int)

count=request.args.get('per_page',100, type=int)
if request.args.get('count'):
count=request.args.get('count',100, type=int)

if request.args.get('page_num'):
page=request.args.get('page_num',1, type=int)

#making id if not valid.
if sort not in valid_sort: sort= 'id'
#checking to see if class is the orderby attricute
order_cls=cls

if not hasattr(cls,sort):
find_att=[Customer,Video,Rental]
for object in find_att:
if hasattr(object,sort):
order_cls=object



#are there filters?
if request.args.get('filter'):
filters=request.args.getlist('filter')
if filters:
join_id=None
join_class=None
if filters.get("customer_id"):
join_class=Video
join_id=join_class.__name__.lower() + "_id"
elif filters.get("video_id"):
join_class=Customer
join_id=join_class.__name__.lower() + "_id"

if join_class:
custom_querys=db.session.query(cls).filter_by(**filters).join(join_class,join_class.id==getattr(
cls,join_id), full=True).order_by(
getattr(order_cls,sort)).paginate(page=page,per_page=count,error_out=False)

else:
custom_querys=db.session.query(cls).filter_by(**filters).order_by(
getattr(order_cls,sort)).paginate(page,count,False)

elif order_cls !=cls:
custom_querys=db.sessoin.query(cls).join(join_class,join_class.id==getattr(
cls,join_id), full=True).order_by(
getattr(order_cls,sort)).paginate(page,count,False)
else:
custom_querys=cls.query.order_by(getattr(
order_cls,sort)).paginate(page,count,False)

query=custom_querys.items
return query


videos_bp = Blueprint("videos_bp", __name__, url_prefix="/videos")

@@ -74,11 +136,12 @@ def delete_a_video(video_id):
@videos_bp.route("/<video_id>/rentals", methods=["GET"])
def get_rentals_by_video(video_id):
video = validate_model(Video, video_id)
query = query_rentals({"video_id":video.id, "status": Rental.RentalStatus.CHECKOUT})
query = custom_query(Rental,['id','name','postal_code', 'registered_at'],{"video_id":video.id, "status": Rental.RentalStatus.CHECKOUT})

response = []
for rental in query:
customer = validate_model(Customer, rental.customer_id)
rental_info = customer.to_dict()
rental_info = customer.to_dict()
rental_info["due_date"] = rental.due_date
response.append(rental_info)
return jsonify(response)