Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

指摘していただいた部分を修正しました。 #8

Open
wants to merge 14 commits into
base: develop
Choose a base branch
from
Open
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,6 @@ yarn-debug.log*
.yarn-integrity

/config/credentials/production.key

.DS_Store
vendor/bundle/
1 change: 1 addition & 0 deletions .node-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
16.16.0
3 changes: 3 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ group :development, :test do
gem 'byebug', platforms: %i[mri mingw x64_mingw]
gem 'rb-readline'
gem 'rspec-rails'
gem 'capybara', '~> 3.23'
gem 'selenium-webdriver', '4.9.0'
gem 'webdrivers'
end

group :development do
Expand Down
28 changes: 28 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,15 @@ GEM
msgpack (~> 1.0)
builder (3.2.4)
byebug (11.1.3)
capybara (3.39.2)
addressable
matrix
mini_mime (>= 0.1.3)
nokogiri (~> 1.8)
rack (>= 1.6.0)
rack-test (>= 0.6.3)
regexp_parser (>= 1.5, < 3.0)
xpath (~> 3.2)
concurrent-ruby (1.1.9)
crass (1.0.6)
diff-lcs (1.4.4)
Expand Down Expand Up @@ -173,6 +182,7 @@ GEM
mail (2.7.1)
mini_mime (>= 0.1.1)
marcel (1.0.2)
matrix (0.4.2)
method_source (1.0.0)
mini_mime (1.1.2)
minitest (5.14.4)
Expand All @@ -181,6 +191,8 @@ GEM
multi_xml (0.6.0)
multipart-post (2.1.1)
nio4r (2.5.8)
nokogiri (1.12.5-arm64-darwin)
racc (~> 1.4)
nokogiri (1.12.5-x86_64-darwin)
racc (~> 1.4)
nokogiri (1.12.5-x86_64-linux)
Expand Down Expand Up @@ -284,6 +296,7 @@ GEM
rubocop (>= 1.7.0, < 2.0)
ruby-progressbar (1.11.0)
ruby2_keywords (0.0.5)
rubyzip (2.3.2)
sass-rails (6.0.0)
sassc-rails (~> 2.1, >= 2.1.1)
sassc (2.4.0)
Expand All @@ -294,6 +307,10 @@ GEM
sprockets (> 3.0)
sprockets-rails
tilt
selenium-webdriver (4.9.0)
rexml (~> 3.2, >= 3.2.5)
rubyzip (>= 1.2.2, < 3.0)
websocket (~> 1.0)
semantic_range (3.0.0)
sorcery (0.16.1)
bcrypt (~> 3.1)
Expand All @@ -318,24 +335,33 @@ GEM
activemodel (>= 6.0.0)
bindex (>= 0.4.0)
railties (>= 6.0.0)
webdrivers (5.3.1)
nokogiri (~> 1.6)
rubyzip (>= 1.3.0)
selenium-webdriver (~> 4.0, < 4.11)
webpacker (5.4.3)
activesupport (>= 5.2)
rack-proxy (>= 0.6.1)
railties (>= 5.2)
semantic_range (>= 2.3.0)
websocket (1.2.10)
websocket-driver (0.7.5)
websocket-extensions (>= 0.1.0)
websocket-extensions (0.1.5)
xpath (3.2.0)
nokogiri (~> 1.8)
zeitwerk (2.5.1)

PLATFORMS
arm64-darwin-22
x86_64-darwin-19
x86_64-linux

DEPENDENCIES
aws-sdk-s3
bootsnap (>= 1.4.4)
byebug
capybara (~> 3.23)
draper
enum_help
factory_bot_rails
Expand All @@ -356,11 +382,13 @@ DEPENDENCIES
rubocop
rubocop-rails
sass-rails (>= 6)
selenium-webdriver (= 4.9.0)
sorcery
spring
sqlite3 (~> 1.4)
tzinfo-data
web-console (>= 4.1.0)
webdrivers
webpacker (~> 5.0)

RUBY VERSION
Expand Down
16 changes: 15 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,24 @@

## 環境構築
```
$ bundle install
$ bundle install --without=production
$ bin/rails db:setup
$ yarn install
$ bin/webpack
$ bin/rails s
```

## 事業をエンジニアリングしよう提案編の回答は以下に記述してください
```
選択した事業側の課題
直近一年間で、2回以上もくもく会に参加してくれた人は利用者全体の1%のみ。もくもく会で気の合う仲間を見つけられなかったのではないか?

提案内容
・もくもく会にタグ(Ruby, Rails, PHP, iOS, 駆け出しエンジニア etc)を設定 & 絞り込みができるようにする
→ 自分の学習している言語を見つけやすくする。また、人気のタグを表示することで、ユーザーは他の・ユーザープロフィールに、ユーザーのタグ情報を追加する。
→ 人々がどのようなトピックに関心を持っているかを知り、共通の興味を持つ仲間を見つけやすくなる。

実装方針
もくもく会でよく使用されるタグを抽出し、トレンドや人気のあるトピックを表示する機能を追加する。
ユーザープロフィールにおいて、タグを表示する機能を追加する。
```
2 changes: 1 addition & 1 deletion app/controllers/mypage/profiles_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@ def update
private

def profile_params
params.require(:user).permit(:name, :avatar)
params.require(:user).permit(:name, :avatar, :hobby, :profile)
end
end
12 changes: 12 additions & 0 deletions app/controllers/relationships_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
class RelationshipsController < ApplicationController
def create
current_user.follow(params[:user_id])
redirect_to request.referer
end

# フォロー外すとき
def destroy
current_user.unfollow(params[:user_id])
redirect_to request.referer
end
end
19 changes: 19 additions & 0 deletions app/controllers/users_controller.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# frozen_string_literal: true

class UsersController < ApplicationController
before_action :set_user, only: [:show, :follows, :followers]
def new
@user = User.new
end
Expand All @@ -16,6 +17,24 @@ def create
end
end

def show
end

def follows
@users = @user.following_users
end

# フォロワー一覧
def followers
@follower_users = @user.follower_users
end

private

def set_user
@user = User.find(params[:id])
end

def user_params
params.require(:user).permit(:email, :name, :password, :password_confirmation)
end
Expand Down
4 changes: 4 additions & 0 deletions app/models/relationship.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
class Relationship < ApplicationRecord
belongs_to :follower, class_name: "User"
belongs_to :followed, class_name: "User"
end
21 changes: 21 additions & 0 deletions app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,13 @@ class User < ApplicationRecord
has_many :notification_timings, through: :user_notification_timings
has_one_attached :avatar

has_many :followers, class_name: "Relationship", foreign_key: "follower_id", dependent: :destroy
has_many :followeds, class_name: "Relationship", foreign_key: "followed_id", dependent: :destroy

# 一覧画面で使う
has_many :following_users, through: :followers, source: :followed
has_many :follower_users, through: :followeds, source: :follower

validates :password, length: { minimum: 3 }, if: -> { new_record? || changes[:crypted_password] }
validates :password, confirmation: true, if: -> { new_record? || changes[:crypted_password] }
validates :password_confirmation, presence: true, if: -> { new_record? || changes[:crypted_password] }
Expand Down Expand Up @@ -76,4 +83,18 @@ def allow_attended_to_event_notification?
def allow_liked_event_notification?
notification_timings.liked_event.present?
end

def follow(user_id)
followers.create(followed_id: user_id)
end

# フォローを外すときの処理
def unfollow(user_id)
followers.find_by(followed_id: user_id)&.destroy
end

#フォローしていればtrueを返す
def following?(user)
following_users.include?(user)
end
end
2 changes: 1 addition & 1 deletion app/views/events/_event.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
<div class="d-flex align-items-center justify-content-between">
<div class="d-flex align-items-center gap-3">
<%= image_tag event.user.decorate.avatar, class: 'avatar-sm rounded-circle' %>
<%= event.user.name %>
<%= link_to event.user.name, user_path(event.user) %>
</div>
<% if logged_in? %>
<div id="js-event-bookmark-<%= event.id %>">
Expand Down
8 changes: 6 additions & 2 deletions app/views/events/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
<div class="card-body">
<div class="d-flex align-items-center gap-3 mb-3">
<%= image_tag @event.user.decorate.avatar, class: 'rounded-circle avatar-lg' %>
<%= @event.user.name %>
<%= link_to @event.user.name, user_path(@event.user) %>
</div>
<div class="p-3 bg-light">
イベント数
Expand Down Expand Up @@ -112,7 +112,11 @@
</div>
<div class="card-body">
<ul class="list-unstyled">
<%= render partial: 'events/attendee', collection: @event.attendees %>
<% @event.attendees.each do |attendee| %>
<li>
<%= link_to attendee.name, user_path(attendee) %>
</li>
<% end %>
</ul>
</div>
</div>
Expand Down
8 changes: 8 additions & 0 deletions app/views/mypage/profiles/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,14 @@
<%= f.label :name, class: 'form-label' %>
<%= f.text_field :name, class: 'form-control', placeholder: 'らんてくん' %>
</div>
<div class="mb-3">
<%= f.label :hobby, class: 'form-label' %>
<%= f.text_field :hobby, class: 'form-control', placeholder: '趣味' %>
</div>
<div class="mb-3">
<%= f.label :profile, class: 'form-label' %>
<%= f.text_area :profile, class: 'form-control', placeholder: 'プロフィール情報' %>
</div>
<div class="col-12">
<!-- Button -->
<%= f.submit class: 'btn btn-primary' %>
Expand Down
10 changes: 10 additions & 0 deletions app/views/users/show.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<h1><%= @user.name %> のプロフィール</h1>

<p><strong>Hobby:</strong> <%= @user.hobby %></p>
<p><strong>Profile:</strong> <%= @user.profile %></p>

<% if current_user.following?(@user) %>
<%= link_to "フォローを外す", user_relationships_path(@user.id), method: :delete %>
<% else %>
<%= link_to "フォローする", user_relationships_path(@user.id), method: :post %>
<% end %>
8 changes: 7 additions & 1 deletion config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,13 @@
delete 'logout', to: 'sessions#destroy'
get 'signup', to: 'users#new'
post 'signup', to: 'users#create'
resources :users, only: %i[new create]
resources :users, only: %i[new create show] do
member do
get :follows, :followers
end
resource :relationships, only: [:create, :destroy]
end

resources :events do
collection do
get :future
Expand Down
6 changes: 6 additions & 0 deletions db/migrate/20231022153030_add_profile_and_hobby_to_users.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
class AddProfileAndHobbyToUsers < ActiveRecord::Migration[6.1]
def change
add_column :users, :profile, :string
add_column :users, :hobby, :string
end
end
10 changes: 10 additions & 0 deletions db/migrate/20231022154826_create_relationships.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
class CreateRelationships < ActiveRecord::Migration[6.1]
def change
create_table :relationships do |t|
t.integer :follower_id
t.integer :followed_id

t.timestamps
end
end
end
11 changes: 10 additions & 1 deletion db/schema.rb

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions spec/decorators/relationship_decorator_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
require 'rails_helper'

RSpec.describe RelationshipDecorator do
end
6 changes: 6 additions & 0 deletions spec/factories/relationships.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
FactoryBot.define do
factory :relationship do
association :follower, factory: :user
association :followed, factory: :user
end
end
5 changes: 5 additions & 0 deletions spec/models/relationship_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
require 'rails_helper'

RSpec.describe Relationship, type: :model do
pending "add some examples to (or delete) #{__FILE__}"
end
7 changes: 7 additions & 0 deletions spec/requests/relationships_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
require 'rails_helper'

RSpec.describe "Relationships", type: :request do
describe "GET /index" do
pending "add some examples (or delete) #{__FILE__}"
end
end