Beispiel #1
0
 def get(self):
     args = self._parse_args()
     if None in [args["movie"], args["hall"], args["time"], args["date"]]:
         return make_response(
             jsonify(
                 {'message': ApiMessages.QUERY_PARAMS_NOT_PROVIDED.value}),
             400)
     query = TicketModel.query.join(SeatModel).join(SeanceModel).join(
         HallModel).join(MovieModel).filter(
             MovieModel.title == args["movie"]).filter(
                 SeanceModel.date == args["date"]).filter(
                     SeanceModel.time == args["time"]).filter(
                         HallModel.name == args["hall"])
     if args["filterRow"] is not None:
         query = query.filter(SeatModel.row == args["filterRow"])
     if args["filterNumber"] is not None:
         query = query.filter(SeatModel.number == args["filterNumber"])
     tickets, count = prepare_and_run_query(query,
                                            args={
                                                "row": "",
                                                "number": "",
                                                "price": ""
                                            })
     output = []
     for ticket in tickets:
         output_elem = TicketSchema().dump(ticket)
         output_elem.update(row=ticket.seat.row, number=ticket.seat.number)
         output.append(output_elem)
     return make_response(jsonify({'data': output, 'count': count}), 200)
Beispiel #2
0
 def get(self):
     args = self._parse_movie_args()
     if args['movieId'] is not None:
         movie = MovieModel.query.filter(
             MovieModel.movieId == args['movieId']).all()
         count = len(movie)
         if not count:
             return make_response(
                 jsonify({'message': ApiMessages.RECORD_NOT_FOUND.value}),
                 404)
         output = MovieSchema(many=True).dump(movie)
     else:
         try:
             query = self._search_movies_query(MovieModel.query)
             movies, count = prepare_and_run_query(query, args)
             output = MovieSchema(many=True).dump(movies)
         except ValueError as err:
             return make_response(jsonify({'message': str(err)}), 404)
     if output is not None:
         return make_response(jsonify({
             'data': output,
             'count': count
         }), 200)
     else:
         return make_response(
             jsonify({"message": ApiMessages.INTERNAL.value}), 500)
Beispiel #3
0
 def get(self):
     args = self._parse_seance_args()
     if args['seanceId'] is not None:
         seance = SeanceModel.query.filter(
             SeanceModel.seanceId == args['seanceId']).all()
         count = len(seance)
         if not count:
             return make_response(
                 jsonify({'message': ApiMessages.RECORD_NOT_FOUND.value}),
                 404)
         output = SeanceSchema(many=True).dump(seance)
     else:
         try:
             query = self._search_seances_query(
                 SeanceModel.query.join(MovieModel).join(HallModel))
             args['name'] = args['title'] = ''
             seances, count = prepare_and_run_query(query, args)
             output = SeanceSchema(many=True).dump(seances)
         except ValueError as err:
             return make_response(jsonify({'message': str(err)}), 404)
     if output is not None:
         return make_response(jsonify({
             'data': output,
             'count': count
         }), 200)
     else:
         return make_response(
             jsonify({"message": ApiMessages.INTERNAL.value}), 500)