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

Implementation #9

Open
wants to merge 10 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added .DS_Store
Binary file not shown.
1 change: 1 addition & 0 deletions .node-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
16.16.0
5 changes: 4 additions & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ ruby '3.0.2'
# Bundle edge Rails instead: gem 'rails', github: 'rails/rails', branch: 'main'
gem 'rails', '~> 6.1.4', '>= 6.1.4.1'
# Use Puma as the app server
gem 'puma', '~> 5.0'
gem 'puma'
# Use SCSS for stylesheets
gem 'sass-rails', '>= 6'
# Transpile app-like JavaScript. Read more: https://github.com/rails/webpacker
Expand Down 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
34 changes: 31 additions & 3 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,14 +182,17 @@ 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)
msgpack (1.4.2)
multi_json (1.15.0)
multi_xml (0.6.0)
multipart-post (2.1.1)
nio4r (2.5.8)
nio4r (2.5.9)
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 All @@ -197,7 +209,7 @@ GEM
ast (~> 2.4.1)
pg (1.2.3)
public_suffix (4.0.6)
puma (5.5.2)
puma (6.4.0)
nio4r (~> 2.0)
racc (1.6.0)
rack (2.2.3)
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 @@ -346,7 +372,7 @@ DEPENDENCIES
letter_opener_web
listen (~> 3.3)
pg
puma (~> 5.0)
puma
rack-mini-profiler (~> 2.0)
rails (~> 6.1.4, >= 6.1.4.1)
rails-i18n
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
14 changes: 13 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,22 @@

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

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

②提出内容
もくもく会にタグの設定と絞り込みができるようにする。これにより、同じ目的を持った人たちが集まりやすいようにする。
また、開催場所の検索と絞り込みもできるようにする。これにより、ユーザーが行きやすいイベントを簡単に見つけられるようにする。

③実装方針
・もくもく会作成時にタグを設定できるようにする。
・ヘッダーの検索フォームにタグと開催地の条件を追加する。
・もくもく会一覧画面で、イベントに設定されているタグ又は開催地をクリックすると、それで絞り込みできるようにする。
Binary file added app/.DS_Store
Binary file not shown.
Binary file added app/assets/.DS_Store
Binary file not shown.
Binary file added app/assets/stylesheets/.DS_Store
Binary file not shown.
2 changes: 1 addition & 1 deletion app/assets/stylesheets/application.scss
Original file line number Diff line number Diff line change
@@ -1 +1 @@
@import 'theme.css';
@import 'theme.css';
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
11 changes: 11 additions & 0 deletions app/controllers/relationships_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
class RelationshipsController < ApplicationController
def create
current_user.follow(params[:user_id])
redirect_to user_path(params[:user_id])
end

def destroy
current_user.unfollow(params[:user_id])
redirect_to user_path(params[:user_id])
end
end
16 changes: 16 additions & 0 deletions app/controllers/users_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,22 @@ def new
@user = User.new
end

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

def follow
user = User.find(params[:id])
current_user.follow(user)
redirect_to user
end

def unfollow
user = User.find(params[:id])
current_user.unfollow(user)
redirect_to user
end

def create
@user = User.new(user_params)
if @user.save
Expand Down
13 changes: 13 additions & 0 deletions app/decorators/relationship_decorator.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
class RelationshipDecorator < Draper::Decorator
delegate_all

# Define presentation-specific methods here. Helpers are accessed through
# `helpers` (aka `h`). You can override attributes, for example:
#
# def created_at
# helpers.content_tag :span, class: 'time' do
# object.created_at.strftime("%a %m/%d/%y")
# end
# end

end
Binary file added app/javascript/.DS_Store
Binary file not shown.
Binary file added app/javascript/channels/.DS_Store
Binary file not shown.
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
20 changes: 20 additions & 0 deletions app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,14 @@ class User < ApplicationRecord
has_many :user_notification_timings, dependent: :destroy
has_many :notification_timings, through: :user_notification_timings
has_one_attached :avatar
has_many :active_relationships, class_name: "Relationship",
foreign_key: "follower_id",
dependent: :destroy
has_many :passive_relationships, class_name: "Relationship",
foreign_key: "followed_id",
dependent: :destroy
has_many :following, through: :active_relationships, source: :followed
has_many :followers, through: :passive_relationships, source: :follower

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

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

def unfollow(user_id)
active_relationships.find_by(followed_id: user_id).destroy
end

def following?(user)
following.include?(user)
end
end
2 changes: 1 addition & 1 deletion app/views/events/_attendee.html.erb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<li>
<div class="d-flex align-items-center gap-2 mb-3">
<%= image_tag attendee.decorate.avatar, class: 'rounded-circle avatar-md' %>
<%= attendee.name %>
<%= link_to attendee.name, user_path(attendee) %>
</div>
</li>
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
2 changes: 1 addition & 1 deletion 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
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_field :profile, class: 'form-control', placeholder: 'プロフィール' %>
</div>
<div class="col-12">
<!-- Button -->
<%= f.submit class: 'btn btn-primary' %>
Expand Down
38 changes: 38 additions & 0 deletions app/views/users/show.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<div class="container">
<div class="row">
<div class="col-12 col-md-8">
<div class="card mb-3">
<div class="card-body">
<div class="d-flex align-items-center">
<div class="p-3">
<%= image_tag @user.decorate.avatar, class: 'avatar-lg rounded-circle' %>
</div>
<h1>
<%= @user.name %>
</h1>
<% if current_user != @user %>
<% if current_user.following?(@user) %>
<%= link_to "フォローを外す", user_relationships_path(@user.id), method: :delete, class: "btn btn-danger" %>
<% else %>
<%= link_to "フォローする", user_relationships_path(@user.id), method: :post, class:"btn btn-success" %>
<% end %>
<% end %>
</div>
</div>
</div>
<div class="card">
<div class="card-header">
プロフィール
</div>
<div class="card-body">
<h4>名前</h4>
<p><%= @user.name %></p>
<h4>趣味</h4>
<p><%= @user.hobby %></p>
<h4>自己紹介</h4>
<p><%= @user.profile %></p>
</div>
</div>
</div>
</div>
</div>
5 changes: 4 additions & 1 deletion config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@
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
resource :relationships, only: [:create, :destroy]
end

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

t.timestamps
end

add_index :relationships, :follower_id
add_index :relationships, :followed_id
add_index :relationships, [:follower_id, :followed_id], unique: true
end
end
Loading