commit
f0bca74f89
|
@ -0,0 +1,6 @@
|
|||
class ChatRoomsController < ApplicationController
|
||||
|
||||
def create
|
||||
|
||||
end
|
||||
end
|
|
@ -0,0 +1,8 @@
|
|||
class RequestsController < ApplicationController
|
||||
|
||||
def update
|
||||
request.accepted = true
|
||||
|
||||
# Create new Chat Room
|
||||
end
|
||||
end
|
|
@ -0,0 +1,5 @@
|
|||
class ChatRoom < ApplicationRecord
|
||||
has_many :users, through: :chat_room_participations
|
||||
has_many :chat_room_participations
|
||||
has_many :requests
|
||||
end
|
|
@ -0,0 +1,4 @@
|
|||
class ChatRoomParticipation < ApplicationRecord
|
||||
belongs_to :user
|
||||
belongs_to :chat_room
|
||||
end
|
|
@ -8,7 +8,7 @@ class Connection < ApplicationRecord
|
|||
|
||||
def create_inverted_connection
|
||||
unless Connection.where('user_id = ? and contact_id = ?', self.contact.id, self.user.id).length > 0
|
||||
Connection.create!(user: self.contact, contact: self.user)
|
||||
inverted = Connection.create!(user: self.contact, contact: self.user)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -0,0 +1,4 @@
|
|||
class Request < ApplicationRecord
|
||||
belongs_to :user
|
||||
belongs_to :chat_room
|
||||
end
|
|
@ -5,6 +5,9 @@ class User < ApplicationRecord
|
|||
:recoverable, :rememberable, :validatable
|
||||
|
||||
has_many :connections
|
||||
has_many :chat_rooms, through: :chat_room_participations
|
||||
has_many :chat_room_participations
|
||||
has_many :requests
|
||||
|
||||
def contacts
|
||||
self.connections.map do |connection|
|
||||
|
|
|
@ -50,7 +50,7 @@ Rails.application.configure do
|
|||
config.action_cable.allowed_request_origins = [ '*' ]
|
||||
|
||||
# Force all access to the app over SSL, use Strict-Transport-Security, and use secure cookies.
|
||||
# config.force_ssl = true
|
||||
config.force_ssl = true
|
||||
|
||||
# Use the lowest log level to ensure availability of diagnostic information
|
||||
# when problems arise.
|
||||
|
|
|
@ -0,0 +1,8 @@
|
|||
class CreateChatRooms < ActiveRecord::Migration[5.2]
|
||||
def change
|
||||
create_table :chat_rooms do |t|
|
||||
|
||||
t.timestamps
|
||||
end
|
||||
end
|
||||
end
|
|
@ -0,0 +1,10 @@
|
|||
class CreateChatRoomParticipations < ActiveRecord::Migration[5.2]
|
||||
def change
|
||||
create_table :chat_room_participations do |t|
|
||||
t.references :user, foreign_key: true
|
||||
t.references :chat_room, foreign_key: true
|
||||
|
||||
t.timestamps
|
||||
end
|
||||
end
|
||||
end
|
|
@ -0,0 +1,11 @@
|
|||
class CreateRequests < ActiveRecord::Migration[5.2]
|
||||
def change
|
||||
create_table :requests do |t|
|
||||
t.references :user, foreign_key: true
|
||||
t.references :chat_room, foreign_key: true
|
||||
t.boolean :accepted
|
||||
|
||||
t.timestamps
|
||||
end
|
||||
end
|
||||
end
|
|
@ -0,0 +1,5 @@
|
|||
class ChangeColumnInRequests < ActiveRecord::Migration[5.2]
|
||||
def change
|
||||
change_column :requests, :accepted, :boolean, default: false
|
||||
end
|
||||
end
|
30
db/schema.rb
30
db/schema.rb
|
@ -10,11 +10,25 @@
|
|||
#
|
||||
# It's strongly recommended that you check this file into your version control system.
|
||||
|
||||
ActiveRecord::Schema.define(version: 2018_08_27_151325) do
|
||||
ActiveRecord::Schema.define(version: 2018_08_29_123204) do
|
||||
|
||||
# These are extensions that must be enabled in order to support this database
|
||||
enable_extension "plpgsql"
|
||||
|
||||
create_table "chat_room_participations", force: :cascade do |t|
|
||||
t.bigint "user_id"
|
||||
t.bigint "chat_room_id"
|
||||
t.datetime "created_at", null: false
|
||||
t.datetime "updated_at", null: false
|
||||
t.index ["chat_room_id"], name: "index_chat_room_participations_on_chat_room_id"
|
||||
t.index ["user_id"], name: "index_chat_room_participations_on_user_id"
|
||||
end
|
||||
|
||||
create_table "chat_rooms", force: :cascade do |t|
|
||||
t.datetime "created_at", null: false
|
||||
t.datetime "updated_at", null: false
|
||||
end
|
||||
|
||||
create_table "connections", force: :cascade do |t|
|
||||
t.bigint "user_id"
|
||||
t.bigint "contact_id"
|
||||
|
@ -22,6 +36,16 @@ ActiveRecord::Schema.define(version: 2018_08_27_151325) do
|
|||
t.index ["user_id"], name: "index_connections_on_user_id"
|
||||
end
|
||||
|
||||
create_table "requests", force: :cascade do |t|
|
||||
t.bigint "user_id"
|
||||
t.bigint "chat_room_id"
|
||||
t.boolean "accepted", default: false
|
||||
t.datetime "created_at", null: false
|
||||
t.datetime "updated_at", null: false
|
||||
t.index ["chat_room_id"], name: "index_requests_on_chat_room_id"
|
||||
t.index ["user_id"], name: "index_requests_on_user_id"
|
||||
end
|
||||
|
||||
create_table "users", force: :cascade do |t|
|
||||
t.string "email", default: "", null: false
|
||||
t.string "encrypted_password", default: "", null: false
|
||||
|
@ -34,6 +58,10 @@ ActiveRecord::Schema.define(version: 2018_08_27_151325) do
|
|||
t.index ["reset_password_token"], name: "index_users_on_reset_password_token", unique: true
|
||||
end
|
||||
|
||||
add_foreign_key "chat_room_participations", "chat_rooms"
|
||||
add_foreign_key "chat_room_participations", "users"
|
||||
add_foreign_key "connections", "users"
|
||||
add_foreign_key "connections", "users", column: "contact_id"
|
||||
add_foreign_key "requests", "chat_rooms"
|
||||
add_foreign_key "requests", "users"
|
||||
end
|
||||
|
|
|
@ -0,0 +1,7 @@
|
|||
require 'test_helper'
|
||||
|
||||
class ChatRoomsControllerTest < ActionDispatch::IntegrationTest
|
||||
# test "the truth" do
|
||||
# assert true
|
||||
# end
|
||||
end
|
|
@ -0,0 +1,7 @@
|
|||
require 'test_helper'
|
||||
|
||||
class RequestsControllerTest < ActionDispatch::IntegrationTest
|
||||
# test "the truth" do
|
||||
# assert true
|
||||
# end
|
||||
end
|
|
@ -0,0 +1,7 @@
|
|||
require 'test_helper'
|
||||
|
||||
class ChatRoomParticipationTest < ActiveSupport::TestCase
|
||||
# test "the truth" do
|
||||
# assert true
|
||||
# end
|
||||
end
|
|
@ -0,0 +1,7 @@
|
|||
require 'test_helper'
|
||||
|
||||
class ChatRoomTest < ActiveSupport::TestCase
|
||||
# test "the truth" do
|
||||
# assert true
|
||||
# end
|
||||
end
|
|
@ -0,0 +1,7 @@
|
|||
require 'test_helper'
|
||||
|
||||
class RequestTest < ActiveSupport::TestCase
|
||||
# test "the truth" do
|
||||
# assert true
|
||||
# end
|
||||
end
|
Loading…
Reference in New Issue