Basic read only api

This commit is contained in:
Brenda Wallace
2017-10-22 13:00:00 +13:00
parent 2a74c057f3
commit c96695258b
14 changed files with 116 additions and 2 deletions

View File

@@ -11,6 +11,9 @@ gem 'coffee-rails'
gem 'haml'
gem 'sass-rails'
# API data
gem 'jsonapi-resources'
# CSS framework
gem 'bootstrap-sass'
gem 'font-awesome-sass'

View File

@@ -277,6 +277,10 @@ GEM
railties (>= 3.2)
sprockets-rails
json (2.1.0)
jsonapi-resources (0.9.0)
activerecord (>= 4.1)
concurrent-ruby
railties (>= 4.1)
jwt (1.5.6)
kaminari (1.1.1)
activesupport (>= 4.1.0)
@@ -590,6 +594,7 @@ DEPENDENCIES
jquery-rails
jquery-ui-rails (~> 5.0.2)
js-routes
jsonapi-resources
kaminari
leaflet-markercluster-rails
leaflet-rails (~> 0.7.7)
@@ -625,7 +630,6 @@ DEPENDENCIES
will_paginate
xmlrpc
RUBY VERSION
ruby 2.4.1p111

View File

@@ -0,0 +1,6 @@
module Api
module V1
class BaseController < JSONAPI::ResourceController
end
end
end

View File

@@ -0,0 +1,6 @@
module Api
module V1
class CropsController < Api::V1::BaseController
end
end
end

View File

@@ -0,0 +1,6 @@
module Api
module V1
class GardensController < Api::V1::BaseController
end
end
end

View File

@@ -0,0 +1,6 @@
module Api
module V1
class MembersController < Api::V1::BaseController
end
end
end

View File

@@ -0,0 +1,6 @@
module Api
module V1
class PhotosController < Api::V1::BaseController
end
end
end

View File

@@ -0,0 +1,6 @@
module Api
module V1
class PlantingsController < Api::V1::BaseController
end
end
end

View File

@@ -0,0 +1,13 @@
module Api
module V1
class CropResource < JSONAPI::Resource
immutable
model_name 'Crop'
attribute :name
attribute :en_wikipedia_url
has_many :plantings
has_many :photos
has_one :parent
end
end
end

View File

@@ -0,0 +1,11 @@
module Api
module V1
class GardenResource < JSONAPI::Resource
immutable
model_name 'Garden'
attribute :name
has_one :owner, class_name: 'Member'
has_many :plantings
end
end
end

View File

@@ -0,0 +1,10 @@
module Api
module V1
class MemberResource < JSONAPI::Resource
immutable
model_name 'Member'
attribute :login_name
has_many :gardens
end
end
end

View File

@@ -0,0 +1,8 @@
module Api
module V1
class PhotoResource < JSONAPI::Resource
immutable
model_name 'Photo'
end
end
end

View File

@@ -0,0 +1,20 @@
module Api
module V1
class PlantingResource < JSONAPI::Resource
immutable
model_name 'Planting'
has_one :garden
has_one :crop
has_one :owner
has_many :photos
attribute :planted_at
attribute :finished_at
attribute :quantity
attribute :description
attribute :sunniness
attribute :planted_from
attribute :days_before_maturity
end
end
end

View File

@@ -96,8 +96,17 @@ Growstuff::Application.routes.draw do
get '/admin/newsletter' => 'admin#newsletter', :as => :admin_newsletter
get '/admin/:action' => 'admin#:action'
get '/.well-known/acme-challenge/:id' => 'pages#letsencrypt'
namespace :api do
namespace :v1 do
jsonapi_resources :photos
jsonapi_resources :crops
jsonapi_resources :plantings
jsonapi_resources :gardens
jsonapi_resources :members
end
end
get '/.well-known/acme-challenge/:id' => 'pages#letsencrypt'
# CMS stuff -- must remain LAST
comfy_route :cms, path: '/', sitemap: false
end