Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feed issue associations and serialization #865

Merged
merged 3 commits into from
Nov 28, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions app/models/feed.rb
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ class Feed < BaseFeed
include HasTags
include UpdatedSince
include HasAGeographicGeometry
include IsAnEntityWithIssues

has_many :feed_versions, -> { order 'created_at DESC' }, dependent: :destroy, as: :feed
has_many :feed_version_imports, -> { order 'created_at DESC' }, through: :feed_versions
Expand All @@ -62,6 +63,8 @@ class Feed < BaseFeed
has_many :operators_in_feed
has_many :operators, through: :operators_in_feed

has_many :issues, through: :entities_with_issues

has_many :entities_imported_from_feed
has_many :imported_operators, through: :entities_imported_from_feed, source: :entity, source_type: 'Operator'
has_many :imported_stops, through: :entities_imported_from_feed, source: :entity, source_type: 'Stop'
Expand Down
10 changes: 10 additions & 0 deletions app/serializers/feed_serializer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ class FeedSerializer < ApplicationSerializer
:feed_versions_count,
:feed_versions_url,
:feed_versions,
:issues,
:active_feed_version,
:import_level_of_active_feed_version,
:created_or_updated_in_changeset_id,
Expand All @@ -74,6 +75,15 @@ def feed_versions
object.feed_versions.pluck(:sha1) if object.persisted?
end

def issues
object.issues.map { |issue| { id: issue.id,
issue_type: issue.issue_type,
open: issue.open,
details: issue.details,
created_by_changeset_id: issue.created_by_changeset_id,
resolved_by_changeset_id: issue.resolved_by_changeset_id } }
end

def active_feed_version
object.active_feed_version.try(:sha1)
end
Expand Down