def on_put(req, resp, ticket_id): payload = json.loads(req.stream.read().decode('utf-8')) status_name = payload.get('status') with session() as db: repo = Repo(db) ticket = repo.list_ticket(int(ticket_id)) repo.change_ticket_status(ticket=ticket, status=Ticket.STATUSES[status_name]) resp.body = json.dumps({ 'id': ticket_id, 'status': status_name }, sort_keys=True, indent=4)
def on_get(req, resp, ticket_id): with session() as db: repo = Repo(db) ticket = repo.list_ticket(int(ticket_id)) if ticket is None: resp.body = json.dumps({'status': 'not found'}, sort_keys=True, indent=4) else: resp.body = json.dumps( { 'id': ticket.ticket_id, 'ticket_type': ticket.ticket_type, 'status': Ticket.find_status_name(ticket.status) }, sort_keys=True, indent=4)