Skip to content
This repository has been archived by the owner on Jul 12, 2019. It is now read-only.

Commit

Permalink
ISSUE-#55: added swagger blocks and nested the api to v1
Browse files Browse the repository at this point in the history
  • Loading branch information
howdoicomputer committed Mar 20, 2017
1 parent b2a59d9 commit 7172ab3
Show file tree
Hide file tree
Showing 8 changed files with 204 additions and 128 deletions.
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ group :development, :test do
gem 'webmock'
gem 'rubocop', require: false
gem 'coveralls', require: false
gem 'swagger-blocks'
end

group :development do
Expand Down
2 changes: 2 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,7 @@ GEM
actionpack (>= 4.0)
activesupport (>= 4.0)
sprockets (>= 3.0.0)
swagger-blocks (2.0.0)
syslog_protocol (0.9.2)
term-ansicolor (1.4.0)
tins (~> 1.0)
Expand Down Expand Up @@ -315,6 +316,7 @@ DEPENDENCIES
spring
spring-watcher-listen (~> 2.0.0)
sprockets (= 3.6.3)
swagger-blocks
tzinfo-data
vcr
webmock
Expand Down
16 changes: 16 additions & 0 deletions app/controllers/api/base_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
class Api::BaseController < ActionController::Base
class << self
Swagger::Docs::Generator.set_real_methods

def inherited(subclass)
super
subclass.class_eval do
setup_basic_api_documentation
end
end

private

def setup_basic_api_documentation; end
end
end
126 changes: 0 additions & 126 deletions app/controllers/api/listings_controller.rb

This file was deleted.

181 changes: 181 additions & 0 deletions app/controllers/api/v1/listings_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,181 @@
# frozen_string_literal: true
module Api
module V1
class ListingsController < Api::BaseController
include Swagger::Blocks

swagger_path '/api/v1/listings' do
operation :get do
key :description, 'Returns all pets from the system that the user has access to'
key :operationId, 'findPets'
key :produces, [
'application/json',
'text/html',
]
key :tags, [
'pet'
]
parameter do
key :name, :tags
key :in, :query
key :description, 'tags to filter by'
key :required, false
key :type, :array
items do
key :type, :string
end
key :collectionFormat, :csv
end
parameter do
key :name, :limit
key :in, :query
key :description, 'maximum number of results to return'
key :required, false
key :type, :integer
key :format, :int32
end
response 200 do
key :description, 'pet response'
schema do
key :type, :array
items do
key :'$ref', :Pet
end
end
end
response :default do
key :description, 'unexpected error'
schema do
key :'$ref', :ErrorModel
end
end
end

before_action :set_listing, only: [:show, :update, :destroy]

# GET /listings
def index
@listings = Listing.all

render json: @listings
end

# GET /listings/1
def show
render json: @listing
end

# POST /listings
def create
@listing = Listing.new(listing_params)

if @listing.save
render json: @listing, status: :created, location: @listing
else
render json: @listing.errors, status: :unprocessable_entity
end
end

# PATCH/PUT /listings/1
def update
if @listing.update(listing_params)
render json: @listing
else
render json: @listing.errors, status: :unprocessable_entity
end
end

# DELETE /listings/1
def destroy
@listing.destroy
end

private

# Use callbacks to share common setup or constraints between actions.
def set_listing
@listing = Listing.find(params[:id])
end

# Only allow a trusted parameter "white list" through.
def listing_params
params.require(:listing).permit(
:listing_id,
:property_type,
:bedrooms,
:bathrooms,
:lease_length,
:year_built_approx,
:square_feet_approx,
:furnished,
:trash_service,
:lawn_care,
:basement,
:parking_type,
:allotted_parking_spaces,
:parking_in_front_of_property_entrance,
:lease_extra_spaces,
:unit_entry,
:lever_style_door_handles,
:door_knock_and_bell_signaller,
:standard_peephole,
:entry_door_intercom,
:deadbolt_on_entry_door,
:secured_entry_to_building,
:automatic_entry_door,
:accessible_elevators,
:unit_on_first_floor,
:multi_story_unit,
:bus_stop,
:playground,
:stove,
:refrigerator_and_freezer,
:air_conditioner,
:clothes_washer,
:clothes_dryer,
:laundry_room_and_facility,
:smoke_detector,
:carbon_monoxide_detector,
:heating_type,
:water_heater,
:counter_height,
:non_digital_kitchen_appliances,
:front_controls_on_stoveandcook_top,
:vanity_height,
:grab_bars,
:reinforced_for_grab_bar,
:roll_in_shower,
:lowered_toilet,
:raised_toilet,
:gated_facility,
:sidewalks,
:emergency_exits,
:dumpsters,
:pool,
:work_out_room,
:theater,
:community_shuttle,
:within_paratransit_route,
:sign_language_friendly,
:recreational_facilities,
:apartment_name,
:address,
:criminal_check,
:credit_check,
:accepts_section_8,
:tax_credit_property,
:subsidized_rent_ok,
:seniors_only,
:pets,
:smoking,
:security_deposit,
:application_fee,
:date_available,
:flooring_materials,
:other_appliances_included
)
end
end
end
end
end
Empty file removed config/initializers/sidekiq.rb
Empty file.
4 changes: 3 additions & 1 deletion config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@

Rails.application.routes.draw do
namespace :api do
resources :listings
namespace :v1 do
resources :listings
end
end

mount Sidekiq::Web => '/sidekiq'
Expand Down
2 changes: 1 addition & 1 deletion frontend/app/adapters/application.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import DS from 'ember-data';

export default DS.JSONAPIAdapter.extend({
namespace: '/api'
namespace: '/api/v1'
});

0 comments on commit 7172ab3

Please sign in to comment.