Commit bc088319 authored by Vanessa Silva's avatar Vanessa Silva
Browse files

Merge branch 'user-view-profile' into 'development'

User can match

See merge request !11
parents b32d5a5e 65361c03
Pipeline #41794 passed with stages
in 2 minutes and 23 seconds
inherit_from: .rubocop_todo.yml
Style/Documentation:
Enabled: false
\ No newline at end of file
Enabled: false
Layout/EndOfLine:
Enabled: False
\ No newline at end of file
......@@ -12,4 +12,17 @@ label{
.profile-picture-w-20{
width: 20%;
}
.grid-container{
display: grid;
grid-template-columns: 50% 50%;
}
.page-division{
border-right: 1px solid black;
}
.items-center{
margin-left: 20%;
}
\ No newline at end of file
class HomeController < ApplicationController
def index
@possible_match = find_possible_match.first if user_signed_in?
@match_users = current_user.match_users if user_signed_in?
end
private
......
class LikesController < ApplicationController
def create
def create # rubocop:disable Metrics/AbcSize
@like = Like.new(like_params)
if @like.save
flash[:notice] = 'Like successful'
got_liked_user = User.find_by(id: like_params[:liked_user_id])
like_exists = Like.exists?(liked_user_id: current_user.id, user_id: got_liked_user.id)
Match.create(user_one: got_liked_user, user_two: current_user) if like_exists
redirect_to root_path
else
flash[:alert] = 'Like no success'
......
class Dislike < ApplicationRecord
validates_uniqueness_of :disliked_user_id, scope: :user_id
belongs_to :user
belongs_to :disliked_user, class_name: 'User'
end
class Like < ApplicationRecord
validates_uniqueness_of :liked_user_id, scope: :user_id
belongs_to :user
belongs_to :liked_user, class_name: 'User'
end
class Match < ApplicationRecord
belongs_to :user_one, class_name: 'User', foreign_key: :user_one_id
belongs_to :user_two, class_name: 'User', foreign_key: :user_two_id
end
......@@ -13,6 +13,12 @@ class User < ApplicationRecord
has_many :disliked_users, through: :dislikes, primary_key: 'user_id', foreign_key: 'disliked_user_id'
has_many :users_who_disliked, through: :dislikes_received, source: :user
# Matches
has_many :matches_one, class_name: "Match", foreign_key: 'user_one_id', dependent: :destroy
has_many :matched_users_one, through: :matches_one, primary_key: 'user_one_id', foreign_key: 'user_two_id', source: :user_two
has_many :matches_two, class_name: "Match", foreign_key: 'user_two_id', dependent: :destroy
has_many :matched_users_two, through: :matches_two, source: :user_one
devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :validatable
validates :birthday, presence: true
......@@ -22,4 +28,8 @@ class User < ApplicationRecord
def age
((Date.today - birthday.to_date) / 365).floor
end
def match_users
matched_users_one + matched_users_two
end
end
<div>
<% if user_signed_in? %>
<div class="container-space-from-the-edge">
<% if @possible_match.nil? %>
<div>
<h1>No more people to see, sorry!</h1>
</div>
<% else %>
<div>
<% if @possible_match.profile_picture.attached? %>
<%= image_tag @possible_match.profile_picture, class: "profile-picture-w-20" %>
<% else %>
<div class="grid-container">
<div class="page-division items-center">
<% if @match_users.empty? %>
<div>
<h2>No matches yet!</h2>
</div>
<% else %>
<h2>Matches</h2>
<% @match_users.each do |user| %>
<div>
<%= image_tag 'placeholder.png' %>
<% if user.profile_picture.attached? %>
<%= image_tag user.profile_picture, class: "profile-picture-w-20" %>
<% else %>
<div>
<%= image_tag 'placeholder.png' %>
</div>
<% end %>
</div>
<div>
<span><%= user.first_name %></span>
<span><%= user.age %></span>
<p><%= user.biography %></p>
</div>
<% end %>
</div>
<div>
<p><%= @possible_match.first_name %></p>
<p><%= @possible_match.age %></p>
<p><%= @possible_match.biography %></p>
<p><%= @possible_match.interests %></p>
</div>
<%= link_to 'Nope', dislikes_path(dislike: {user_id: current_user.id, disliked_user_id: @possible_match.id}), method: :post %>
<%= link_to 'Like', likes_path(like: {user_id: current_user.id, liked_user_id: @possible_match.id}), method: :post %>
<% end %>
<% end %>
</div>
<div class="items-center">
<h2>Swipe!</h2>
<% if @possible_match.nil? %>
<div>
<h1>No more people to see, sorry!</h1>
</div>
<% else %>
<div>
<div>
<% if @possible_match.profile_picture.attached? %>
<%= image_tag @possible_match.profile_picture, class: "profile-picture-w-20" %>
<% else %>
<div>
<%= image_tag 'placeholder.png' %>
</div>
<% end %>
</div>
<div>
<p><%= @possible_match.first_name %></p>
<p><%= @possible_match.age %></p>
<p><%= @possible_match.biography %></p>
<p><%= @possible_match.interests %></p>
</div>
<%= link_to 'Nope', dislikes_path(dislike: {user_id: current_user.id, disliked_user_id: @possible_match.id}), method: :post %>
<%= link_to 'Like', likes_path(like: {user_id: current_user.id, liked_user_id: @possible_match.id}), method: :post %>
</div>
</div>
<% end %>
</div>
</div>
<% else %>
<div class="d-flex justify-content-center">
......
class Matches < ActiveRecord::Migration[6.1]
def change
create_table :matches do |t|
t.belongs_to :user_one
t.belongs_to :user_two
t.timestamps
end
end
end
......@@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 2021_09_13_124519) do
ActiveRecord::Schema.define(version: 2021_09_14_135410) do
# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
......@@ -61,6 +61,15 @@ ActiveRecord::Schema.define(version: 2021_09_13_124519) do
t.index ["user_id"], name: "index_likes_on_user_id"
end
create_table "matches", force: :cascade do |t|
t.bigint "user_one_id"
t.bigint "user_two_id"
t.datetime "created_at", precision: 6, null: false
t.datetime "updated_at", precision: 6, null: false
t.index ["user_one_id"], name: "index_matches_on_user_one_id"
t.index ["user_two_id"], name: "index_matches_on_user_two_id"
end
create_table "users", force: :cascade do |t|
t.string "email", default: "", null: false
t.string "encrypted_password", default: "", null: false
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment