Xwitter 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 9b50b28b796dfc085d711e55972d4ab8715581551eb7f208b04c15026bf11ea1
4
- data.tar.gz: 0760f874e11fe179e2f5c31c82bbeaaec3a8f5f77b878e7d16221f4787a02abc
3
+ metadata.gz: d604abaf77a9180b5a024d4b8547822ed95d753c44725891f91d5f67bf09cc24
4
+ data.tar.gz: 90a4dcca82463b218fcda903e16a0f7a3a0c4716637aecdc9b5d3be5cd8a2cb1
5
5
  SHA512:
6
- metadata.gz: 5f9a0454aff54100bee78332684a25d6f08502cfec69fc14b5d15389722643b78cc2fde41c0aeaaf72cdb09644b4fca255680f92133830e11d41f7a087360fe1
7
- data.tar.gz: c5c7b9e9d60941451702e55618d10a5b78d503d0d975ff550a7373ae3b1b6f27180d5547bca50b1d8cb0a54e3762d4176ad274f71874e75e44693861ca349e18
6
+ metadata.gz: 95783e0b3c87e8dc35b442db77887a1210e3678ed802d295701627ac257bb3d641da740f6c7f70f0571175a3cf28c160facd5e2da8197e8de6eb8e863119c087
7
+ data.tar.gz: 1f953cd9e5ee150bb378079fb6db297031a8fe470dbdc7fed03219dac4d9fb2e92ea0170194b7a6e9f336a1dc5636b9bc97f46ba50369b51b700ed826718c545
data/Schemafile CHANGED
@@ -1,23 +1,34 @@
1
1
  # Export Schema
2
- create_table :users do |t|
3
- t.string :email, null: false
4
- t.string :name
5
- t.string :screen_name
6
- t.string :encrypted_password, null: false
7
- t.string :reset_password_token
8
- t.boolean :public, null: false, default: true
9
- t.datetime :reset_password_sent_at
10
- t.datetime :remember_created_at
2
+ create_table "users" do |t|
3
+ t.string "email", null: false
4
+ t.string "name"
5
+ t.string "screen_name"
6
+ t.string "encrypted_password", null: false
7
+ t.string "reset_password_token"
8
+ t.boolean "public", null: false, default: true
9
+ t.datetime "reset_password_sent_at"
10
+ t.datetime "remember_created_at"
11
11
  t.timestamps null: false
12
12
  t.index ["name"], unique: true
13
13
  end
14
14
 
15
+ create_table "observes", force: :cascade do |t|
16
+ t.bigint "from_user_id", null: false
17
+ t.bigint "to_user_id", null: false
18
+ t.timestamps null: false
19
+ t.index ["from_user_id", "to_user_id"], unique: true
20
+ t.index ["to_user_id", "from_user_id"], unique: true
21
+ end
22
+ add_foreign_key "observes", "users", column: "from_user_id"
23
+ add_foreign_key "observes", "users", column: "to_user_id", name: "observe_to_user_fk"
24
+
15
25
  create_table "messages", force: :cascade do |t|
16
26
  t.bigint "user_id", null: false
17
27
  t.text "text", null: false
18
28
  t.datetime "created_at", null: false
19
29
  t.index ["user_id"]
20
30
  end
31
+ add_foreign_key "messages", "users"
21
32
 
22
33
  create_table "likes", force: :cascade do |t|
23
34
  t.bigint "user_id", null: false
@@ -33,7 +44,6 @@ create_table "shares", force: :cascade do |t|
33
44
  t.index ["user_id", "message_id"], unique: true
34
45
  end
35
46
 
36
- add_foreign_key "messages", "users"
37
47
  add_foreign_key "likes", "users"
38
48
  add_foreign_key "likes", "messages"
39
49
  add_foreign_key "shares", "users"
@@ -0,0 +1,13 @@
1
+ class FollowsController < ApplicationController
2
+ # POST /:username/follow
3
+ def create
4
+ Observe.create!(from_user: current_user, to_user: User.find_by(name: params[:username]))
5
+ redirect_to "/" + params[:username]
6
+ end
7
+
8
+ # DELETE /:username/follow
9
+ def destroy
10
+ Observe.find_by(from_user: current_user, to_user: User.find_by(name: params[:username])).destroy
11
+ redirect_to "/" + params[:username]
12
+ end
13
+ end
@@ -8,7 +8,13 @@ class MessagesController < ApplicationController
8
8
  redirect_to edit_profile_url
9
9
  return
10
10
  end
11
- @messages = Message.all
11
+
12
+ if user_signed_in?
13
+ user_ids = current_user.observe_users.pluck(:id) + [current_user.id]
14
+ @messages = Message.where(user_id: user_ids)
15
+ else
16
+ @messages = Message.all
17
+ end
12
18
  end
13
19
 
14
20
  # GET /messages/1
@@ -0,0 +1,4 @@
1
+ class Observe < ApplicationRecord
2
+ belongs_to :from_user, class_name: 'User'
3
+ belongs_to :to_user, class_name: 'User'
4
+ end
data/app/models/user.rb CHANGED
@@ -3,4 +3,12 @@ class User < ApplicationRecord
3
3
  # :confirmable, :lockable, :timeoutable, :trackable and :omniauthable
4
4
  devise :database_authenticatable, :registerable,
5
5
  :recoverable, :rememberable, :validatable
6
+
7
+ has_many :observes, foreign_key: "from_user_id", class_name: "Observe"
8
+ has_many :observe_users, through: :observes, source: "to_user"
9
+ has_many :observed, foreign_key: "to_user_id", class_name: "Observe"
10
+
11
+ def follow?(user)
12
+ observe_users.include?(user)
13
+ end
6
14
  end
@@ -1,4 +1,4 @@
1
- - messages.each do |message|
1
+ - messages.order("created_at DESC").each do |message|
2
2
  div
3
3
  p
4
4
  = message.user.screen_name
@@ -6,15 +6,4 @@ h1
6
6
  = link_to 'Sign in', new_user_session_path, class: 'btn btn-primary'
7
7
  = link_to 'Sign up', new_user_registration_path, class: 'btn btn-default'
8
8
 
9
- - @messages.each do |message|
10
- div
11
- p
12
- = message.user.screen_name
13
- | &nbsp;
14
- = link_to '@' + message.user.name, '/' + message.user.name
15
-
16
- p= message.text
17
- p= l message.created_at
18
- - if user_signed_in? && message.user == current_user
19
- .oi.oi-trash
20
- = link_to 'Destroy', message, data: { confirm: 'Are you sure?' }, method: :delete
9
+ = render 'index', messages: @messages
@@ -2,7 +2,13 @@ h2
2
2
  = @user.screen_name
3
3
  | &nbsp;
4
4
  small= '@' + @user.name
5
- - if @user == current_user
6
- = link_to 'Edit', edit_profile_path, class: 'btn'
5
+ - if user_signed_in?
6
+ | &nbsp;
7
+ - if @user == current_user
8
+ = link_to 'Edit', edit_profile_path, class: 'btn'
9
+ - elsif current_user.follow?(@user)
10
+ = link_to 'Unfollow', follow_path, class: 'btn btn-warning', method: :delete
11
+ - else
12
+ = link_to 'Follow', follow_path, class: 'btn btn-primary', method: :post
7
13
 
8
14
  = render 'messages/index', messages: Message.where(user: @user)
data/config/routes.rb CHANGED
@@ -4,4 +4,6 @@ Rails.application.routes.draw do
4
4
  devise_for :users
5
5
  root 'messages#index'
6
6
  get ':username', to: 'profiles#show'
7
+ post ':username/follow', to: 'follows#create', as: 'follow'
8
+ delete ':username/follow', to: 'follows#destroy'
7
9
  end
@@ -1,3 +1,3 @@
1
1
  module Xwitter
2
- VERSION = "0.1.0"
2
+ VERSION = "0.2.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: Xwitter
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - myun2
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-11-10 00:00:00.000000000 Z
11
+ date: 2018-11-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -71,6 +71,7 @@ files:
71
71
  - app/channels/application_cable/connection.rb
72
72
  - app/controllers/application_controller.rb
73
73
  - app/controllers/concerns/.keep
74
+ - app/controllers/follows_controller.rb
74
75
  - app/controllers/messages_controller.rb
75
76
  - app/controllers/profiles_controller.rb
76
77
  - app/helpers/application_helper.rb
@@ -87,6 +88,7 @@ files:
87
88
  - app/models/application_record.rb
88
89
  - app/models/concerns/.keep
89
90
  - app/models/message.rb
91
+ - app/models/observe.rb
90
92
  - app/models/user.rb
91
93
  - app/views/layouts/application.html.slim
92
94
  - app/views/layouts/mailer.html.erb