Commit c2669df4 authored by Zac Wood's avatar Zac Wood

Added controllers + docs

parent 212e258a
......@@ -121,6 +121,9 @@ GEM
rb-fsevent (0.10.3)
rb-inotify (0.9.10)
ffi (>= 0.5.0, < 2)
rubyXL (3.3.29)
nokogiri (>= 1.4.4)
rubyzip (>= 1.1.6)
ruby_dep (1.5.0)
rubyzip (1.2.1)
sass (3.5.6)
......@@ -182,6 +185,7 @@ DEPENDENCIES
listen (>= 3.0.5, < 3.2)
puma (~> 3.7)
rails (~> 5.1.6)
rubyXL
sass-rails (~> 5.0)
selenium-webdriver
spring
......
# Place all the behaviors and hooks related to the matching controller here.
# All this logic will automatically be available in application.js.
# You can use CoffeeScript in this file: http://coffeescript.org/
# Place all the behaviors and hooks related to the matching controller here.
# All this logic will automatically be available in application.js.
# You can use CoffeeScript in this file: http://coffeescript.org/
// Place all the styles related to the Courses controller here.
// They will automatically be included in application.css.
// You can use Sass (SCSS) here: http://sass-lang.com/
// Place all the styles related to the Sections controller here.
// They will automatically be included in application.css.
// You can use Sass (SCSS) here: http://sass-lang.com/
# Contains all actions having to do with Courses.
class CoursesController < ApplicationController
# Renders JSON of all courses.
def index
@courses = Course.all
render json: @courses
end
end
# Contains all actions having to do with Sections.
# This is a nested controller -- see +config/routes.rb+ for details
class SectionsController < ApplicationController
# Render JSON of all Sections belonging to a given Course.
def index
@course = Course.find(params[:course_id])
@sections = @course.sections
render json: @sections
end
end
# Contains logic regarding the +Course+ model.
#
# TODO: Add more docs
class Course < ApplicationRecord
# Each course belongs to a +Semester+
belongs_to :semester
# Ensure all necessary fields are present.
validates :course_number, presence: true
validates :subject, presence: true
validates :semester_id, presence: true
# Returns all +Section+ objects that belong to this course.
def sections
Section.where :course_id => id
end
end
# Contains logic belonging to the +Section+ model.
#
# TODO: Add more docs
class Section < ApplicationRecord
# Each +Section+ belongs to a +Course+.
belongs_to :course
# Ensure all necessary fields are present.
validates :name, presence: true
validates :crn, presence: true
# Unsure if necessary
# validates :section_type, presence: true
validates :title, presence: true
validates :start_date, presence: true
validates :end_date, presence: true
validates :days, presence: true
validates :start_time, presence: true
validates :end_time, presence: true
end
# Contains logic having to do with the +Semester+ model.
#
# A +Semester+ is a simple model that consists of a +year+ and a +season+, e.g. "Fall 2018".
class Semester < ApplicationRecord
# Ensure necessary fields are present.
validates :year, presence: true
validates :season, presence: true
end
<h1>Courses#index</h1>
<p>Find me in app/views/courses/index.html.erb</p>
<h1>Sections#index</h1>
<p>Find me in app/views/sections/index.html.erb</p>
Rails.application.routes.draw do
resources :courses, only: [:index] do
resources :sections, only: [:index]
end
root 'courses#index'
# For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html
end
require 'test_helper'
class CoursesControllerTest < ActionDispatch::IntegrationTest
test "should get index" do
get courses_index_url
assert_response :success
end
end
require 'test_helper'
class SectionsControllerTest < ActionDispatch::IntegrationTest
test "should get index" do
get sections_index_url
assert_response :success
end
end
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