Skip to content

Commit 30d3a56

Browse files
authored
CV2-6342: Refactor SavedSearch to accept list_type (#2291)
* CV2-6342: refactor SavedSearch to accept list_type * CV2-6342: update schema
1 parent f637ab0 commit 30d3a56

File tree

8 files changed

+54
-1
lines changed

8 files changed

+54
-1
lines changed

app/graph/mutations/saved_search_mutations.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ class Create < Mutations::CreateMutation
1515

1616
argument :title, GraphQL::Types::String, required: true
1717
argument :team_id, GraphQL::Types::Int, required: true, camelize: false
18+
argument :list_type, GraphQL::Types::String, required: true, camelize: false
1819
end
1920

2021
class Update < Mutations::UpdateMutation

app/graph/types/saved_search_type.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ class SavedSearchType < DefaultObject
88
field :team_id, GraphQL::Types::Int, null: true
99
field :team, PublicTeamType, null: true
1010
field :items_count, GraphQL::Types::Int, null: true
11+
field :list_type, GraphQL::Types::String, null: true
1112
field :filters, GraphQL::Types::String, null: true
1213

1314
def filters

app/models/saved_search.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
class SavedSearch < ApplicationRecord
22
attr_accessor :is_being_copied
33

4+
enum list_type: { media: 0, article: 1 }
5+
46
validates_presence_of :title, :team_id
57
validates :title, uniqueness: { scope: :team_id }, unless: proc { |ss| ss.is_being_copied }
68

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
class AddListTypeToSavedSearch < ActiveRecord::Migration[6.1]
2+
def change
3+
add_column :saved_searches, :list_type, :integer, null: false, default: 0
4+
add_index :saved_searches, :list_type
5+
end
6+
end

db/schema.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
#
1111
# It's strongly recommended that you check this file into your version control system.
1212

13-
ActiveRecord::Schema.define(version: 2025_04_11_153835) do
13+
ActiveRecord::Schema.define(version: 2025_04_19_100047) do
1414

1515
# These are extensions that must be enabled in order to support this database
1616
enable_extension "plpgsql"
@@ -680,6 +680,8 @@
680680
t.json "filters"
681681
t.datetime "created_at", null: false
682682
t.datetime "updated_at", null: false
683+
t.integer "list_type", default: 0, null: false
684+
t.index ["list_type"], name: "index_saved_searches_on_list_type"
683685
t.index ["team_id"], name: "index_saved_searches_on_team_id"
684686
end
685687

lib/relay.idl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2673,6 +2673,7 @@ input CreateSavedSearchInput {
26732673
"""
26742674
clientMutationId: String
26752675
filters: JsonStringType
2676+
list_type: String!
26762677
team_id: Int!
26772678
title: String!
26782679
}
@@ -12290,6 +12291,7 @@ type SavedSearch implements Node {
1229012291
id: ID!
1229112292
is_part_of_feeds: Boolean
1229212293
items_count: Int
12294+
list_type: String
1229312295
permissions: String
1229412296
team: PublicTeam
1229512297
team_id: Int

public/relay.json

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16274,6 +16274,22 @@
1627416274
"isDeprecated": false,
1627516275
"deprecationReason": null
1627616276
},
16277+
{
16278+
"name": "list_type",
16279+
"description": null,
16280+
"type": {
16281+
"kind": "NON_NULL",
16282+
"name": null,
16283+
"ofType": {
16284+
"kind": "SCALAR",
16285+
"name": "String",
16286+
"ofType": null
16287+
}
16288+
},
16289+
"defaultValue": null,
16290+
"isDeprecated": false,
16291+
"deprecationReason": null
16292+
},
1627716293
{
1627816294
"name": "clientMutationId",
1627916295
"description": "A unique identifier for the client performing the mutation.",
@@ -64937,6 +64953,20 @@
6493764953
"isDeprecated": false,
6493864954
"deprecationReason": null
6493964955
},
64956+
{
64957+
"name": "list_type",
64958+
"description": null,
64959+
"args": [
64960+
64961+
],
64962+
"type": {
64963+
"kind": "SCALAR",
64964+
"name": "String",
64965+
"ofType": null
64966+
},
64967+
"isDeprecated": false,
64968+
"deprecationReason": null
64969+
},
6494064970
{
6494164971
"name": "permissions",
6494264972
"description": null,

test/models/saved_search_test.rb

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,15 @@ def setup
1212
end
1313
end
1414

15+
test "should set list type" do
16+
ss = create_saved_search
17+
assert_equal 'media', ss.list_type
18+
create_saved_search list_type: 'article'
19+
assert_raises ArgumentError do
20+
create_saved_search list_type: 'invalid'
21+
end
22+
end
23+
1524
test "should not create saved search if title is not present" do
1625
assert_no_difference 'SavedSearch.count' do
1726
assert_raises ActiveRecord::RecordInvalid do

0 commit comments

Comments
 (0)