Dpalazzari/johari_window_api

View on GitHub
app/controllers/api/v1/users/descriptions_controller.rb

Summary

Maintainability
A
0 mins
Test Coverage
class Api::V1::Users::DescriptionsController < Api::V1::BaseController

  def index
    describee = User.find(params[:id])
    render json: Johari.new(describee).format_descriptions 
  end
  
  def create
    describee    = User.find(params[:id])
    descriptions = JSON.parse(request.body.read)
    describer    = User.find(descriptions['describer_id'])
    render status: 401 and return if Assignment.invalid?(describee.id, describer.id)
    describee.create_descriptions(descriptions['johari'], describer)
    if describee.all_descriptions_completed?(describer.id, descriptions['johari'])
      Assignment.complete(describee.id, describer.id)
      render status: 202
    else
      render status: 304
    end
  end

end