Skip to content

Commit

Permalink
fixing the route and pr comments
Browse files Browse the repository at this point in the history
  • Loading branch information
pamatyatake2 committed Oct 25, 2024
1 parent e9c9a48 commit cd81930
Show file tree
Hide file tree
Showing 10 changed files with 30 additions and 26 deletions.
11 changes: 7 additions & 4 deletions app/controllers/saved_searches_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ class SavedSearchesController < ApplicationController
].freeze

def index
searches = organization.users.map(&:saved_searches).flatten
my_search = SavedSearch.for_user(current_user)
respond_to do |format|
format.html { render "index" }
format.json do
searches = organization.users.includes(:saved_searches).map(&:saved_searches).flatten
my_search = SavedSearch.for_user(current_user)
render json:
{ all_searches: SavedSearchSerializer.new(searches).serializable_hash[:data],
user_searches: SavedSearchSerializer.new(my_search).serializable_hash[:data] }
Expand All @@ -24,9 +24,10 @@ def index

def show
@search = SavedSearch.find_by_id(params[:id])
@search_json = SavedSearchSerializer.new(@search).serializable_hash[:data]
respond_to do |format|
format.html { render "show" }
format.json { render json: SavedSearchSerializer.new(@search).serializable_hash[:data] }
format.json { render json: @search_json }
end
end

Expand All @@ -48,10 +49,12 @@ def destroy
end
end

helper_method :organization

private

def organization
@organization ||= BusinessLine.find_by(url: params[:decision_review_business_line_slug])
@organization ||= Organization.find_by(url: params[:decision_review_business_line_slug])
end

def save_search_create_params
Expand Down
1 change: 0 additions & 1 deletion app/models/saved_search.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ class SavedSearch < CaseflowRecord
validates :description, presence: true, length: { maximum: 1000 }
validate :saved_search_limit

# Ex:- scope :active, -> {where(:active => true)}
scope :for_user, ->(user) { where(user: user).order(created_at: :desc) }

private
Expand Down
16 changes: 8 additions & 8 deletions app/serializers/saved_search_serializer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@ class SavedSearchSerializer
attribute :description
attribute :savedSearch, &:saved_search
attribute :createdAt, &:created_at
attribute :userCssId do |object|
object.user.css_id
end
attribute :userFullName do |object|
object.user.full_name
end
attribute :userId do |object|
object.user.id

attribute :user do |object|
user = object.try(:user)
{
css_id: user.try(:css_id),
full_name: user.try(:full_name),
id: user.id
}
end
end
3 changes: 3 additions & 0 deletions app/views/saved_searches/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,12 @@
buildDate: build_date,
flash: flash,
serverNonComp: {
businessLine: organization.name,
businessLineUrl: organization.url,
currentUserCssId: current_user.css_id,
},
savedSearches: {

}
}) %>
<% end %>
1 change: 1 addition & 0 deletions app/views/saved_searches/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
currentUserCssId: current_user.css_id,
},
savedSearches: {
@search_json
}
}) %>
<% end %>
2 changes: 1 addition & 1 deletion client/app/nonComp/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ class NonComp extends React.PureComponent {
/>
<PageRoute
exact
path="/:businessLineSlug/report/searches"
path="/:businessLineSlug/searches"
title={`${appName} Saved Searches | Caseflow`}
component={SavedSearches}
/>
Expand Down
2 changes: 1 addition & 1 deletion client/app/nonComp/pages/ReportPage.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -413,7 +413,7 @@ const ReportPage = ({ history }) => {
>
<div className="report-page-header">
<h1>Generate task report</h1>
<Link button="secondary" to={`/${businessLineUrl}/report/searches`}>View saved searches</Link>
<Link button="secondary" to={`/${businessLineUrl}/searches`}>View saved searches</Link>
</div>
<FormProvider {...methods}>
<form>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ exports[`DaysWaiting renders correctly 1`] = `
</h1>
<a
class="usa-button-secondary"
href="/undefined/report/searches"
href="/undefined/searches"
type="button"
>
View saved searches
Expand Down
2 changes: 1 addition & 1 deletion config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@
get '/remands(/*path)', to: redirect('/supplemental_claims/%{path}')

resources :decision_reviews, param: :business_line_slug do
resources :saved_searches, only: [:index, :create, :destroy, :show]
resources :searches, controller: :saved_searches, only: [:index, :create, :destroy, :show]
resources :tasks, controller: :decision_reviews, param: :task_id, only: [:show, :update] do
member do
get :history
Expand Down
16 changes: 7 additions & 9 deletions spec/controllers/saved_searches_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,20 @@
describe SavedSearchesController, :postgres, type: :controller do
let(:user) { create(:user, :vha_admin_user, :with_saved_search_reports) }
let(:saved_search) { create(:saved_search, user: user) }
let(:non_comp_org) { VhaBusinessLine.singleton }

let(:default_user) { create(:user) }
let(:vha_business_line) { VhaBusinessLine.singleton }
let(:options) { { format: :json, decision_review_business_line_slug: non_comp_org.url } }
let(:delete_param) { { id: user.saved_searches.first.id, decision_review_business_line_slug: non_comp_org.url } }
let(:options) { { format: :json, decision_review_business_line_slug: vha_business_line.url } }
let(:delete_param) { { id: user.saved_searches.first.id, decision_review_business_line_slug: vha_business_line.url } }

before do
User.stub = user
non_comp_org.add_user(user)
end

describe "#create" do
let(:valid_params) do
{
decision_review_business_line_slug: non_comp_org.url,
decision_review_business_line_slug: vha_business_line.url,
search: {
name: Faker::Name.name,
description: Faker::Lorem.sentence,
Expand All @@ -39,7 +37,7 @@
}
end

context "VHA user creating saved search" do
context "VHA admin user creating saved search" do
it "should create search" do
expect { post :create, params: valid_params }
.to change(SavedSearch, :count).by(1)
Expand All @@ -58,9 +56,9 @@
end
end

context "VHA user saved search not exists" do
context "VHA admin user saved search not exists" do
it "retunrs a not found error" do
delete :destroy, params: { id: 0, decision_review_business_line_slug: non_comp_org.url }
delete :destroy, params: { id: 0, decision_review_business_line_slug: vha_business_line.url }

expect(response).to have_http_status(:not_found)
end
Expand Down Expand Up @@ -122,7 +120,7 @@

subject do
get :show,
params: { id: saved_search.id, format: :json, decision_review_business_line_slug: non_comp_org.url }
params: { id: saved_search.id, format: :json, decision_review_business_line_slug: vha_business_line.url }
end

it "returns specific saved search" do
Expand Down

0 comments on commit cd81930

Please sign in to comment.