This repository has been archived by the owner. It is now read-only.
Permalink
Browse files

Add Footnote API endpoint

  • Loading branch information...
saulius committed Jan 21, 2014
1 parent 1be154b commit 2f777d8314c492615d35c09c7fd4a6ddde40a6d6
@@ -0,0 +1,37 @@
+module Api
+ module V1
+ class FootnotesController < ApiController
+ before_filter :authenticate_user!
+
+ def index
+ @footnotes = Footnote.national
+
+ respond_with @footnotes
+ end
+
+ def show
+ @footnote = Footnote.with_pk(footnote_pk)
+ end
+
+ def update
+ @footnote = Footnote.with_pk(footnote_pk)
+
+ respond_with @footnote
+ end
+
+ private
+
+ def rollback_params
+ params.require(:rollback).permit(:date, :redownload)
+ end
+
+ def footnote_pk
+ [footnote_id[0..1], footnote_id[2, 5]]
+ end
+
+ def footnote_id
+ params.fetch(:id, '')
+ end
+ end
+ end
+end
View
@@ -3,7 +3,7 @@ class Footnote < Sequel::Model
plugin :oplog, primary_key: [:footnote_id, :footnote_type_id]
plugin :conformance_validator
- set_primary_key [:footnote_id, :footnote_type_id]
+ set_primary_key [:footnote_type_id, :footnote_id]
many_to_many :footnote_descriptions, join_table: :footnote_description_periods,
@@ -55,6 +55,12 @@ def footnote_description
delegate :description, :formatted_description, to: :footnote_description
+ dataset_module do
+ def national
+ where(national: true)
+ end
+ end
+
# FO4
# length_of :footnote_description_periods, minimum: 1
# # FO4
@@ -0,0 +1,6 @@
+attributes :footnote_id,
+ :footnote_type_id,
+ :validity_start_date,
+ :validity_end_date
+
+node(:description) { |footnote| footnote.formatted_description }
@@ -0,0 +1,3 @@
+collection @footnotes
+
+extends('api/v1/footnotes/footnote')
@@ -0,0 +1,3 @@
+object @footnote
+
+extends('api/v1/footnotes/footnote')
@@ -0,0 +1,3 @@
+object @footnote
+
+extends('api/v1/footnotes/footnote')
View
@@ -56,7 +56,9 @@
resources :search_references, only: [:index]
post "search" => "search#search", via: :post, as: :search
+
resources :rollbacks, only: [:create, :index]
+ resources :footnotes, only: [:index, :show, :update]
end
end

0 comments on commit 2f777d8

Please sign in to comment.