show both, files and file infos in acq.media API response
This commit is contained in:
@@ -45,13 +45,14 @@ class Api::ReleasesController < Api::ApiController
|
|||||||
if model_name == "acquired_media_release"
|
if model_name == "acquired_media_release"
|
||||||
mapping = {
|
mapping = {
|
||||||
"#{model_name.camelize}": SerializableAcquiredMediaRelease,
|
"#{model_name.camelize}": SerializableAcquiredMediaRelease,
|
||||||
|
FileInfo: SerializableFileInfo,
|
||||||
"ActiveStorage::Attachment".to_sym => ActiveStorage::SerializableAttachment,
|
"ActiveStorage::Attachment".to_sym => ActiveStorage::SerializableAttachment,
|
||||||
}
|
}
|
||||||
|
|
||||||
render jsonapi: release,
|
render jsonapi: release,
|
||||||
status: status,
|
status: status,
|
||||||
class: mapping,
|
class: mapping,
|
||||||
include: [:files]
|
include: [:files, :file_infos]
|
||||||
else
|
else
|
||||||
mapping = {
|
mapping = {
|
||||||
"#{model_name.camelize}": show_serializable,
|
"#{model_name.camelize}": show_serializable,
|
||||||
|
|||||||
@@ -8,6 +8,16 @@ class SerializableAcquiredMediaRelease < JSONAPI::Serializable::Resource
|
|||||||
:applicable_medium_id, :applicable_medium_text, :territory_id, :territory_text, :term_id, :term_text,
|
:applicable_medium_id, :applicable_medium_text, :territory_id, :territory_text, :term_id, :term_text,
|
||||||
:restriction_id, :restriction_text, :categories, :description, :tag_list
|
:restriction_id, :restriction_text, :categories, :description, :tag_list
|
||||||
|
|
||||||
|
has_many :file_infos do
|
||||||
|
data do
|
||||||
|
@object.file_infos
|
||||||
|
end
|
||||||
|
|
||||||
|
meta do
|
||||||
|
{ count: @object.file_infos.size }
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
has_many :files do
|
has_many :files do
|
||||||
data do
|
data do
|
||||||
@object.files
|
@object.files
|
||||||
|
|||||||
@@ -37,7 +37,7 @@ RSpec.describe Api::AcquiredMediaReleasesController, type: :controller do
|
|||||||
sign_in_to_api(current_user)
|
sign_in_to_api(current_user)
|
||||||
get :show, params: { id: tested_release.id }
|
get :show, params: { id: tested_release.id }
|
||||||
|
|
||||||
expect(response.body).not_to match /file_infos/
|
expect(response.body).to match /file_infos/
|
||||||
expect(response.body).to match /files/
|
expect(response.body).to match /files/
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user