def get(self, ticket_id, **kwargs): user_id = request.user.id controller = TicketController() ticket = controller.find_one(user_id=user_id, id=ticket_id, serialize=True) return ticket
def update_ticket(ticket_id): """Update a specific ticket.""" ticket_data = request.get_json() user_by_id = None response = None # get ticket by id ticket_by_id = TicketController.get_ticket_by_id(ticket_id) # check if there is assignee key provided in request if "ticket_assignee" in ticket_data: user_by_id = UserController.get_users_by_id( ticket_data["ticket_assignee"]) if user_by_id is None: return (error_response(404, "Resource Not Found") ) # return not found response if wrong user provided # check if ticket was found and update accordingly if ticket_by_id: TicketController.update_ticket(ticket_by_id, ticket_data, user_by_id) response = success_response_body(ticket_data) else: # return no user error response = error_response(404, "Resource Not Found") return response
def get(self, params, **kwargs): user_id = request.user.id controller = TicketController() if not request.user.is_staff: params.append({'operator':'=','value':request.user.id,'field':'user_id'}) tickets = controller.find(serialize=True, operator='AND', params=params, **kwargs) return tickets, 200
def delete_ticket(ticket_id): """Delete a specific ticket.""" if TicketController.get_ticket_by_id(ticket_id): TicketController.delete_ticket(ticket_id) response = success_response_body({}) else: response = error_response(404, "Resource Not Found") return response
def post(self): body = api.payload or {} api.schema_model('Tickets', {**schema}).validate(body) body['user_id'] = request.user.id controller = TicketController() seats_ids = body.pop('seat_id') seat_list = seats_ids if type(seats_ids) is list else [seats_ids] seats = process_tickets_seats(body, seat_list) ticket = controller.insert(seats, seat_id=seat_list, **body) return ticket, 201
def get(self, params, **kwargs): user_id = request.user.id controller = TicketController() if not request.user.is_staff: params.append({ "operator": "=", "value": user_id, "field": "user_id" }) tickets = controller.find(serialize=True, operator="AND", params=params, **kwargs) return tickets, 200
def update_ticket(ticket_id): """Update a ticket.""" ticket_data = request.get_json() put_ticket = TicketController.update_ticket(ticket_id, ticket_data) return jsonify(put_ticket)
def delete_ticket(ticket_id): """Delete a ticket.""" TicketController.delete_ticket(ticket_id) response = success_response_body({}) return response
def create_ticket(): """Create a new ticket.""" ticket_data = request.get_json() new_ticket = TicketController.create_ticket(ticket_data) return jsonify(new_ticket.conv_ticket_to_dict())
def get_single_ticket(ticket_id): """Get the details of a single ticket.""" tickets_array = TicketController.get_ticket_by_id(ticket_id) return jsonify(tickets_array.conv_ticket_to_dict())
def get_ticket_list(): """Get a list of tickets.""" tickets_array = TicketController.get_tickets() return jsonify(tickets_array)
def get_single_ticket(ticket_id): """Return a single ticket based on its ID.""" ticket = TicketController.get_ticket_by_id(ticket_id) return jsonify(ticket.ticket_to_dict())
def create_ticket(): """Create a new ticket and add it to the ticket pool.""" data = request.get_json() ticket = TicketController.create_ticket(data) return jsonify(ticket.ticket_to_dict())
def delete_user(user_id): """Delete a specific user based on ID.""" TicketController.unassign_tickets_by_user_id(user_id) UserController.delete_user(user_id) return jsonify({})