Commit d3e794e2 authored by Pawel Chojnacki's avatar Pawel Chojnacki

Optionally filter by deployment time

parent 73203873
...@@ -2,9 +2,11 @@ class Projects::DeploymentsController < Projects::ApplicationController ...@@ -2,9 +2,11 @@ class Projects::DeploymentsController < Projects::ApplicationController
before_action :authorize_read_deployment! before_action :authorize_read_deployment!
def index def index
serializer = DeploymentSerializer.new(user: @current_user) serializer = DeploymentSerializer.new(user: @current_user, project: project)
deployments = environment.deployments.where('created_at > ?', 8.hours.ago)
.map { |d| serializer.represent(d) } deployments = environment.deployments.reorder(created_at: :desc)
deployments = deployments.where('created_at > ?', params[:after].to_time) if params[:after]&.to_time
deployments = deployments.map { |deployment| serializer.represent(deployment) }
render json: { deployments: deployments } render json: { deployments: deployments }
end end
......
...@@ -20,7 +20,7 @@ describe Projects::DeploymentsController do ...@@ -20,7 +20,7 @@ describe Projects::DeploymentsController do
create(:deployment, environment: environment, created_at: 7.hours.ago) create(:deployment, environment: environment, created_at: 7.hours.ago)
create(:deployment, environment: environment) create(:deployment, environment: environment)
get :index, environment_params get :index, environment_params(:after => 8.hours.ago)
expect(response).to be_ok expect(response).to be_ok
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment