mirror of
https://github.com/Growstuff/growstuff.git
synced 2026-04-04 07:04:19 -04:00
Basic read only api
This commit is contained in:
3
Gemfile
3
Gemfile
@@ -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'
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
6
app/controllers/api/v1/base_controller.rb
Normal file
6
app/controllers/api/v1/base_controller.rb
Normal file
@@ -0,0 +1,6 @@
|
||||
module Api
|
||||
module V1
|
||||
class BaseController < JSONAPI::ResourceController
|
||||
end
|
||||
end
|
||||
end
|
||||
6
app/controllers/api/v1/crops_controller.rb
Normal file
6
app/controllers/api/v1/crops_controller.rb
Normal file
@@ -0,0 +1,6 @@
|
||||
module Api
|
||||
module V1
|
||||
class CropsController < Api::V1::BaseController
|
||||
end
|
||||
end
|
||||
end
|
||||
6
app/controllers/api/v1/gardens_controller.rb
Normal file
6
app/controllers/api/v1/gardens_controller.rb
Normal file
@@ -0,0 +1,6 @@
|
||||
module Api
|
||||
module V1
|
||||
class GardensController < Api::V1::BaseController
|
||||
end
|
||||
end
|
||||
end
|
||||
6
app/controllers/api/v1/members_controller.rb
Normal file
6
app/controllers/api/v1/members_controller.rb
Normal file
@@ -0,0 +1,6 @@
|
||||
module Api
|
||||
module V1
|
||||
class MembersController < Api::V1::BaseController
|
||||
end
|
||||
end
|
||||
end
|
||||
6
app/controllers/api/v1/photos_controller.rb
Normal file
6
app/controllers/api/v1/photos_controller.rb
Normal file
@@ -0,0 +1,6 @@
|
||||
module Api
|
||||
module V1
|
||||
class PhotosController < Api::V1::BaseController
|
||||
end
|
||||
end
|
||||
end
|
||||
6
app/controllers/api/v1/plantings_controller.rb
Normal file
6
app/controllers/api/v1/plantings_controller.rb
Normal file
@@ -0,0 +1,6 @@
|
||||
module Api
|
||||
module V1
|
||||
class PlantingsController < Api::V1::BaseController
|
||||
end
|
||||
end
|
||||
end
|
||||
13
app/resources/api/v1/crop_resource.rb
Normal file
13
app/resources/api/v1/crop_resource.rb
Normal 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
|
||||
11
app/resources/api/v1/garden_resource.rb
Normal file
11
app/resources/api/v1/garden_resource.rb
Normal 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
|
||||
10
app/resources/api/v1/member_resource.rb
Normal file
10
app/resources/api/v1/member_resource.rb
Normal 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
|
||||
8
app/resources/api/v1/photo_resource.rb
Normal file
8
app/resources/api/v1/photo_resource.rb
Normal file
@@ -0,0 +1,8 @@
|
||||
module Api
|
||||
module V1
|
||||
class PhotoResource < JSONAPI::Resource
|
||||
immutable
|
||||
model_name 'Photo'
|
||||
end
|
||||
end
|
||||
end
|
||||
20
app/resources/api/v1/planting_resource.rb
Normal file
20
app/resources/api/v1/planting_resource.rb
Normal 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
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user