diff --git a/README.md b/README.md index fef99f9..e06ef2e 100644 --- a/README.md +++ b/README.md @@ -57,6 +57,8 @@ Business Units are programs: Denver WDI (1), Boulder WDI (2), etc. ### Students * `/api/v1/students` + * `email=mail@mail.com` + * `github=github_username` * `/api/v1/students/:student_id` * `/api/v1/business-units/:business_unit_id/cohorts/:cohort_id/students` * `/api/v1/cohorts/:cohort_id/students` diff --git a/app/controllers/students.js b/app/controllers/students.js index c60b436..e815f08 100644 --- a/app/controllers/students.js +++ b/app/controllers/students.js @@ -7,7 +7,7 @@ var Student = require("../models/Student"); module.exports = { multiple: function(request, response){ - Student.getAll() + Student.getAll(request.query) .then(respond.bind(null, request, response)); }, single: function(request, response){ diff --git a/app/models/Student.js b/app/models/Student.js index 0019b8c..56f0021 100644 --- a/app/models/Student.js +++ b/app/models/Student.js @@ -20,9 +20,17 @@ class Student extends Model { "galvanize_id" ]; } - static getAll(){ - return this.query() - .select(this.columns) + static getAll(filters = {}){ + let query = this.query().select(this.columns) + + if (filters.github) { + query = query.where("github_username", filters.github) + } + if (filters.email) { + query = query.where("email", filters.email) + } + + return query } static getOne(id){ return this.query() diff --git a/tests/acceptance/students.js b/tests/acceptance/students.js index 3d5c559..3cb8ee2 100644 --- a/tests/acceptance/students.js +++ b/tests/acceptance/students.js @@ -51,6 +51,56 @@ describe("acceptance - /students", function(){ }).catch(done); }); }); + describe("#GET /students?github=kylecoberly", function(){ + it("displays a list of matching serialized students", done => { + request(app) + .get(`${VERSION}/students?github=kylecoberly`) + .expect(200) + .then(response => { + assert.deepEqual(response.body.data, [{ + id: "1", + type: "students", + attributes: { + "first-name": "Kyle", + "last-name": "Coberly", + "email": "kyle.coberly@gmail.com", + "twitter": "kylecoberly", + "phone": "777-777-7777", + "github": "kylecoberly", + "linkedin": "kylecoberly", + "galvanize-id": "1", + "avatar": "https://www.google.com" + } + }]); + done(); + }).catch(done); + }); + }); + describe("#GET /students?email=danny.fritz@gmail.com", function(){ + it("displays a list of matching serialized students", done => { + request(app) + .get(`${VERSION}/students?email=danny.fritz@gmail.com`) + .expect(200) + .then(response => { + assert.deepEqual(response.body.data, [{ + id: "2", + type: "students", + attributes: { + "first-name": "Danny", + "last-name": "Fritz", + "email": "danny.fritz@gmail.com", + "twitter": "dannyfritz", + "phone": "777-777-7777", + "github": "dannyfritz", + "linkedin": "dannyfritz", + "galvanize-id": "2", + "avatar": "https://www.google.com" + } + }]); + done(); + }).catch(done); + }); + }); describe("#GET /students/:id", function(){ it("displays a single serialized student", done => { request(app)