diff --git a/.gitignore b/.gitignore index 5b61ab0..6db3c9a 100644 --- a/.gitignore +++ b/.gitignore @@ -11,3 +11,5 @@ /log/* !/log/.keep /tmp + +.DS_Store diff --git a/README.md b/README.md index dd4e97e..d477840 100644 --- a/README.md +++ b/README.md @@ -1,28 +1,60 @@ -== README - -This README would normally document whatever steps are necessary to get the -application up and running. - -Things you may want to cover: - -* Ruby version - -* System dependencies - -* Configuration - -* Database creation - -* Database initialization - -* How to run the test suite - -* Services (job queues, cache servers, search engines, etc.) - -* Deployment instructions - -* ... - - -Please feel free to use a different markup language if you do not plan to run -rake doc:app. +# API Docs + +## Classical + +User + Session are all done the 'old fashioned way' via server-rendered erb. + +ROOT (/): Renders the Sign In / Sign Up forms. +POST /users will create a new user, redirect to ROOT +POST /session will create a new session, redirect to SPA page + +--- +## JSON + +GET /current_user will return JSON object containing currently logged in user + +GET /transgressions will return array of transgressions complete with confessions subarray + + ```json + { + transgressions: [ + { + id: 3, + sin_type: "Gluttony", + description: "I love eating a whole box full of cucumbers, like a 20lb box" + confessions: [ + { + description: "Some description", + occurred_at: "3 weeks ago" + } + ] + } + ] + } + ``` + +POST /transgressions will take a JSON object as such: + + ```json + { + authenticity_token: "osmeaksdfiohuiHDFIUSDHFUkjadfhjk324", + transgression: { + sin_type: "Some Sin", + description: "Some Description" + } + } + ``` + + And return the created transgression as an object. + +POST /transgressions/:id/confessions will take a JSON object as such: + + ```json + { + authenticity_token: "adsf123i478KJkhajksldfhjk0", + confession: { + description: "I did a thing", + occurred_at: "2015-03-27" + } + } + ``` diff --git a/app/.DS_Store b/app/.DS_Store deleted file mode 100644 index 84f5661..0000000 Binary files a/app/.DS_Store and /dev/null differ diff --git a/app/assets/javascripts/confessions.coffee b/app/assets/javascripts/confessions.coffee new file mode 100644 index 0000000..24f83d1 --- /dev/null +++ b/app/assets/javascripts/confessions.coffee @@ -0,0 +1,3 @@ +# 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/ diff --git a/app/assets/stylesheets/confessions.scss b/app/assets/stylesheets/confessions.scss new file mode 100644 index 0000000..fc0467c --- /dev/null +++ b/app/assets/stylesheets/confessions.scss @@ -0,0 +1,3 @@ +// Place all the styles related to the confessions controller here. +// They will automatically be included in application.css. +// You can use Sass (SCSS) here: http://sass-lang.com/ diff --git a/app/controllers/confessions_controller.rb b/app/controllers/confessions_controller.rb new file mode 100644 index 0000000..25107d4 --- /dev/null +++ b/app/controllers/confessions_controller.rb @@ -0,0 +1,2 @@ +class ConfessionsController < ApplicationController +end diff --git a/app/controllers/transgressions_controller.rb b/app/controllers/transgressions_controller.rb index 5f7b2ad..9b6ff2b 100644 --- a/app/controllers/transgressions_controller.rb +++ b/app/controllers/transgressions_controller.rb @@ -9,7 +9,9 @@ class TransgressionsController < ApplicationController @transgression = current_user.transgressions .new(transgression_params) - if @transgression.save + @confession = @transgression.confessions.new(confession_params) + + if @transgression.save && @confession.save redirect_to transgressions_path else flash[:message] = @transgression.errors.full_messages.to_sentence @@ -29,6 +31,8 @@ class TransgressionsController < ApplicationController def index @transgressions = current_user.transgressions + .includes(:confessions) + .group_by { |x| x.sin_type } end def delete @@ -40,4 +44,9 @@ class TransgressionsController < ApplicationController return params.require(:transgression) .permit(:sin_type, :description) end + + def confession_params + return params.require(:confession) + .permit(:description, :occurred_at) + end end diff --git a/app/helpers/confessions_helper.rb b/app/helpers/confessions_helper.rb new file mode 100644 index 0000000..0266769 --- /dev/null +++ b/app/helpers/confessions_helper.rb @@ -0,0 +1,2 @@ +module ConfessionsHelper +end diff --git a/app/models/confession.rb b/app/models/confession.rb new file mode 100644 index 0000000..49c719c --- /dev/null +++ b/app/models/confession.rb @@ -0,0 +1,8 @@ +class Confession < ActiveRecord::Base + validates :description, presence: true + validates :transgression, presence: true + validates :occurred_at, presence: true + + belongs_to :transgression + delegate :sinner, to: :transgression +end diff --git a/app/models/transgression.rb b/app/models/transgression.rb index 7f4c475..e47ff6b 100644 --- a/app/models/transgression.rb +++ b/app/models/transgression.rb @@ -5,10 +5,14 @@ class Transgression < ActiveRecord::Base ] validates :description, presence: true - validates :user, presence: true + validates :sinner, presence: true validates :sin_type, inclusion: { in: SIN_TYPES } - belongs_to :user + # belongs_to :sinner, it would assume there is a Sinner Class, as well as a sinner_id column in this table + + belongs_to :sinner, class_name: "User", foreign_key: :user_id + + has_many :confessions, dependent: :destroy end # Transgression::SIN_TYPES diff --git a/app/models/user.rb b/app/models/user.rb index 8e0dc61..0e76bb5 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -8,5 +8,6 @@ class User < ActiveRecord::Base minimum: 8, allow_nil: true } - has_many :transgressions + has_many :transgressions, dependent: :destroy + has_many :confessions, through: :transgressions end diff --git a/app/views/transgressions/index.html.erb b/app/views/transgressions/index.html.erb index f2add68..c252c40 100644 --- a/app/views/transgressions/index.html.erb +++ b/app/views/transgressions/index.html.erb @@ -1,3 +1,22 @@ -<% @transgressions.each do |trans| %> -