Skip to content

Commit

Permalink
Add date format validation
Browse files Browse the repository at this point in the history
  • Loading branch information
SethDamiani committed Dec 12, 2020
1 parent c14933b commit cbcdf6c
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions qa327/frontend.py
Original file line number Diff line number Diff line change
Expand Up @@ -271,17 +271,20 @@ def does_user_have_sufficient_balance(user_balance, ticket_price):

@app.route('/update', methods=['POST'])
def updateticket():
message = ""

ticket_id = request.form['ticket_id']
ticket_name = request.form['name']
ticket_quantity = int(request.form['quantity'])
ticket_price = float(request.form['price'])
ticket_date = request.form['date']
ticket_date = datetime.datetime.strptime(ticket_date, '%Y%m%d')
try:
ticket_date = datetime.datetime.strptime(ticket_date, '%Y%m%d')
except ValueError:
message = "Invalid date format. Please use the format YYYMMDD, i.e. 20200421."
user_email = request.form['user']
user = bn.get_user(user_email)

message = ""

# check ticket exists
if not does_ticket_exist(ticket_id):
message = "Ticket not found."
Expand Down Expand Up @@ -328,16 +331,19 @@ def buyticket():

@app.route('/sell', methods=['POST'])
def sellticket():
message = ""

ticket_name = request.form['name']
ticket_quantity = int(request.form['quantity'])
ticket_price = float(request.form['price'])
ticket_date = request.form['date']
ticket_date = datetime.datetime.strptime(ticket_date, '%Y%m%d')
try:
ticket_date = datetime.datetime.strptime(ticket_date, '%Y%m%d')
except ValueError:
message = "Invalid date format. Please use the format YYYMMDD, i.e. 20200421."
user_email = request.form['user']
user = bn.get_user(user_email)

message = ""

# check name
if not is_ticket_name_valid(ticket_name):
message = "Ticket name is invalid."
Expand Down

0 comments on commit cbcdf6c

Please sign in to comment.