Exemplo n.º 1
0
def create_ticket():
    data = request.get_json() or {}

    if 'title' not in data or 'content' not in data or 'category_id' not in data or 'ticket_priority_id' not in data:
        return bad_request('Must include title, content, category_id and ticket_priority_id.')

    if not isinstance(data['category_id'], int) or not isinstance(data['ticket_priority_id'], int):
        return bad_request('ticket_priority_id and category_id must be integers.')

    if not FlicketCategory.query.filter_by(id=data['category_id']).first():
        return bad_request('not a valid category_id')

    if not FlicketPriority.query.filter_by(id=data['ticket_priority_id']).first():
        return bad_request('not a valid ticket_priority_id')

    ticket = FlicketTicket()
    ticket.from_dict(data)
    ticket.started_id = g.current_user.id
    ticket.date_added = datetime.datetime.now()
    ticket.status_id = 1

    db.session.add(ticket)
    db.session.commit()

    response = jsonify(ticket.to_dict())
    response.status_code = 201
    response.headers['Location'] = url_for('bp_api.get_ticket', id=ticket.id)

    return response
Exemplo n.º 2
0
def create_category():
    data = request.get_json() or {}

    if 'category' not in data or 'department_id' not in data:
        return bad_request('Must include category name and department_id')

    if not isinstance(data['department_id'], int):
        return bad_request('department_id must be an integer.')

    if FlicketCategory.query. \
            filter_by(category=data['category']). \
            filter_by(department_id=data['department_id']).first():
        return bad_request('Category within department already exists.')

    department = FlicketDepartment.query.filter_by(
        id=data['department_id']).first()
    category = FlicketCategory(data['category'], department)
    db.session.add(category)
    db.session.commit()

    response = jsonify(category.to_dict())
    response.status_code = 201
    response.headers['Location'] = url_for('bp_api.get_category',
                                           id=category.id)
    return response
Exemplo n.º 3
0
def create_domain():
    data = request.get_json() or {}

    if "domain" not in data:
        return bad_request("Must include domain name")

    if FlicketDomain.query.filter_by(domain=data["domain"]).first():
        return bad_request("Domain  already exists.")

    domain = FlicketDomain(data["domain"])
    db.session.add(domain)
    db.session.commit()

    response = jsonify(domain.to_dict())
    response.status_code = 201
    response.headers["Location"] = url_for("bp_api.get_domain", id=domain.id)
    return response
Exemplo n.º 4
0
def create_institute():

    # todo add authentication. only those in the admin or super_user groups should be allowed to create.

    data = request.get_json() or {}

    if "institute" not in data:
        return bad_request("Must include institute name.")

    if FlicketInstitute.query.filter_by(institute=data["institute"]).first():
        return bad_request("Institute already created.")

    institute = FlicketInstitute(data["institute"])
    db.session.add(institute)
    db.session.commit()

    response = jsonify(institute.to_dict())
    response.status_code = 201
    response.headers["Location"] = url_for("bp_api.get_institute", id=institute.id)

    return response
Exemplo n.º 5
0
def create_ticket():
    data = request.get_json() or {}

    if "title" not in data or "content" not in data or "domain_id" not in data:
        return bad_request("Must include title, content, domain_id")

    if not FlicketDomain.query.filter_by(id=data["domain_id"]).first():
        return bad_request("not a valid domain_id")

    ticket = FlicketTicket()
    ticket.from_dict(data)
    ticket.started_id = g.current_user.id
    ticket.date_added = datetime.datetime.now()
    ticket.status_id = 1

    db.session.add(ticket)
    db.session.commit()

    response = jsonify(ticket.to_dict())
    response.status_code = 201
    response.headers["Location"] = url_for("bp_api.get_ticket", id=ticket.id)

    return response
Exemplo n.º 6
0
def create_department():

    # todo add authentication. only those in the admin or super_user groups should be allowed to create.

    data = request.get_json() or {}

    if 'department' not in data:
        return bad_request('Must include department name.')

    if FlicketDepartment.query.filter_by(
            department=data['department']).first():
        return bad_request('Department already created.')

    department = FlicketDepartment(data['department'])
    db.session.add(department)
    db.session.commit()

    response = jsonify(department.to_dict())
    response.status_code = 201
    response.headers['Location'] = url_for('bp_api.get_department',
                                           id=department.id)

    return response