From 34aa3c01a83127a4992b73a1055a86b6d4acfc63 Mon Sep 17 00:00:00 2001 From: Ben Muschol Date: Wed, 19 Apr 2017 16:47:44 -0400 Subject: [PATCH 1/4] integrate gem into back-end --- Gemfile | 1 + Gemfile.lock | 4 ++ app/controllers/api/application_controller.rb | 7 ++++ app/controllers/api/debaters_controller.rb | 5 +++ app/controllers/api/schools_controller.rb | 5 +++ app/controllers/schools_controller.rb | 41 ------------------- app/resoucres/api/debater_resource.rb | 8 ++++ app/resoucres/api/school_resource.rb | 6 +++ app/resoucres/api/team_resource.rb | 8 ++++ .../components/debaters/DebaterContainer.js | 2 +- client/app/components/debaters/DebaterItem.js | 2 +- client/app/components/schools/SchoolDetail.js | 2 +- client/app/components/schools/SchoolItem.js | 2 +- .../components/schools/SchoolSelectField.js | 2 +- client/app/resources/Resource.js | 16 ++------ config/routes.rb | 19 ++++----- 16 files changed, 60 insertions(+), 70 deletions(-) create mode 100644 app/controllers/api/application_controller.rb create mode 100644 app/controllers/api/debaters_controller.rb create mode 100644 app/controllers/api/schools_controller.rb create mode 100644 app/resoucres/api/debater_resource.rb create mode 100644 app/resoucres/api/school_resource.rb create mode 100644 app/resoucres/api/team_resource.rb diff --git a/Gemfile b/Gemfile index d89ee41..9e127e7 100644 --- a/Gemfile +++ b/Gemfile @@ -13,6 +13,7 @@ gem 'skylight' # application performance monitoring gem 'sprockets', '>= 3.0.0' gem 'uglifier' gem 'graph_matching' # max-weight matching algorithm used to pair +gem 'jsonapi-resources' # API is build around this gem # front-end libraries gem 'react_on_rails' diff --git a/Gemfile.lock b/Gemfile.lock index 21fb39e..e8a161c 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -109,6 +109,9 @@ GEM hashdiff (0.3.2) i18n (0.8.1) json (2.1.0) + jsonapi-resources (0.8.3) + concurrent-ruby + rails (>= 4.0) lazy_priority_queue (0.1.1) libv8 (5.3.332.38.5) listen (3.1.5) @@ -300,6 +303,7 @@ DEPENDENCIES faker formulaic graph_matching + jsonapi-resources listen mini_racer normalize-rails diff --git a/app/controllers/api/application_controller.rb b/app/controllers/api/application_controller.rb new file mode 100644 index 0000000..de913d7 --- /dev/null +++ b/app/controllers/api/application_controller.rb @@ -0,0 +1,7 @@ +# frozen_string_literal: true +module Api + class ApplicationController < ::ApplicationController + include JSONAPI::ActsAsResourceController + protect_from_forgery with: :null_session + end +end diff --git a/app/controllers/api/debaters_controller.rb b/app/controllers/api/debaters_controller.rb new file mode 100644 index 0000000..51d84ca --- /dev/null +++ b/app/controllers/api/debaters_controller.rb @@ -0,0 +1,5 @@ +# frozen_string_literal: true +module Api + class DebatersController < ApplicationController + end +end diff --git a/app/controllers/api/schools_controller.rb b/app/controllers/api/schools_controller.rb new file mode 100644 index 0000000..fe70ddc --- /dev/null +++ b/app/controllers/api/schools_controller.rb @@ -0,0 +1,5 @@ +# frozen_string_literal: true +module Api + class SchoolsController < ApplicationController + end +end diff --git a/app/controllers/schools_controller.rb b/app/controllers/schools_controller.rb index 12fde9d..9f10ebf 100644 --- a/app/controllers/schools_controller.rb +++ b/app/controllers/schools_controller.rb @@ -2,50 +2,9 @@ class SchoolsController < ApplicationController def index @schools = School.order(:name).map(&:as_json) - respond_to do |format| - format.html { render :index } - format.json { render json: @schools } - end - end - - def create - @school = School.new(school_params) - if @school.save - render json: @school - else - render json: @school.errors, status: :unprocessable - end end def show @school = School.find(params[:id]).as_json - respond_to do |format| - format.html { render :show } - format.json { render json: @school } - end - end - - def update - @school = School.find(params[:id]) - if @school.update(school_params) - render json: @school - else - render json: @school.errors, status: :unprocessable - end - end - - def destroy - @school = School.find(params[:id]) - if @school.destroy - render json: {}, status: 200 - else - render json: {}, status: :unprocessable - end - end - - private - - def school_params - params.require(:school).permit(:name) end end diff --git a/app/resoucres/api/debater_resource.rb b/app/resoucres/api/debater_resource.rb new file mode 100644 index 0000000..8c34b85 --- /dev/null +++ b/app/resoucres/api/debater_resource.rb @@ -0,0 +1,8 @@ +# frozen_string_literal: true +module Api + class DebaterResource < JSONAPI::Resource + attributes :name, :novice + belongs_to :team + belongs_to :school + end +end diff --git a/app/resoucres/api/school_resource.rb b/app/resoucres/api/school_resource.rb new file mode 100644 index 0000000..975750f --- /dev/null +++ b/app/resoucres/api/school_resource.rb @@ -0,0 +1,6 @@ +# frozen_string_literal: true +module Api + class SchoolResource < JSONAPI::Resource + attributes :name + end +end diff --git a/app/resoucres/api/team_resource.rb b/app/resoucres/api/team_resource.rb new file mode 100644 index 0000000..2b4cc09 --- /dev/null +++ b/app/resoucres/api/team_resource.rb @@ -0,0 +1,8 @@ +# frozen_string_literal: true +module Api + class TeamResource < JSONAPI::Resource + attributes :name, :seed + has_many :debaters + belongs_to :school + end +end diff --git a/client/app/components/debaters/DebaterContainer.js b/client/app/components/debaters/DebaterContainer.js index a3f2687..9394564 100644 --- a/client/app/components/debaters/DebaterContainer.js +++ b/client/app/components/debaters/DebaterContainer.js @@ -39,7 +39,7 @@ export class DebaterContainer extends React.Component { const confirmed = confirm('Are you sure? This will delete all of this debaters stats and affect their team speaks') if (confirmed) { debater.destroy() - .then(() => window.location = debater.pathTo().index) + .then(() => window.location = debater.pathTo(false).index) .catch(() => this.setState({ message: 'Could not delete this debater' })) } } diff --git a/client/app/components/debaters/DebaterItem.js b/client/app/components/debaters/DebaterItem.js index 8ff155b..3a77b80 100644 --- a/client/app/components/debaters/DebaterItem.js +++ b/client/app/components/debaters/DebaterItem.js @@ -4,7 +4,7 @@ import Debater from '../../resources/Debater' export const DebaterItem = (props) => { const debater = new Debater(props.id) return ( -
  • {props.name} ({props.school.name})
  • +
  • {props.name} ({props.school.name})
  • ) } diff --git a/client/app/components/schools/SchoolDetail.js b/client/app/components/schools/SchoolDetail.js index 0952dd1..471018f 100644 --- a/client/app/components/schools/SchoolDetail.js +++ b/client/app/components/schools/SchoolDetail.js @@ -19,7 +19,7 @@ class SchoolDetail extends React.Component { const school = this.getSchoolObject() if (confirmed) { school.destroy() - .then((response) => window.location = school.pathTo().index) + .then((response) => window.location = school.pathTo(false).index) .catch(() => this.setState({message: 'Could not delete school.'})) } } diff --git a/client/app/components/schools/SchoolItem.js b/client/app/components/schools/SchoolItem.js index 859c8b3..b73284f 100644 --- a/client/app/components/schools/SchoolItem.js +++ b/client/app/components/schools/SchoolItem.js @@ -3,7 +3,7 @@ import School from '../../resources/School' export const SchoolItem = (props) => { return ( -
  • {props.name}
  • +
  • {props.name}
  • ) } diff --git a/client/app/components/schools/SchoolSelectField.js b/client/app/components/schools/SchoolSelectField.js index 4cf0357..20b9e68 100644 --- a/client/app/components/schools/SchoolSelectField.js +++ b/client/app/components/schools/SchoolSelectField.js @@ -41,7 +41,7 @@ export default class SchoolSelectField extends React.Component { } componentDidMount() { - new School().index('json') + new School().index() .then((response) => this.setState({schools: response.data})) } diff --git a/client/app/resources/Resource.js b/client/app/resources/Resource.js index 995f4ab..46309fa 100644 --- a/client/app/resources/Resource.js +++ b/client/app/resources/Resource.js @@ -25,11 +25,11 @@ export default class Resource { return {authenticity_token: ReactOnRails.authenticityToken()} } - index = (ext) => { + index = (api=true) => { return axios.get(this.pathTo().index + this._extension(ext), this.authenticityTokenObject()) } - new = (ext) => { + new = (api=true) => { return axios.get(this.pathTo().new + this._extension(ext), this.authenticityTokenObject()) } @@ -40,11 +40,11 @@ export default class Resource { .post(this.pathTo().create + this._extension(ext), {...data, ...this.authenticityTokenObject()}) } - show = (ext) => { + show = (api=true) => { return axios.get(this.pathTo().show + this._extension(ext), this.authenticityTokenObject()) } - edit = (ext) => { + edit = (api=true) => { return axios.get(this.pathTo().edit + this._extension(ext), this.authenticityTokenObject()) } @@ -62,12 +62,4 @@ export default class Resource { data: this.authenticityTokenObject() }) } - - _extension(extension) { - if (extension) { - return `.${extension}` - } else { - return '' - } - } } diff --git a/config/routes.rb b/config/routes.rb index 09a77a2..dcd10b4 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,15 +1,10 @@ Rails.application.routes.draw do - resources :debaters - get 'debaters/index' - - get 'debaters/create' - - get 'debaters/show' - - get 'debaters/update' - - get 'debaters/destroy' - root 'application#index' - resources :schools, only: [:index, :create, :show, :update, :destroy] + resources :debaters, only: [:index, :show] + resource :schools, only: [:index, :show] + + namespace :api do + jsonapi_resources :schools + jsonapi_resources :debaters + end end From 236ce03aaa3007309ed38f05648f0ad815e7e4fb Mon Sep 17 00:00:00 2001 From: Ben Muschol Date: Wed, 19 Apr 2017 17:21:28 -0400 Subject: [PATCH 2/4] wip integrate on front-end --- app/controllers/api/application_controller.rb | 5 ++-- .../components/debaters/DebaterContainer.js | 6 ++--- .../app/components/debaters/DebaterDetail.js | 2 +- client/app/components/debaters/DebaterForm.js | 4 +-- client/app/components/debaters/DebaterItem.js | 4 +-- client/app/components/schools/SchoolDetail.js | 13 +++------- client/app/components/schools/SchoolItem.js | 4 +-- .../components/schools/SchoolListContainer.js | 4 +-- .../components/schools/SchoolSelectField.js | 6 ++--- client/app/resources/ApiResource.js | 21 +++++++++++++++ client/app/resources/Debater.js | 9 ++++++- client/app/resources/Resource.js | 26 +++++++++---------- client/app/resources/School.js | 9 ++++++- 13 files changed, 72 insertions(+), 41 deletions(-) create mode 100644 client/app/resources/ApiResource.js diff --git a/app/controllers/api/application_controller.rb b/app/controllers/api/application_controller.rb index de913d7..c0e6e78 100644 --- a/app/controllers/api/application_controller.rb +++ b/app/controllers/api/application_controller.rb @@ -1,7 +1,8 @@ # frozen_string_literal: true module Api - class ApplicationController < ::ApplicationController - include JSONAPI::ActsAsResourceController + class ApplicationController < JSONAPI::ResourceController + skip_before_action :ensure_correct_media_type + skip_before_action :ensure_valid_accept_media_type protect_from_forgery with: :null_session end end diff --git a/client/app/components/debaters/DebaterContainer.js b/client/app/components/debaters/DebaterContainer.js index 9394564..52ba473 100644 --- a/client/app/components/debaters/DebaterContainer.js +++ b/client/app/components/debaters/DebaterContainer.js @@ -1,7 +1,7 @@ import React from 'react' import {Button} from 'react-bootstrap' import {DebaterForm, DebaterDetail} from './index' -import Debater from '../../resources/Debater' +import {Debater, ApiDebater} from '../../resources/Debater' export class DebaterContainer extends React.Component { static propTypes = { @@ -35,11 +35,11 @@ export class DebaterContainer extends React.Component { handleEditClick = () => this.setState({ isEditing: true }) handleDeleteClick = () => { - const debater = new Debater(this.state.debater.id) + const debater = new ApiDebater(this.state.debater.id) const confirmed = confirm('Are you sure? This will delete all of this debaters stats and affect their team speaks') if (confirmed) { debater.destroy() - .then(() => window.location = debater.pathTo(false).index) + .then(() => window.location = new Debater().pathTo(false).index) .catch(() => this.setState({ message: 'Could not delete this debater' })) } } diff --git a/client/app/components/debaters/DebaterDetail.js b/client/app/components/debaters/DebaterDetail.js index ccc1ee1..3e8bb75 100644 --- a/client/app/components/debaters/DebaterDetail.js +++ b/client/app/components/debaters/DebaterDetail.js @@ -1,5 +1,5 @@ import React from 'react'; -import School from '../../resources/School' +import {School} from '../../resources/School' export const DebaterDetail = (props) => { const school = new School(props.school.id) diff --git a/client/app/components/debaters/DebaterForm.js b/client/app/components/debaters/DebaterForm.js index 525a9e2..29dd757 100644 --- a/client/app/components/debaters/DebaterForm.js +++ b/client/app/components/debaters/DebaterForm.js @@ -1,6 +1,6 @@ import React from 'react' import {FormControl, ControlLabel, FormGroup, Button} from 'react-bootstrap' -import Debater from '../../resources/Debater' +import {ApiDebater} from '../../resources/Debater' import SchoolSelectField from '../schools/SchoolSelectField' export class DebaterForm extends React.Component { @@ -27,7 +27,7 @@ export class DebaterForm extends React.Component { handleSubmit = (event) => { event.preventDefault() - const debater = new Debater(this.props.id) + const debater = new ApiDebater(this.props.id) let request = this.props.id ? debater.update : debater.create request(this.paramsToSubmit()) .then((response) => this.props.handleSuccessfulSubmit(response)) diff --git a/client/app/components/debaters/DebaterItem.js b/client/app/components/debaters/DebaterItem.js index 3a77b80..fbab152 100644 --- a/client/app/components/debaters/DebaterItem.js +++ b/client/app/components/debaters/DebaterItem.js @@ -1,10 +1,10 @@ import React from 'react' -import Debater from '../../resources/Debater' +import {Debater} from '../../resources/Debater' export const DebaterItem = (props) => { const debater = new Debater(props.id) return ( -
  • {props.name} ({props.school.name})
  • +
  • {props.name} ({props.school.name})
  • ) } diff --git a/client/app/components/schools/SchoolDetail.js b/client/app/components/schools/SchoolDetail.js index 471018f..9d3be1b 100644 --- a/client/app/components/schools/SchoolDetail.js +++ b/client/app/components/schools/SchoolDetail.js @@ -1,7 +1,7 @@ import React, {PropTypes} from 'react' import {Button} from 'react-bootstrap' import EditableText from '../shared/EditableText' -import School from '../../resources/School' +import {School, ApiSchool} from '../../resources/School' class SchoolDetail extends React.Component { state = { @@ -16,17 +16,16 @@ class SchoolDetail extends React.Component { deleteSchool = (event) => { event.preventDefault() let confirmed = confirm('Are you sure? This will delete all of the debaters and judges') - const school = this.getSchoolObject() if (confirmed) { - school.destroy() - .then((response) => window.location = school.pathTo(false).index) + new ApiSchool(this.state.school.id).destroy() + .then((response) => window.location = new School.pathTo().index) .catch(() => this.setState({message: 'Could not delete school.'})) } } handleNameUpdate = (name) => { if (name.trim() !== this.state.school.name) { - this.getSchoolObject().update({name}) + new ApiSchool(this.state.school.id).update({name}) .then((response) => { this.flashMessage('School updated!') this.setState({school: response.data}) @@ -40,10 +39,6 @@ class SchoolDetail extends React.Component { setTimeout(() => this.setState({message: ''}), 2500) } - getSchoolObject () { - return new School(this.state.school.id) - } - render () { return (
    diff --git a/client/app/components/schools/SchoolItem.js b/client/app/components/schools/SchoolItem.js index b73284f..cec4fda 100644 --- a/client/app/components/schools/SchoolItem.js +++ b/client/app/components/schools/SchoolItem.js @@ -1,9 +1,9 @@ import React from 'react' -import School from '../../resources/School' +import {School} from '../../resources/School' export const SchoolItem = (props) => { return ( -
  • {props.name}
  • +
  • {props.name}
  • ) } diff --git a/client/app/components/schools/SchoolListContainer.js b/client/app/components/schools/SchoolListContainer.js index 1e8dab0..f81a455 100644 --- a/client/app/components/schools/SchoolListContainer.js +++ b/client/app/components/schools/SchoolListContainer.js @@ -2,7 +2,7 @@ import React from 'react' import _ from 'lodash' import {SchoolList} from './SchoolList' import {CreateSchool} from './CreateSchool' -import School from '../../resources/School' +import {ApiSchool} from '../../resources/School' export class SchoolListContainer extends React.Component { static propTypes = { @@ -17,7 +17,7 @@ export class SchoolListContainer extends React.Component { handleAddSchool = (event) => { event.preventDefault() - new School().create({name: this.state.newSchool}) + new ApiSchool().create({name: this.state.newSchool}) .then((response) => { const newSchool = response.data this.setState({ diff --git a/client/app/components/schools/SchoolSelectField.js b/client/app/components/schools/SchoolSelectField.js index 20b9e68..afef903 100644 --- a/client/app/components/schools/SchoolSelectField.js +++ b/client/app/components/schools/SchoolSelectField.js @@ -1,7 +1,7 @@ import React from 'react' import Autosuggest from 'react-autosuggest' import {ControlLabel, FormGroup} from 'react-bootstrap' -import School from '../../resources/School' +import {ApiSchool} from '../../resources/School' const preprocessName = (name) => name.trim().toLowerCase() @@ -41,8 +41,8 @@ export default class SchoolSelectField extends React.Component { } componentDidMount() { - new School().index() - .then((response) => this.setState({schools: response.data})) + new ApiSchool().index() + .then((response) => this.setState({schools: response.data.data})) } onSuggestionsClearRequested = () => { diff --git a/client/app/resources/ApiResource.js b/client/app/resources/ApiResource.js new file mode 100644 index 0000000..a5a3cb4 --- /dev/null +++ b/client/app/resources/ApiResource.js @@ -0,0 +1,21 @@ +import Resource from './Resource' + +export default class ApiResource extends Resource { + constructor(name, id) { + super(name, id) + } + + pathTo = () => { + const listPath = `/api/${this.name}s` + const individualPath = `${listPath}/${this.id}` + return { + index: listPath, + new: `${listPath}/new`, + create: listPath, + show: individualPath, + edit: `${individualPath}/edit`, + update: individualPath, + destroy: individualPath + } + } +} diff --git a/client/app/resources/Debater.js b/client/app/resources/Debater.js index 1cd51aa..c864e29 100644 --- a/client/app/resources/Debater.js +++ b/client/app/resources/Debater.js @@ -1,6 +1,13 @@ import Resource from './Resource' +import ApiResource from './ApiResource' -export default class Debater extends Resource { +export class Debater extends Resource { + constructor (id) { + super('debater', id) + } +} + +export class ApiDebater extends ApiResource { constructor (id) { super('debater', id) } diff --git a/client/app/resources/Resource.js b/client/app/resources/Resource.js index 46309fa..5024a35 100644 --- a/client/app/resources/Resource.js +++ b/client/app/resources/Resource.js @@ -2,7 +2,7 @@ import axios from 'axios' import ReactOnRails from 'react-on-rails' export default class Resource { - constructor (name, id) { + constructor(name, id) { this.name = name this.id = id } @@ -25,39 +25,39 @@ export default class Resource { return {authenticity_token: ReactOnRails.authenticityToken()} } - index = (api=true) => { - return axios.get(this.pathTo().index + this._extension(ext), this.authenticityTokenObject()) + index = () => { + return axios.get(this.pathTo().index, this.authenticityTokenObject()) } - new = (api=true) => { - return axios.get(this.pathTo().new + this._extension(ext), this.authenticityTokenObject()) + new = () => { + return axios.get(this.pathTo().new, this.authenticityTokenObject()) } create = (resourceData, ext) => { let data = {} data[this.name] = resourceData return axios - .post(this.pathTo().create + this._extension(ext), {...data, ...this.authenticityTokenObject()}) + .post(this.pathTo().create, {...data, ...this.authenticityTokenObject()}) } - show = (api=true) => { - return axios.get(this.pathTo().show + this._extension(ext), this.authenticityTokenObject()) + show = () => { + return axios.get(this.pathTo().show, this.authenticityTokenObject()) } - edit = (api=true) => { - return axios.get(this.pathTo().edit + this._extension(ext), this.authenticityTokenObject()) + edit = () => { + return axios.get(this.pathTo().edit, this.authenticityTokenObject()) } update = (resourceData, ext) => { let data = {} data[this.name] = resourceData return axios - .put(this.pathTo().update + this._extension(ext), {...data, ...this.authenticityTokenObject()}) + .put(this.pathTo().update, {...data, ...this.authenticityTokenObject()}) } - destroy = (ext) => { + destroy = () => { return axios.request({ - url: this.pathTo().destroy + this._extension(ext), + url: this.pathTo().destroy, method: 'DELETE', data: this.authenticityTokenObject() }) diff --git a/client/app/resources/School.js b/client/app/resources/School.js index cb5862a..56aa446 100644 --- a/client/app/resources/School.js +++ b/client/app/resources/School.js @@ -1,6 +1,13 @@ import Resource from './Resource' +import ApiResource from './ApiResource' -export default class School extends Resource { +export class School extends Resource { + constructor (id) { + super('school', id) + } +} + +export class ApiSchool extends ApiResource { constructor (id) { super('school', id) } From 99651e739e95009e18e80b5dd863085171170689 Mon Sep 17 00:00:00 2001 From: Ben Muschol Date: Fri, 21 Apr 2017 10:55:59 -0400 Subject: [PATCH 3/4] clean up naming --- app/controllers/api/debaters_controller.rb | 1 + app/controllers/api/schools_controller.rb | 1 + app/resoucres/api/debater_resource.rb | 8 -------- app/resoucres/api/school_resource.rb | 6 ------ app/resoucres/api/team_resource.rb | 8 -------- app/resoucres/debater_resource.rb | 6 ++++++ app/resoucres/school_resource.rb | 4 ++++ app/resoucres/team_resource.rb | 6 ++++++ 8 files changed, 18 insertions(+), 22 deletions(-) delete mode 100644 app/resoucres/api/debater_resource.rb delete mode 100644 app/resoucres/api/school_resource.rb delete mode 100644 app/resoucres/api/team_resource.rb create mode 100644 app/resoucres/debater_resource.rb create mode 100644 app/resoucres/school_resource.rb create mode 100644 app/resoucres/team_resource.rb diff --git a/app/controllers/api/debaters_controller.rb b/app/controllers/api/debaters_controller.rb index 51d84ca..515baca 100644 --- a/app/controllers/api/debaters_controller.rb +++ b/app/controllers/api/debaters_controller.rb @@ -1,5 +1,6 @@ # frozen_string_literal: true module Api class DebatersController < ApplicationController + model_name 'Debater' end end diff --git a/app/controllers/api/schools_controller.rb b/app/controllers/api/schools_controller.rb index fe70ddc..2fe8233 100644 --- a/app/controllers/api/schools_controller.rb +++ b/app/controllers/api/schools_controller.rb @@ -1,5 +1,6 @@ # frozen_string_literal: true module Api class SchoolsController < ApplicationController + model_name 'School' end end diff --git a/app/resoucres/api/debater_resource.rb b/app/resoucres/api/debater_resource.rb deleted file mode 100644 index 8c34b85..0000000 --- a/app/resoucres/api/debater_resource.rb +++ /dev/null @@ -1,8 +0,0 @@ -# frozen_string_literal: true -module Api - class DebaterResource < JSONAPI::Resource - attributes :name, :novice - belongs_to :team - belongs_to :school - end -end diff --git a/app/resoucres/api/school_resource.rb b/app/resoucres/api/school_resource.rb deleted file mode 100644 index 975750f..0000000 --- a/app/resoucres/api/school_resource.rb +++ /dev/null @@ -1,6 +0,0 @@ -# frozen_string_literal: true -module Api - class SchoolResource < JSONAPI::Resource - attributes :name - end -end diff --git a/app/resoucres/api/team_resource.rb b/app/resoucres/api/team_resource.rb deleted file mode 100644 index 2b4cc09..0000000 --- a/app/resoucres/api/team_resource.rb +++ /dev/null @@ -1,8 +0,0 @@ -# frozen_string_literal: true -module Api - class TeamResource < JSONAPI::Resource - attributes :name, :seed - has_many :debaters - belongs_to :school - end -end diff --git a/app/resoucres/debater_resource.rb b/app/resoucres/debater_resource.rb new file mode 100644 index 0000000..4977456 --- /dev/null +++ b/app/resoucres/debater_resource.rb @@ -0,0 +1,6 @@ +# frozen_string_literal: true +class DebaterResource < JSONAPI::Resource + attributes :name, :novice + belongs_to :team + belongs_to :school +end diff --git a/app/resoucres/school_resource.rb b/app/resoucres/school_resource.rb new file mode 100644 index 0000000..91350ef --- /dev/null +++ b/app/resoucres/school_resource.rb @@ -0,0 +1,4 @@ +# frozen_string_literal: true +class SchoolResource < JSONAPI::Resource + attributes :name +end diff --git a/app/resoucres/team_resource.rb b/app/resoucres/team_resource.rb new file mode 100644 index 0000000..e39d921 --- /dev/null +++ b/app/resoucres/team_resource.rb @@ -0,0 +1,6 @@ +# frozen_string_literal: true +class TeamResource < JSONAPI::Resource + attributes :name, :seed + has_many :debaters + belongs_to :school +end From f6aace3937a5b8f6c28466171744e3af75634daf Mon Sep 17 00:00:00 2001 From: Ben Muschol Date: Thu, 27 Apr 2017 18:06:56 -0400 Subject: [PATCH 4/4] accept my nested namespace overlords --- app/controllers/api/debaters_controller.rb | 1 - app/controllers/api/schools_controller.rb | 1 - app/resoucres/api/debater_resource.rb | 8 ++++++++ app/resoucres/api/school_resource.rb | 6 ++++++ app/resoucres/api/team_resource.rb | 8 ++++++++ app/resoucres/debater_resource.rb | 6 ------ app/resoucres/school_resource.rb | 4 ---- app/resoucres/team_resource.rb | 6 ------ 8 files changed, 22 insertions(+), 18 deletions(-) create mode 100644 app/resoucres/api/debater_resource.rb create mode 100644 app/resoucres/api/school_resource.rb create mode 100644 app/resoucres/api/team_resource.rb delete mode 100644 app/resoucres/debater_resource.rb delete mode 100644 app/resoucres/school_resource.rb delete mode 100644 app/resoucres/team_resource.rb diff --git a/app/controllers/api/debaters_controller.rb b/app/controllers/api/debaters_controller.rb index 515baca..51d84ca 100644 --- a/app/controllers/api/debaters_controller.rb +++ b/app/controllers/api/debaters_controller.rb @@ -1,6 +1,5 @@ # frozen_string_literal: true module Api class DebatersController < ApplicationController - model_name 'Debater' end end diff --git a/app/controllers/api/schools_controller.rb b/app/controllers/api/schools_controller.rb index 2fe8233..fe70ddc 100644 --- a/app/controllers/api/schools_controller.rb +++ b/app/controllers/api/schools_controller.rb @@ -1,6 +1,5 @@ # frozen_string_literal: true module Api class SchoolsController < ApplicationController - model_name 'School' end end diff --git a/app/resoucres/api/debater_resource.rb b/app/resoucres/api/debater_resource.rb new file mode 100644 index 0000000..8c34b85 --- /dev/null +++ b/app/resoucres/api/debater_resource.rb @@ -0,0 +1,8 @@ +# frozen_string_literal: true +module Api + class DebaterResource < JSONAPI::Resource + attributes :name, :novice + belongs_to :team + belongs_to :school + end +end diff --git a/app/resoucres/api/school_resource.rb b/app/resoucres/api/school_resource.rb new file mode 100644 index 0000000..975750f --- /dev/null +++ b/app/resoucres/api/school_resource.rb @@ -0,0 +1,6 @@ +# frozen_string_literal: true +module Api + class SchoolResource < JSONAPI::Resource + attributes :name + end +end diff --git a/app/resoucres/api/team_resource.rb b/app/resoucres/api/team_resource.rb new file mode 100644 index 0000000..2b4cc09 --- /dev/null +++ b/app/resoucres/api/team_resource.rb @@ -0,0 +1,8 @@ +# frozen_string_literal: true +module Api + class TeamResource < JSONAPI::Resource + attributes :name, :seed + has_many :debaters + belongs_to :school + end +end diff --git a/app/resoucres/debater_resource.rb b/app/resoucres/debater_resource.rb deleted file mode 100644 index 4977456..0000000 --- a/app/resoucres/debater_resource.rb +++ /dev/null @@ -1,6 +0,0 @@ -# frozen_string_literal: true -class DebaterResource < JSONAPI::Resource - attributes :name, :novice - belongs_to :team - belongs_to :school -end diff --git a/app/resoucres/school_resource.rb b/app/resoucres/school_resource.rb deleted file mode 100644 index 91350ef..0000000 --- a/app/resoucres/school_resource.rb +++ /dev/null @@ -1,4 +0,0 @@ -# frozen_string_literal: true -class SchoolResource < JSONAPI::Resource - attributes :name -end diff --git a/app/resoucres/team_resource.rb b/app/resoucres/team_resource.rb deleted file mode 100644 index e39d921..0000000 --- a/app/resoucres/team_resource.rb +++ /dev/null @@ -1,6 +0,0 @@ -# frozen_string_literal: true -class TeamResource < JSONAPI::Resource - attributes :name, :seed - has_many :debaters - belongs_to :school -end