def book_ticket(): if 'user_id' not in session: return login_in_please() user_id = session['user_id'] req = request.get_json() if 'type' not in req: return bad_request() ticket_type = req['type'] if ticket_type not in app.config['TYPE_IDS'].values(): return bad_request() seat_num = None if ticket_type == app.config['TYPE_IDS']['pc']: if 'seat' not in req: return bad_request() seat_num = req['seat'] tickets_max = app.config['TICKETS_MAX'] price = app.config['PRICING'][ticket_type] r = Ticket.book_temp(user_id, ticket_type, price, tickets_max, seat_num) if r[0]: ticket = Ticket.query.filter(Ticket.owner_id == user_id) \ .filter(or_(Ticket.paid, Ticket.reserved_until >= datetime.now())) \ .one() return jsonify({'ticket': ticket.as_pub_dict()}), 201 # Conflict while booking ticket return jsonify({'error': str(r[1])}), 409
def book_ticket(): if 'user_id' not in session: return login_in_please() user_id = session['user_id'] req = request.get_json() if 'type' not in req: return bad_request() ticket_type = req['type'] if ticket_type not in app.config['TYPE_IDS'].values(): return bad_request() seat_num = None if ticket_type == app.config['TYPE_IDS']['pc']: if 'seat' not in req: return bad_request() seat_num = req['seat'] tickets_max = app.config['TICKETS_MAX'] price = app.config['PRICING'][ticket_type] r = Ticket.book_temp(user_id, ticket_type, price, tickets_max, seat_num) if r[0]: ticket = Ticket.query.filter(Ticket.owner_id == user_id) \ .filter(or_(Ticket.paid, Ticket.reserved_until >= datetime.now()))\ .one() return jsonify({'ticket': ticket.as_pub_dict()}), 201 # Conflict while booking ticket mess = 'Conflit lors de la réservation de billet: "%s"' % str(r[1]) if len(r) == 3: mess = '%s Exception: %s' % (mess, r[2]) app.logger.error(mess) return jsonify({'message': str(r[1])}), 409