Skip to content

Commit dbe6b71

Browse files
committed
Create models
1 parent 00cc1cd commit dbe6b71

9 files changed

Lines changed: 122 additions & 1 deletion

app/models/complaint.rb

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
class Complaint < ApplicationRecord
2+
belongs_to :user, required: false
3+
belongs_to :assignee, required: false, class_name: 'User'
4+
5+
after_create :generate_access_token
6+
7+
private
8+
9+
def generate_access_token
10+
update(access_token: SecureRandom.uuid)
11+
end
12+
end

app/models/complaint_comment.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
class ComplaintComment < ApplicationRecord
2+
belongs_to :complaint
3+
belongs_to :user, required: false
4+
end
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
class CreateComplaints < ActiveRecord::Migration[7.2]
2+
def change
3+
create_table :complaints do |t|
4+
t.references :user, null: true, foreign_key: true
5+
t.string :report_type
6+
t.string :status
7+
t.references :assignee, null: true, foreign_key: { to_table: :users }
8+
t.boolean :user_wants_updates
9+
t.string :access_token
10+
11+
t.timestamps
12+
13+
t.index :access_token, unique: true
14+
t.index :report_type
15+
t.index :status
16+
end
17+
end
18+
end
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
class CreateComplaintComments < ActiveRecord::Migration[7.2]
2+
def change
3+
create_table :complaint_comments do |t|
4+
t.references :complaint, null: false, foreign_key: true
5+
t.references :user, null: true, foreign_key: true
6+
t.text :content, null: false
7+
t.boolean :internal, null: false
8+
9+
t.timestamps
10+
end
11+
end
12+
end

db/schema.rb

Lines changed: 32 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[7.2].define(version: 2025_09_20_103432) do
13+
ActiveRecord::Schema[7.2].define(version: 2025_10_07_224207) do
1414
create_table "abilities", charset: "utf8mb4", collation: "utf8mb4_0900_ai_ci", force: :cascade do |t|
1515
t.bigint "community_id"
1616
t.string "name"
@@ -233,6 +233,33 @@
233233
t.index ["user_id"], name: "index_community_users_on_user_id"
234234
end
235235

236+
create_table "complaint_comments", charset: "utf8mb4", collation: "utf8mb4_unicode_ci", force: :cascade do |t|
237+
t.bigint "complaint_id", null: false
238+
t.bigint "user_id"
239+
t.text "content", null: false
240+
t.boolean "internal", null: false
241+
t.datetime "created_at", null: false
242+
t.datetime "updated_at", null: false
243+
t.index ["complaint_id"], name: "index_complaint_comments_on_complaint_id"
244+
t.index ["user_id"], name: "index_complaint_comments_on_user_id"
245+
end
246+
247+
create_table "complaints", charset: "utf8mb4", collation: "utf8mb4_unicode_ci", force: :cascade do |t|
248+
t.bigint "user_id"
249+
t.string "report_type"
250+
t.string "status"
251+
t.bigint "assignee_id"
252+
t.boolean "user_wants_updates"
253+
t.string "access_token"
254+
t.datetime "created_at", null: false
255+
t.datetime "updated_at", null: false
256+
t.index ["access_token"], name: "index_complaints_on_access_token", unique: true
257+
t.index ["assignee_id"], name: "index_complaints_on_assignee_id"
258+
t.index ["report_type"], name: "index_complaints_on_report_type"
259+
t.index ["status"], name: "index_complaints_on_status"
260+
t.index ["user_id"], name: "index_complaints_on_user_id"
261+
end
262+
236263
create_table "email_logs", charset: "utf8mb4", collation: "utf8mb4_unicode_ci", force: :cascade do |t|
237264
t.string "log_type"
238265
t.string "destination"
@@ -823,6 +850,10 @@
823850
add_foreign_key "community_users", "communities"
824851
add_foreign_key "community_users", "users"
825852
add_foreign_key "community_users", "users", column: "deleted_by_id"
853+
add_foreign_key "complaint_comments", "complaints"
854+
add_foreign_key "complaint_comments", "users"
855+
add_foreign_key "complaints", "users"
856+
add_foreign_key "complaints", "users", column: "assignee_id"
826857
add_foreign_key "error_logs", "communities"
827858
add_foreign_key "error_logs", "users"
828859
add_foreign_key "filters", "users"
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# Read about fixtures at https://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
2+
3+
one:
4+
complaint: one
5+
user: one
6+
content: MyText
7+
internal: false
8+
9+
two:
10+
complaint: two
11+
user: two
12+
content: MyText
13+
internal: false

test/fixtures/complaints.yml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Read about fixtures at https://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
2+
3+
one:
4+
user: one
5+
report_type: MyString
6+
status: MyString
7+
assignee: one
8+
user_wants_updates: false
9+
access_token: MyString
10+
11+
two:
12+
user: two
13+
report_type: MyString
14+
status: MyString
15+
assignee: two
16+
user_wants_updates: false
17+
access_token: MyString
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
require "test_helper"
2+
3+
class ComplaintCommentTest < ActiveSupport::TestCase
4+
# test "the truth" do
5+
# assert true
6+
# end
7+
end

test/models/complaint_test.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
require "test_helper"
2+
3+
class ComplaintTest < ActiveSupport::TestCase
4+
# test "the truth" do
5+
# assert true
6+
# end
7+
end

0 commit comments

Comments
 (0)