Browse Source

Add show method to JSON API and document not found response

pull/53/head
baarkerlounger 4 years ago
parent
commit
5c409d8c40
  1. 15
      app/controllers/case_logs_controller.rb
  2. 42
      docs/api/DLUHC-CORE-Data.v1.json
  3. 18
      spec/requests/case_log_controller_spec.rb

15
app/controllers/case_logs_controller.rb

@ -33,9 +33,18 @@ class CaseLogsController < ApplicationController
end
end
# We don't have a dedicated non-editable show view
def show
edit
respond_to do |format|
# We don't have a dedicated non-editable show view
format.html { edit }
format.json do
if (case_log = CaseLog.find_by(id: params[:id]))
render json: case_log, status: :ok
else
render json: { error: "Case Log #{params[:id]} not found" }, status: :not_found
end
end
end
end
def edit
@ -90,7 +99,7 @@ class CaseLogsController < ApplicationController
private
API_ACTIONS = %w[create update destroy].freeze
API_ACTIONS = %w[create show update destroy].freeze
def question_responses(questions_for_page)
questions_for_page.each_with_object({}) do |(question_key, question_info), result|

42
docs/api/DLUHC-CORE-Data.v1.json

@ -30,7 +30,22 @@
}
},
"404": {
"description": "Not Found"
"description": "Not Found",
"content": {
"application/json": {
"schema": {
"type": "object",
"properties": {}
},
"examples": {
"Not found": {
"value": {
"error": "Case Log 67 not found"
}
}
}
}
}
}
},
"operationId": "get-case_logs-case_logs-:id",
@ -70,7 +85,13 @@
"type": "object",
"properties": {}
},
"examples": {}
"examples": {
"Not found": {
"value": {
"error": "Case Log 67 not found"
}
}
}
}
}
},
@ -127,7 +148,22 @@
"description": "No Content"
},
"404": {
"description": "Not Found"
"description": "Not Found",
"content": {
"application/json": {
"schema": {
"type": "object",
"properties": {}
},
"examples": {
"Not found": {
"value": {
"error": "Case Log 67 not found"
}
}
}
}
}
}
},
"description": "Delete a case log",

18
spec/requests/case_log_controller_spec.rb

@ -99,6 +99,24 @@ RSpec.describe CaseLogsController, type: :request do
end
end
describe "GET" do
let(:case_log) { FactoryBot.create(:case_log, :completed) }
let(:id) { case_log.id }
before do
get "/case_logs/#{id}", headers: headers
end
it "returns http success" do
expect(response).to have_http_status(:success)
end
it "returns a serialized Case Log" do
json_response = JSON.parse(response.body)
expect(json_response["status"]).to eq(case_log.status)
end
end
describe "PATCH" do
let(:case_log) do
FactoryBot.create(:case_log, :in_progress, tenant_code: "Old Value", property_postcode: "Old Value")

Loading…
Cancel
Save