Commit 3436ebcb authored by Mark Stenglein's avatar Mark Stenglein

Added initial api

- It's connected to the database!!
parent 0dfa592f
Pipeline #690 failed with stage
in 42 seconds
...@@ -13,34 +13,55 @@ var express = require('express') ...@@ -13,34 +13,55 @@ var express = require('express')
var router = express.Router() var router = express.Router()
// var Semester = require('../../models/Semester') // var Semester = require('../../models/Semester')
var ical = require('ical-generator') var ical = require('ical-generator')
// var db = require('models')
var config = require('config') var config = require('config')
// Load site wide configurations // Load site wide configurations
var schoolSlugs = config.get('schoolSlugs') var schoolSlugs = config.get('schoolSlugs')
var db = require('models')
// //////////////////////////////////////////////////////////////////////////// // ////////////////////////////////////////////////////////////////////////////
// JSON API Section // JSON API Section Get school and semester slug listing
// Get school and semester slug listing
router.get('/json/schools', function (req, res, next) { router.get('/json/schools', function (req, res, next) {
res.json(schoolSlugs) db.University.findAll({
attributes: ['slug', 'name', 'website']
}).then(function (query) {
var schools
res.json(query)
})
})
// GET semester slug listing for school
router.get('/json/semesters/:SCHOOLSLUG', function (req, res, next) {
db.Semester.findAll({
attributes: ['slug', 'name'],
where: {
university: req.params['SCHOOLSLUG']
}
}).then(function (query) {
res.json(query)
})
}) })
// GET classes for a semester // GET classes for a semester
router.get('/json/classes/:SEMSLUG', function (req, res, next) { router.get('/json/classes/:SEMSLUG', function (req, res, next) {
// var slug = req.params['SEMSLUG'] db.Section.findAll({
// find each person with matching slug where: {
semester: req.params['SEMSLUG']
// remove unwanted fields from request }
}).then(function (query) {
// excecute the request (caches with redis) res.json(query)
})
// if there was an error or nothing was returned })
// send an error message
// else send out the semester object as json // GET Class information for one course by CRN
router.get('/json/classes/crn/:CRN', function (req, res, next) {
db.Section.findAll({
where: {
crn: req.params['CRN']
}
}).then(function (query) {
res.json(query)
})
}) })
// //////////////////////////////////////////////////////////////////////////// // ////////////////////////////////////////////////////////////////////////////
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment