from apps.cinema import api from apps.cinema.schema import param, validate_date from apps.cinema.schema.parser import use_args from apps.cinema.schema.user_schema import ( login_schema, user_login_schema, user_request_fields, user_schema, user_schema_fields, ) from apps.middlewares.auth import generate_token, is_admin, token_header from apps.middlewares.validation import ValidationError from controllers.user_controller import UserController user_args = { "id": param(flds.Int(required=True)), "email": param(flds.Str()), "report": param(flds.Bool()), "name": param(flds.Str()), "ticket_startdate": param(flds.Str(validate=validate_date)), "ticket_enddate": param(flds.Str(validate=validate_date)), "total": param(flds.Float()), } @api.route("/auth", endpoint="user") class UserRegistration(Resource): @api.marshal_with(user_schema_fields, envelope="user", skip_none=True) @api.expect(user_request_fields) def post(self): user = api.payload
from flask import Blueprint, jsonify, request from werkzeug.security import check_password_hash, generate_password_hash from apps.cinema import api from apps.cinema.schema import param, validate_date from apps.cinema.schema.parser import use_args from apps.cinema.schema.user_schema import * from apps.middlewares.auth import generate_token, is_admin, token_header from apps.middlewares.validation import ValidationError from controllers.user_controller import UserController from flask_restplus import Resource, abort from webargs import fields as flds user_args = { 'id': param(flds.Int(required=True)), 'email': param(flds.Str()), 'report': param(flds.Bool()), 'name': param(flds.Str()), 'ticket_startdate': param(flds.Str(validate=validate_date)), 'ticket_enddate': param(flds.Str(validate=validate_date)), 'total': param(flds.Float()) } @api.route('/auth', endpoint='user') class UserRegistration(Resource): @api.marshal_with(user_schema_fields, envelope='user', skip_none=True) @api.expect(user_request_fields) def post(self): user = api.payload api.schema_model('User', {**user_schema}).validate(user)
from apps.cinema.schema import param from apps.cinema.schema.cinema_schema import ( cinema_response_schema, process_seats, schema, ) from apps.cinema.schema.parser import use_args from apps.middlewares.auth import is_admin, token_header from controllers.cinema import CinemaController from controllers.seats import SeatController from flask_restplus import Resource from models import CinemaHall from utils import find_or_404 from webargs import fields as flds cinema_args = {"id": param(flds.Int(required=True))} @api.route("/cinema", endpoint="cinemas") class CinemasEndpoint(Resource): @api.marshal_with(cinema_response_schema, envelope="cinema", skip_none=True) @token_header @is_admin def post(self): body = api.payload api.schema_model("cinema", {**schema}).validate(body) seats = body.pop("seats") controller = CinemaController() cinema = controller.insert(body)[0]
from flask import Blueprint, jsonify, request from apps.cinema import api from apps.cinema.schema import validate_date from apps.cinema.schema.parser import use_args from apps.cinema.schema.ticket_schema import * from apps.middlewares.auth import token_header from controllers.ticket_controller import TicketController from flask_restplus import Resource from webargs import fields as flds from apps.cinema.schema import param ticket_args = {'user_id': param(flds.Int(required=True)), 'date_created': param(flds.Str(validate=validate_date)), 'show_date_time': param(flds.Str(validate=validate_date)), 'movie_id': param(flds.Int()), 'price': param(flds.Float()), 'id': param(flds.Int())} @api.route('/ticket', endpoint='tickets') class TicketBookings(Resource): @api.marshal_with(ticket_response_body, envelope='ticket', skip_none=True) @api.expect(ticket_schema) @token_header def post(self): body = api.payload or {} api.schema_model('Tickets', {**schema}).validate(body) body['user_id'] = request.user.id controller = TicketController()
from datetime import datetime from flask_restplus import Resource from webargs import fields as flds # noqa from apps.cinema import api from apps.cinema.schema import param, validate_date from apps.cinema.schema.parser import use_args from apps.cinema.schema.showtime_schema import schema, showtimes_schema from apps.middlewares.auth import is_admin, token_header from controllers.show_time_controller import ShowTimeController showtime_args = { "start_date": param(flds.Str(required=True, validate=validate_date)), "id": param(flds.Int(required=True)), } @api.route("/showtime", endpoint="showtimes") class ShowTimeEndpoint(Resource): @api.marshal_with(showtimes_schema, envelope="showtimes", skip_none=True) @token_header @use_args(showtime_args) def get(self, params): showtimes = ShowTimeController() params = {items.get("field"): items.get("value") for items in params} return showtimes.find(**params), 200 @api.marshal_with(showtimes_schema, envelope="showtimes", skip_none=True) @token_header @is_admin
from webargs import fields as flds from apps.cinema import api from apps.cinema.schema import param, validate_date from apps.cinema.schema.parser import use_args from apps.cinema.schema.ticket_schema import ( process_tickets_seats, schema, ticket_response_body, ticket_schema, ) from apps.middlewares.auth import token_header from controllers.ticket_controller import TicketController ticket_args = { "user_id": param(flds.Int(required=True)), "date_created": param(flds.Str(validate=validate_date)), "show_datetime": param(flds.Str(validate=validate_date)), "movie_id": param(flds.Int()), "price": param(flds.Float()), "id": param(flds.Int()), } @api.route("/ticket", endpoint="tickets") class TicketBookings(Resource): @api.marshal_with(ticket_response_body, envelope="ticket", skip_none=True) @api.expect(ticket_schema) @token_header def post(self): body = api.payload or {}
from flask import current_app, request from apps.cinema import api from apps.cinema.schema import param, validate_date from apps.cinema.schema.cinema_schema import * from apps.cinema.schema.parser import use_args from apps.middlewares.auth import is_admin, token_header from controllers.cinema import CinemaController from controllers.seats import SeatController from flask_restplus import Resource from models import CinemaHall from utils import dict_to_tuple, find_or_404 from webargs import fields as flds cinema_args = {'id': param(flds.Int(required=True))} @api.route('/cinema', endpoint='cinemas') class CinemasEndpoint(Resource): @api.marshal_with(cinema_response_schema, envelope='cinema', skip_none=True) @token_header @is_admin def post(self): body = api.payload api.schema_model('cinema', {**schema}).validate(body) seats = body.pop('seats') controller = CinemaController() cinema = controller.insert(body)[0] seats_dict = process_seats(seats, cinema.get('id'))