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

Social media website #384

Open
wants to merge 22 commits into
base: master
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
8 changes: 4 additions & 4 deletions .github/workflows/linters.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ jobs:
- uses: actions/checkout@v2
- uses: actions/setup-ruby@v1
with:
ruby-version: 2.6.x
ruby-version: 3.0.x
- name: Setup Rubocop
run: |
gem install --no-document rubocop:'~>0.81.0' # https://docs.rubocop.org/en/stable/installation/
gem install --no-document rubocop -v '>= 1.0, < 2.0' # https://docs.rubocop.org/en/stable/installation/
[ -f .rubocop.yml ] || wget https://raw.githubusercontent.com/microverseinc/linters-config/master/ror/.rubocop.yml
- name: Rubocop Report
run: rubocop --color
Expand All @@ -30,7 +30,7 @@ jobs:
node-version: "12.x"
- name: Setup Stylelint
run: |
npm install --save-dev stylelint@13.3.x stylelint-scss@3.17.x stylelint-config-standard@20.0.x stylelint-csstree-validator
npm install --save-dev [email protected] [email protected] stylelint-config-standard@21.x stylelint-csstree-validator@1.x
[ -f .stylelintrc.json ] || wget https://raw.githubusercontent.com/microverseinc/linters-config/master/ror/.stylelintrc.json
- name: Stylelint Report
run: npx stylelint "**/*.{css,scss}"
run: npx stylelint "**/*.{css,scss}"
19 changes: 4 additions & 15 deletions .rubocop.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
AllCops:
NewCops: enable
Exclude:
- "db/**/*"
- "bin/*"
- "config/**/*"
- "Guardfile"
- "Rakefile"
- "node_modules/**/*"
Expand All @@ -12,21 +10,16 @@ AllCops:
Layout/LineLength:
Max: 120
Metrics/MethodLength:
Include:
- "app/controllers/*"
- "app/models/*"
Max: 20
Metrics/AbcSize:
Include:
- "app/controllers/*"
- "app/models/*"
Max: 50
Metrics/ClassLength:
Max: 150
Metrics/BlockLength:
ExcludedMethods: ["describe"]
IgnoredMethods: ['describe']
Max: 30


Style/Documentation:
Enabled: false
Style/ClassAndModuleChildren:
Expand All @@ -47,13 +40,9 @@ Layout/ExtraSpacing:
Layout/MultilineMethodCallIndentation:
Enabled: true
EnforcedStyle: indented
Lint/RaiseException:
Enabled: false
Lint/StructNewOverride:
Enabled: false
Style/HashEachMethods:
Enabled: false
Style/HashTransformKeys:
Enabled: false
Style/HashTransformValues:
Enabled: false
Enabled: false
13 changes: 1 addition & 12 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
source 'https://rubygems.org'
git_source(:github) { |repo| "https://github.com/#{repo}.git" }

ruby '2.7.0'

# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '~> 5.2.4'
# Use postgresql as the database for Active Record
Expand All @@ -15,7 +13,6 @@ gem 'sass-rails', '~> 5.0'
gem 'uglifier', '>= 1.3.0'
# See https://github.com/rails/execjs#readme for more supported runtimes
# gem 'mini_racer', platforms: :ruby

# Use CoffeeScript for .coffee assets and views
gem 'coffee-rails', '~> 4.2'
# Turbolinks makes navigating your web application faster. Read more: https://github.com/turbolinks/turbolinks
Expand All @@ -30,22 +27,15 @@ gem 'jbuilder', '~> 2.5'
gem 'wdm', '>= 0.1.0' if Gem.win_platform?
# Use ActiveStorage variant
# gem 'mini_magick', '~> 4.8'

# Use Capistrano for deployment
# gem 'capistrano-rails', group: :development

# Reduces boot times through caching; required in config/boot.rb
gem 'bootsnap', '>= 1.1.0', require: false

gem 'devise'

group :development, :test do
# Call 'byebug' anywhere in the code to stop execution and get a debugger console
gem 'byebug', platforms: %i[mri mingw x64_mingw]
end

group :test do
gem 'rspec'
gem 'rspec-rails', '~> 5.0', '>= 5.0.1'
end

group :development do
Expand All @@ -57,6 +47,5 @@ group :development do
gem 'spring'
gem 'spring-watcher-listen', '~> 2.0.0'
end

# Windows does not include zoneinfo files, so bundle the tzinfo-data gem
gem 'tzinfo-data', platforms: %i[mingw mswin x64_mingw jruby]
34 changes: 20 additions & 14 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ GEM
railties (>= 4.1.0)
responders
warden (~> 1.2.3)
diff-lcs (1.3)
diff-lcs (1.4.4)
erubi (1.9.0)
execjs (2.7.0)
ffi (1.12.2)
Expand All @@ -89,7 +89,9 @@ GEM
marcel (0.3.3)
mimemagic (~> 0.3.2)
method_source (0.9.2)
mimemagic (0.3.4)
mimemagic (0.3.10)
nokogiri (~> 1)
rake
mini_mime (1.0.2)
mini_portile2 (2.5.0)
minitest (5.14.0)
Expand Down Expand Up @@ -145,19 +147,23 @@ GEM
actionpack (>= 5.0)
railties (>= 5.0)
rexml (3.2.4)
rspec (3.9.0)
rspec-core (~> 3.9.0)
rspec-expectations (~> 3.9.0)
rspec-mocks (~> 3.9.0)
rspec-core (3.9.1)
rspec-support (~> 3.9.1)
rspec-expectations (3.9.1)
rspec-core (3.10.1)
rspec-support (~> 3.10.0)
rspec-expectations (3.10.1)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.9.0)
rspec-mocks (3.9.1)
rspec-support (~> 3.10.0)
rspec-mocks (3.10.2)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.9.0)
rspec-support (3.9.2)
rspec-support (~> 3.10.0)
rspec-rails (5.0.1)
actionpack (>= 5.2)
activesupport (>= 5.2)
railties (>= 5.2)
rspec-core (~> 3.10)
rspec-expectations (~> 3.10)
rspec-mocks (~> 3.10)
rspec-support (~> 3.10)
rspec-support (3.10.2)
rubocop (0.80.1)
jaro_winkler (~> 1.5.1)
parallel (~> 1.10)
Expand Down Expand Up @@ -228,7 +234,7 @@ DEPENDENCIES
pg (>= 0.18, < 2.0)
puma (~> 3.12)
rails (~> 5.2.4)
rspec
rspec-rails (~> 5.0, >= 5.0.1)
rubocop
sass-rails (~> 5.0)
spring
Expand Down
46 changes: 29 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,20 @@
# Scaffold for social media app with Ruby on Rails
# Social media website

> We build a social media app for users to create and like each other's posts. They can also comment on posts.
- As a guest user:
- You're able to create account/log in.
- You can see “Sign in” and “Sign out” page.
<br>
- As a logged-in user:
- You're able to see all users list.
- You're able to see selected user page with their user name and all posts written by them
- You're able to send a friendship invitation.
- You're able to see pending friendship invitations sent to me from other users.
- You're able to accept or reject friendships invitation.
- You're able to create new posts (text only).
- You're able to like/dislike posts (but I can like single post only once).
- You're able to add comments to posts.

> This repo includes intial code for social media app with basic styling. Its purpose is to be a starting point for Microverse students.

## Built With

Expand All @@ -9,8 +23,6 @@

## Live Demo

TBA


## Getting Started

Expand All @@ -37,16 +49,6 @@ Setup database with:
rails db:migrate
```

### Github Actions

To make sure the linters' checks using Github Actions work properly, you should follow the next steps:

1. On your recently forked repo, enable the GitHub Actions in the Actions tab.
2. Create the `feature/branch` and push.
3. Start working on your milestone as usual.
4. Open a PR from the `feature/branch` when your work is done.


### Usage

Start server with:
Expand All @@ -70,14 +72,24 @@ Open `http://localhost:3000/` in your browser.
TBA

## Authors
👤 **Moises Hernandez Coronado**

- GitHub: [@Mhdez221993](https://github.com/Mhdez221993)
- Twitter: [@MoisesH42060050](https://twitter.com/MoisesH42060050)
- LinkedIn: [Moises Hernandez Coronado](https://www.linkedin.com/in/moises-hernandez-coronado/)

👤 **Ivana Novaković-Leković**

- GitHub: [@githubhandle](https://github.com/1v4n4)
- Twitter: [@twitterhandle](https://twitter.com/codeIv1)
- LinkedIn: [LinkedIn](https://www.linkedin.com/in/1v4n4/)

TBA

## 🤝 Contributing

Contributions, issues and feature requests are welcome!
Contributions, issues, and feature requests are welcome!

Feel free to check the [issues page](issues/).
Feel free to check the [issues page](https://github.com/Mhdez221993/private-events/issues).

## Show your support

Expand Down
3 changes: 3 additions & 0 deletions app/assets/javascripts/friendships.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Place all the behaviors and hooks related to the matching controller here.
# All this logic will automatically be available in application.js.
# You can use CoffeeScript in this file: http://coffeescript.org/
3 changes: 3 additions & 0 deletions app/assets/stylesheets/friendships.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// Place all the styles related to the friendships controller here.
// They will automatically be included in application.css.
// You can use Sass (SCSS) here: http://sass-lang.com/
69 changes: 69 additions & 0 deletions app/controllers/friendships_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
class FriendshipsController < ApplicationController
before_action :set_friendship, only: %i[show edit update destroy]
before_action :authenticate_user!, only: %i[index show]

def index
@friendships = Friendship.all
end

def show; end

def new
@friendship = Friendship.new
end

def edit; end

def create
friend = User.find(params[:friend_id])
if Friendship.where(user_id: current_user.id, friend_id: friend.id).exists?
redirect_to root_path, notice: 'Frend request already sent'
return
elsif current_user == friend
redirect_to root_path, notice: "You can't send request to yourself"
return
end

@friendship = current_user.friendships.build(friend_id: friend.id)

respond_to do |format|
if @friendship.save
format.html { redirect_to users_path, notice: 'Friend request sent' }
format.json { render :show, status: :created, location: @friendship }
else
format.html { render :new }
format.json { render json: @friendship.errors, status: :unprocessable_entity }
end
end
end

def update
respond_to do |format|
if @friendship.update(friendship_params)
format.html { redirect_to root_path, notice: 'Friend request accepted.' }
format.json { render :show, status: :ok, location: @friendship }
else
format.html { render :edit }
format.json { render json: @friendship.errors, status: :unprocessable_entity }
end
end
end

def destroy
@friendship.destroy
respond_to do |format|
format.html { redirect_to users_path, notice: 'Friendship was declined' }
format.json { head :no_content }
end
end

private

def set_friendship
@friendship = Friendship.find(params[:id])
end

def friendship_params
params.require(:friendship).permit(:user_id, :friend_id, :confirmed)
end
end
1 change: 1 addition & 0 deletions app/controllers/users_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,6 @@ def index
def show
@user = User.find(params[:id])
@posts = @user.posts.ordered_by_most_recent
@received = Friendship.where(friend_id: @user.id, confirmed: false)
end
end
2 changes: 2 additions & 0 deletions app/helpers/friendships_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
module FriendshipsHelper
end
4 changes: 4 additions & 0 deletions app/models/friendship.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
class Friendship < ApplicationRecord
belongs_to :user
belongs_to :friend, class_name: 'User'
end
3 changes: 3 additions & 0 deletions app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,7 @@ class User < ApplicationRecord
has_many :posts
has_many :comments, dependent: :destroy
has_many :likes, dependent: :destroy

has_many :friendships, foreign_key: 'user_id'
has_many :inverse_friendships, class_name: 'Friendship', foreign_key: 'friend_id'
end
22 changes: 22 additions & 0 deletions app/views/friendships/_form.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<%= form_with(model: friendship, local: true) do |form| %>
<% if friendship.errors.any? %>
<div id="error_explanation">
<h2><%= pluralize(friendship.errors.count, "error") %> prohibited this friendship from being saved:</h2>

<ul>
<% friendship.errors.full_messages.each do |message| %>
<li><%= message %></li>
<% end %>
</ul>
</div>
<% end %>

<div class="field">
<%= form.label :confirmed %>
<%= form.check_box :confirmed %>
</div>

<div class="actions">
<%= form.submit %>
</div>
<% end %>
2 changes: 2 additions & 0 deletions app/views/friendships/_friendship.json.jbuilder
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
json.extract! friendship, :id, :user_id, :friend_id, :confirmed, :created_at, :updated_at
json.url friendship_url(friendship, format: :json)
6 changes: 6 additions & 0 deletions app/views/friendships/edit.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<h1>Editing Friendship</h1>

<%= render 'form', friendship: @friendship %>


<%= link_to 'Back', friendships_path %>
Loading