Add EnvironmentSerializer to EnvironmentsController

This commit is contained in:
Grzegorz Bizon 2016-11-07 09:43:43 +01:00 committed by Filipa Lacerda
parent 14345b2150
commit bd01a5a47c
1 changed files with 3 additions and 16 deletions

View File

@ -13,7 +13,9 @@ class Projects::EnvironmentsController < Projects::ApplicationController
respond_to do |format|
format.html
format.json do
render json: serialize_as_json(@environments)
render json: EnvironmentSerializer
.new(project: @project)
.represent(@environments)
end
end
end
@ -63,19 +65,4 @@ class Projects::EnvironmentsController < Projects::ApplicationController
def environment
@environment ||= project.environments.find(params[:id])
end
def serialize_as_json(resource)
resource.as_json(
include: {
last_deployment: {
include: {
user: { only: [:id, :name, :username], methods: [:avatar_url] },
deployable: { only: [:id, :name, :ref, :tag] }
},
methods: [:short_sha, :commit_title, :commit]
},
project: { methods: [:namespace] }
}
)
end
end