Skip to content

Commit

Permalink
Merge branch 'main' into feat/priorizando-usuarios-premium
Browse files Browse the repository at this point in the history
  • Loading branch information
hreis1 authored Feb 15, 2024
2 parents 78ff119 + a0ca345 commit a47964c
Show file tree
Hide file tree
Showing 50 changed files with 797 additions and 127 deletions.
1 change: 1 addition & 0 deletions Procfile.dev
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
web: env RUBY_DEBUG_OPEN=true bin/rails server
js: yarn build --watch
css: yarn watch:css
job: bundle exec rake solid_queue:start
14 changes: 14 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ O Portfoliorrr é uma rede social com funcionalidades de portfólio para pessoas

- [Informações técnicas](https://github.com/TreinaDev/td11-portfoliorrr?tab=readme-ov-file#informa%C3%A7%C3%B5es-t%C3%A9cnicas)
- [Como configurar a aplicação](https://github.com/TreinaDev/td11-portfoliorrr?tab=readme-ov-file#como-configurar-a-aplica%C3%A7%C3%A3o)
- [Ver emails enviados em ambiente de desenvolvimento](https://github.com/TreinaDev/td11-portfoliorrr?tab=readme-ov-file#ver-emails-enviados-em-ambiente-de-desenvolvimento)
- [Como visualizar a aplicação no navegador](https://github.com/TreinaDev/td11-portfoliorrr?tab=readme-ov-file#como-visualizar-a-aplica%C3%A7%C3%A3o-no-navegador)
- [Documentação da API](https://github.com/TreinaDev/td11-portfoliorrr?tab=readme-ov-file#documenta%C3%A7%C3%A3o-da-api)

Expand All @@ -27,6 +28,19 @@ O Portfoliorrr é uma rede social com funcionalidades de portfólio para pessoas
- Rode o comando `bin/dev`;
- Acesse a aplicação através do endereço `http://localhost:4000/`

## Ver emails enviados em ambiente de desenvolvimento

- Siga as instruções de configuração da aplicação;
- Instale localmente a gem `mailcatcher` executando o comando abaixo:
```shell
gem install mailcatcher
```
- Execute o comando abaixo para iniciar o `mailcatcher`
```shell
mailcatcher
```
- Acesse o MailCatcher através do endereço `http://localhost:1080`. Todos e-mails enviados serão mostrados nessa página, que emula uma caixa de entrada.

## Como rodar os testes da aplicação

- Siga as instruções de configuração da aplicação
Expand Down
28 changes: 27 additions & 1 deletion app/assets/stylesheets/application.bootstrap.scss
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ $theme-colors: (
"primary": #a130fd,
"secondary": #515253,
"success": #2abd4cde,
"info": #68a1f7,
"info": #8fd0f5,
"warning": #ffc107,
"danger": #dc3545,
"light": rgba(255, 251, 251, 0.603),
Expand Down Expand Up @@ -98,3 +98,29 @@ input[type="checkbox"]:checked {
box-shadow 1s ease-in-out,
background-color 1s ease-in-out;
}

.comment-message, .reply-form{
margin-left: 5.2rem !important;
}

.comment-actions{
margin-left: 5.0rem !important;
}

.reply-content{
margin-left: 4.5rem !important;
}

.reply-form{
min-width: 350px;
}

.reply-collapser{
margin-left: 4.8rem !important;
color: #065fd4 !important;
font-size: large;
}

.reply-content, .comment-message{
font-size: large;
}
2 changes: 1 addition & 1 deletion app/assets/stylesheets/navbar.scss
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@
}

.dropdown-item:active {
background-color: #9030df !important;
background-color: #9030df !important;
}
18 changes: 11 additions & 7 deletions app/controllers/invitation_requests_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,22 @@ class InvitationRequestsController < ApplicationController
before_action :authenticate_user!, only: %i[index]

def index
invitation_requests = current_user.invitation_requests
@error = false
@invitation_request_infos = []
return if current_user.subscription.inactive?

begin
@invitation_request_infos = InvitationRequestService::InvitationRequest.send(invitation_requests)
rescue StandardError
return @error = true
end
@error = false
request_data

return @invitation_request_infos if params[:filter].blank?

@invitation_request_infos.filter! { |request| request.status == params[:filter] }
end

private

def request_data
@invitation_request_infos = InvitationRequestService::InvitationRequest.send(current_user.invitation_requests)
rescue StandardError
@error = true
end
end
8 changes: 7 additions & 1 deletion app/controllers/posts_controller.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
class PostsController < ApplicationController
before_action :authenticate_user!, only: %w[new create edit pin]
before_action :set_post, only: %w[show edit update pin]
before_action :set_post, only: %w[show edit update pin publish]
before_action :authorize!, only: %w[edit update pin]
before_action :blocks_update, only: %w[update]
before_action :redirect_if_removed_content, only: %w[show edit update pin]
Expand Down Expand Up @@ -29,6 +29,7 @@ def show
@comment = Comment.new
@likes_count = @post.likes.count
@liked = Like.find_by(user: current_user, likeable: @post)
@reply = Reply.new
end

def edit; end
Expand All @@ -52,6 +53,11 @@ def pin
end
end

def publish
@post.published!
redirect_to post_path(@post), notice: t('.success')
end

private

def post_params
Expand Down
8 changes: 8 additions & 0 deletions app/controllers/projects_controller.rb
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
class ProjectsController < ApplicationController
before_action :authenticate_user!
before_action :authenticate_subscriber, only: :create_invitation_request

def index
@invitation_request = current_user.invitation_requests.build
@invitation_requests = current_user.invitation_requests.pluck(:project_id).to_json
@invitation_requests_projects_ids = current_user.invitation_requests.pluck(:project_id)
@free_user = current_user.subscription.inactive?
end

def create_invitation_request
Expand All @@ -19,6 +21,12 @@ def create_invitation_request

private

def authenticate_subscriber
return if current_user.subscription.active?

redirect_to root_path, alert: t('alerts.unauthorized')
end

def invitation_request_params
invitation_request_params = params.require(:invitation_request).permit(:message)
invitation_request_params['project_id'] = params['project_id']
Expand Down
12 changes: 12 additions & 0 deletions app/controllers/replies/likes_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
module Replies
class LikesController < LikesController
before_action :set_likeable

private

def set_likeable
@likeable = Reply.find(params[:reply_id])
@post = @likeable.comment.post
end
end
end
21 changes: 21 additions & 0 deletions app/controllers/replies_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
class RepliesController < ApplicationController
before_action :authenticate_user!
def create
comment = Comment.find(params[:comment_id])
@reply = comment.replies.build(reply_params)

if @reply.save
redirect_to post_path(comment.post), notice: t('.success')
else
redirect_to post_path(comment.post), alert: t('.error')
end
end

private

def reply_params
reply_params = params.require(:reply).permit(:message)
reply_params[:user_id] = current_user.id
reply_params
end
end
9 changes: 6 additions & 3 deletions app/controllers/reports_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ def set_reportable_for_new
@reportable = Post.find(reportable_id) if params[:reportable_type] == 'Post'
@reportable = Profile.find(reportable_id) if params[:reportable_type] == 'Profile'
@reportable = Comment.find(reportable_id) if params[:reportable_type] == 'Comment'
@reportable = Reply.find(reportable_id) if params[:reportable_type] == 'Reply'
end

def set_reportable_for_create
Expand Down Expand Up @@ -91,9 +92,11 @@ def authorize!
end

def redirect_if_self_report
return if @reportable.is_a?(Profile) && @reportable != current_user.profile
return if @reportable.is_a?(Comment) && @reportable.user != current_user
return if @reportable.is_a?(Post) && @reportable.user != current_user
reportable_classes = [Profile, Comment, Post, Reply]

return if reportable_classes.any? do |klass|
@reportable.is_a?(klass) && @reportable.user != current_user
end

redirect_to root_path, alert: t('.self_report')
end
Expand Down
13 changes: 13 additions & 0 deletions app/controllers/subscriptions_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
class SubscriptionsController < ApplicationController
before_action :authenticate_user!

def index
@subscription = current_user.subscription
end

def update
@subscription = Subscription.find params[:id]
@subscription.active!
redirect_to subscriptions_path, notice: t('.success')
end
end
31 changes: 17 additions & 14 deletions app/javascript/components/projects_vue.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export default {
showingForm: false,
currentProjectId: null,
invitationRequestsProjectsIds: window.invitationRequestsProjectsIds,
freeUser: window.freeUser,
errorMsg: false,
}
},
Expand Down Expand Up @@ -44,21 +45,23 @@ export default {
},

async created() {
try {
let response = await fetch('/api/v1/projects', { signal });
if (response.ok) {
let data = await response.json();
if (!data.message) {
this.projects = data;
if (!freeUser) {
try {
let response = await fetch('/api/v1/projects', { signal });
if (response.ok) {
let data = await response.json();
if (!data.message) {
this.projects = data;
}
} else {
this.errorMsg = true;
}
} catch (error) {
if (error.name == 'AbortError') {
console.log('Requisição abortada');
} else {
this.errorMsg = true;
}
} else {
this.errorMsg = true;
}
} catch (error) {
if (error.name == 'AbortError') {
console.log('Requisição abortada');
} else {
this.errorMsg = true;
}
}
}
Expand Down
3 changes: 2 additions & 1 deletion app/jobs/post_scheduler_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ class PostSchedulerJob < ApplicationJob
queue_as :default

def perform(post)
return if post.published?

post.published!
post.update(published_at: Time.zone.now)
end
end
1 change: 1 addition & 0 deletions app/models/comment.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ class Comment < ApplicationRecord
belongs_to :post
belongs_to :user
has_many :likes, as: :likeable, dependent: :destroy
has_many :replies, dependent: :destroy
has_many :reports, as: :reportable, dependent: :destroy
has_many :notifications, as: :notifiable, dependent: :destroy

Expand Down
5 changes: 5 additions & 0 deletions app/models/post.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,11 @@ def first_image_attached
end
end

def published!
super
update(published_at: Time.current)
end

private

def create_notification_to_followers
Expand Down
6 changes: 6 additions & 0 deletions app/models/reply.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
class Reply < ApplicationRecord
belongs_to :user
belongs_to :comment
has_many :likes, as: :likeable, dependent: :destroy
validates :message, presence: true
end
1 change: 1 addition & 0 deletions app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ class User < ApplicationRecord
has_one :subscription, dependent: :destroy
has_many :posts, dependent: :nullify
has_many :likes, dependent: :destroy
has_many :replies, dependent: :destroy
has_many :comments, dependent: :nullify
has_one :personal_info, through: :profile
has_many :professional_infos, through: :profile
Expand Down
4 changes: 2 additions & 2 deletions app/views/home/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
<aside class="col-md-3">
<h2> <%= t('.most_followed') %> </h2>

<div class="py-2" style="width: 18rem;">
<div style="width: 18rem;">
<% @most_followed.each do |profile| %>
<div class="card mb-3 bg-light-subtle text-center">
<div class="card-body">
Expand All @@ -47,7 +47,7 @@
<%= t('.find_connect_shine') %> <br>
<span> <%= t('.your_profile_your_space') %> </span><br>
<span class="text-primary fw-bold py-3"><%= t('.become_part_of_comunity') %></span> <br>
<%= link_to t('.create_account'), new_user_registration_path, class: 'btn btn-primary col-10 py-2 my-4 fs-4' %>
<%= link_to t('.create_account_btn'), new_user_registration_path, class: 'btn btn-primary col-10 py-2 my-4 fs-4' %>
</h3>
</div>
</div>
Expand Down
Loading

0 comments on commit a47964c

Please sign in to comment.