def METHOD_NAME(
    query: Query,
    department_id: int,
    csv_suffix: str,
    field_names: List[str],
    record_maker: Callable[[T], _Record],
) -> Response:
    department = Department.query.filter_by(id=department_id).first()
    if not department:
        abort(404)
    csv_output = io.StringIO()
    csv_writer = csv.DictWriter(csv_output, fieldnames=field_names)
    csv_writer.writeheader()
    for entity in query:
        record = record_maker(entity)
        csv_writer.writerow(record)
    dept_name = department.name.replace(" ", "_")
    csv_name = dept_name + "_" + csv_suffix + ".csv"
    csv_headers = {"Content-disposition": "attachment; filename=" + csv_name}
    return Response(csv_output.getvalue(), mimetype="text/csv", headers=csv_headers)