Skip to content

Commit

Permalink
Merge pull request #1167 from transitland/master
Browse files Browse the repository at this point in the history
Production release 75
  • Loading branch information
irees committed Aug 23, 2017
2 parents aff4409 + 257fc19 commit 35c39bf
Show file tree
Hide file tree
Showing 23 changed files with 666 additions and 589 deletions.
30 changes: 29 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,38 @@

## [Unreleased](https://github.com/transitland/transitland-datastore/tree/HEAD)

[Full Changelog](https://github.com/transitland/transitland-datastore/compare/73...HEAD)
[Full Changelog](https://github.com/transitland/transitland-datastore/compare/74...HEAD)

**Merged pull requests:**

- Production release 74 [\#1157](https://github.com/transitland/transitland-datastore/pull/1157) ([irees](https://github.com/irees))

## [74](https://github.com/transitland/transitland-datastore/tree/74) (2017-08-14)
[Full Changelog](https://github.com/transitland/transitland-datastore/compare/73...74)

**Implemented enhancements:**

- include more information/columns when requesting CSV from API endpoints [\#1164](https://github.com/transitland/transitland-datastore/issues/1164)

**Closed issues:**

- Relax JSON Schema array uniqueness requirements [\#1159](https://github.com/transitland/transitland-datastore/issues/1159)
- Remove old SSPs [\#1156](https://github.com/transitland/transitland-datastore/issues/1156)
- Stop becomes StopPlatform [\#1152](https://github.com/transitland/transitland-datastore/issues/1152)
- Feeds: feed\_versions default ordering by service\_start\_date [\#1144](https://github.com/transitland/transitland-datastore/issues/1144)
- Feed: Add a 'name' field [\#1131](https://github.com/transitland/transitland-datastore/issues/1131)
- Query for Operators without Feeds [\#1130](https://github.com/transitland/transitland-datastore/issues/1130)

**Merged pull requests:**

- update misc. gems [\#1166](https://github.com/transitland/transitland-datastore/pull/1166) ([drewda](https://github.com/drewda))
- CSV additions [\#1165](https://github.com/transitland/transitland-datastore/pull/1165) ([drewda](https://github.com/drewda))
- SSP: Skip trip if interpolation issues [\#1163](https://github.com/transitland/transitland-datastore/pull/1163) ([irees](https://github.com/irees))
- Feed: add name [\#1162](https://github.com/transitland/transitland-datastore/pull/1162) ([irees](https://github.com/irees))
- Operators: with\_feed and without\_feed [\#1161](https://github.com/transitland/transitland-datastore/pull/1161) ([irees](https://github.com/irees))
- Relax JSON Schema "uniqueItems" requirements [\#1160](https://github.com/transitland/transitland-datastore/pull/1160) ([irees](https://github.com/irees))
- Feed: sort feed\_versions by earliest\_calendar\_date [\#1158](https://github.com/transitland/transitland-datastore/pull/1158) ([irees](https://github.com/irees))
- Changeset: changeStopType action [\#1155](https://github.com/transitland/transitland-datastore/pull/1155) ([irees](https://github.com/irees))
- Production release 73 [\#1140](https://github.com/transitland/transitland-datastore/pull/1140) ([irees](https://github.com/irees))

## [73](https://github.com/transitland/transitland-datastore/tree/73) (2017-08-03)
Expand Down
12 changes: 6 additions & 6 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -77,13 +77,13 @@ GEM
activerecord (>= 3.2, < 6.0)
rake (>= 10.4, < 13.0)
arel (6.0.4)
aws-sdk (2.10.25)
aws-sdk-resources (= 2.10.25)
aws-sdk-core (2.10.25)
aws-sdk (2.10.29)
aws-sdk-resources (= 2.10.29)
aws-sdk-core (2.10.29)
aws-sigv4 (~> 1.0)
jmespath (~> 1.0)
aws-sdk-resources (2.10.25)
aws-sdk-core (= 2.10.25)
aws-sdk-resources (2.10.29)
aws-sdk-core (= 2.10.29)
aws-sigv4 (1.0.1)
bcrypt (3.1.11)
better_errors (2.3.0)
Expand Down Expand Up @@ -135,7 +135,7 @@ GEM
factory_girl_rails (4.8.0)
factory_girl (~> 4.8.0)
railties (>= 3.0.0)
faraday (0.12.2)
faraday (0.13.1)
multipart-post (>= 1.2, < 3)
ffaker (2.6.0)
figaro (1.1.1)
Expand Down
4 changes: 2 additions & 2 deletions app/controllers/api/v1/activity_updates_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def index
private

def query_params
{
super.merge({
feed: {
desc: "Filter by Feed",
type: "onestop_id",
Expand All @@ -39,7 +39,7 @@ def query_params
type: "integer",
array: true
}
}
})
end

end
10 changes: 10 additions & 0 deletions app/controllers/api/v1/base_api_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ class Api::V1::BaseApiController < ApplicationController
render_error code: 400, message: exception.message
end


# following this pattern: https://gist.github.com/Sujimichi/2349565
def raise_not_found!
raise ActionController::RoutingError.new("No route matches #{request.env['REQUEST_METHOD']} /api/#{params[:unmatched_route]}")
Expand All @@ -52,6 +53,15 @@ def default_url_options

private

def query_params
return {
apikey: {
desc: "API Key",
type: "string"
}
}
end

def set_default_response_format
request.format = :json unless [:geojson, :csv, :rss].include?(request.format.to_sym)
end
Expand Down
4 changes: 2 additions & 2 deletions app/controllers/api/v1/change_payloads_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def destroy
private

def query_params
{
super.merge({
ids: {
desc: "Change Payload ID",
type: "integer",
Expand All @@ -50,7 +50,7 @@ def query_params
type: "integer",
show: false
}
}
})
end

def change_payload_params
Expand Down
4 changes: 2 additions & 2 deletions app/controllers/api/v1/changesets_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ def revert
private

def query_params
{
super.merge({
ids: {
desc: "Filter by Changeset ID",
type: "integer",
Expand All @@ -120,7 +120,7 @@ def query_params
desc: "Applied Changesets",
type: "boolean"
}
}
})
end

def set_changeset
Expand Down
4 changes: 2 additions & 2 deletions app/controllers/api/v1/current_entity_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ def set_model

def query_params
# Allowed query parameters - and documentation
{
super.merge({
onestop_id: {
desc: "Onestop ID",
type: "onestop_id",
Expand Down Expand Up @@ -188,6 +188,6 @@ def query_params
type: "boolean",
show: false
}
}
})
end
end
4 changes: 2 additions & 2 deletions app/controllers/api/v1/feed_version_imports_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def show
private

def query_params
{
super.merge({
ids: {
desc: "FeedVersionImport IDs",
type: "integer",
Expand All @@ -48,7 +48,7 @@ def query_params
type: "sha1",
array: true
}
}
})
end

def set_feed_version_import
Expand Down
4 changes: 2 additions & 2 deletions app/controllers/api/v1/feed_version_infos_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def paginated_json_collection(collection)
private

def query_params
{
super.merge({
feed_onestop_id: {
desc: "Feed",
type: "onestop_id",
Expand All @@ -77,7 +77,7 @@ def query_params
type: "integer",
array: true
}
}
})
end

def set_feed_version_info
Expand Down
4 changes: 2 additions & 2 deletions app/controllers/api/v1/feed_versions_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ def update
private

def query_params
{
super.merge({
feed_onestop_id: {
desc: "Feed",
type: "onestop_id",
Expand Down Expand Up @@ -146,7 +146,7 @@ def query_params
type: "sha1",
array: true
}
}
})
end

def set_feed_version
Expand Down
4 changes: 2 additions & 2 deletions app/controllers/api/v1/issues_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -86,15 +86,15 @@ def categories
private

def query_params
{
super.merge({
open: {},
issue_type: {},
category: {},
of_feed_entities: {},
of_entity: {},
imported_from_feed: {},
imported_from_feed_version: {}
}
})
end

def set_issue
Expand Down
4 changes: 2 additions & 2 deletions app/controllers/api/v1/onestop_id_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ def show
end

def query_params
{
super.merge({
onestop_id: {
desc: "Onestop ID",
type: "onestop_id"
}
}
})
end
end
18 changes: 9 additions & 9 deletions app/controllers/api/v1/schedule_stop_pairs_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ def set_schedule_stop_pairs
# Feed Version, or default: All active Feed Versions
feed_version_sha1 = params[:feed_version_sha1].presence || params[:imported_from_feed_version].presence
if feed_version_sha1
@ssps = @ssps.where(feed_version: FeedVersion.find_by!(sha1: feed_version_sha1))
@ssps = @ssps.where(feed_version: FeedVersion.find_by!(sha1: feed_version_sha1).id)
end

# Explicitly use active Feed Versions
Expand All @@ -92,7 +92,7 @@ def set_schedule_stop_pairs
# Feed
feed_onestop_id = params[:feed_onestop_id].presence || params[:imported_from_feed].presence
if feed_onestop_id
@ssps = @ssps.where(feed: Feed.find_by_onestop_id!(feed_onestop_id))
@ssps = @ssps.where(feed: Feed.find_by_onestop_id!(feed_onestop_id).id)
end

# FeedVersion Import level
Expand All @@ -116,11 +116,11 @@ def set_schedule_stop_pairs

# Service between stops
if params[:origin_onestop_id].present?
origin_stops = Stop.find_by_onestop_ids!(AllowFiltering.param_as_array(params, :origin_onestop_id))
origin_stops = Stop.find_by_onestop_ids!(AllowFiltering.param_as_array(params, :origin_onestop_id)).pluck(:id)
@ssps = @ssps.where(origin: origin_stops)
end
if params[:destination_onestop_id].present?
destination_stops = Stop.find_by_onestop_ids!(AllowFiltering.param_as_array(params, :destination_onestop_id))
destination_stops = Stop.find_by_onestop_ids!(AllowFiltering.param_as_array(params, :destination_onestop_id)).pluck(:id)
@ssps = @ssps.where(destination: destination_stops)
end

Expand All @@ -144,15 +144,15 @@ def set_schedule_stop_pairs

# Service on a route
if params[:route_onestop_id].present?
routes = Route.find_by_onestop_ids!(AllowFiltering.param_as_array(params, :route_onestop_id))
routes = Route.find_by_onestop_ids!(AllowFiltering.param_as_array(params, :route_onestop_id)).pluck(:id)
@ssps = @ssps.where(route: routes)
end
if params[:route_stop_pattern_onestop_id].present?
rsps = RouteStopPattern.find_by_onestop_ids!(AllowFiltering.param_as_array(params, :route_stop_pattern_onestop_id))
rsps = RouteStopPattern.find_by_onestop_ids!(AllowFiltering.param_as_array(params, :route_stop_pattern_onestop_id)).pluck(:id)
@ssps = @ssps.where(route_stop_pattern: rsps)
end
if params[:operator_onestop_id].present?
operators = Operator.find_by_onestop_ids!(AllowFiltering.param_as_array(params, :operator_onestop_id))
operators = Operator.find_by_onestop_ids!(AllowFiltering.param_as_array(params, :operator_onestop_id)).pluck(:id)
@ssps = @ssps.where(operator: operators)
end

Expand All @@ -175,7 +175,7 @@ def set_schedule_stop_pairs


def query_params
{
super.merge({
active: {
desc: "Imported from active Feed Version",
type: "boolean"
Expand Down Expand Up @@ -262,7 +262,7 @@ def query_params
type: "sha1",
array: true
}
}
})
end

def tz_now
Expand Down
6 changes: 3 additions & 3 deletions app/controllers/api/v1/users_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,13 @@ def show
private

def query_params
{
super.merge({
ids: {
desc: "Users",
type: "integer",
array: true
},
}
}
})
end

def set_user
Expand Down
21 changes: 14 additions & 7 deletions app/controllers/concerns/json_collection_pagination.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ def paginated_collection(collection)
per_page = sort_per_page
offset = sort_offset
include_total = sort_total
min_id = sort_min_id
meta = {
sort_key: sort_key,
sort_order: sort_order,
offset: offset,
per_page: per_page,
}
qps = params.permit(query_params.keys)
Expand All @@ -22,12 +22,21 @@ def paginated_collection(collection)
# Setup prev/next links
if ['false', '∞'].include?(per_page)
data_on_page = collection.to_a
elsif min_id
# Get the current page of results, +1 to limit to check next page
data = collection.where('id > ?', min_id).limit(per_page+1).to_a
data_on_page = data[0...per_page]
meta[:sort_min_id] = data_on_page.last.id
meta_next = url_for(qps.merge(meta))
(meta[:next] = meta_next) if data.size > per_page
else
# Get the current page of results.
# Add +1 to limit to see if there is a next page.
# This will be dropped in the return.
data = collection.offset(offset).limit(per_page+1).to_a
data_on_page = data[0...per_page]
# Previous and next page
meta[:offset] = offset
meta_prev = url_for(qps.merge(meta).merge({
offset: (offset - per_page) >= 0 ? (offset - per_page) : 0,
}))
Expand All @@ -36,8 +45,6 @@ def paginated_collection(collection)
}))
(meta[:prev] = meta_prev) if offset > 0
(meta[:next] = meta_next) if data.size > per_page
# Slice data
data_on_page = data[0...per_page]
end

if include_total
Expand Down Expand Up @@ -66,14 +73,14 @@ def paginated_geojson_collection(collection)

private

def query_params
{}
end

def sort_key
(params[:sort_key].presence || :id).to_sym
end

def sort_min_id
params[:sort_min_id].presence ? params[:sort_min_id].to_i : nil
end

def sort_order
params[:sort_order].to_s == 'desc' ? :desc : :asc
end
Expand Down
Loading

0 comments on commit 35c39bf

Please sign in to comment.