Skip to content

Commit

Permalink
Merge branch 'main' into refactor/api-services
Browse files Browse the repository at this point in the history
  • Loading branch information
eliseuramos93 committed Feb 15, 2024
2 parents 4d48a35 + d216962 commit 425990e
Show file tree
Hide file tree
Showing 57 changed files with 936 additions and 151 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;
}
4 changes: 2 additions & 2 deletions app/controllers/api/v1/profiles_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ module V1
class ProfilesController < ApiController
def index
if params[:search].blank?
profiles = Profile.active.open_to_work
profiles = Profile.active.open_to_work.order_by_premium
profiles = profiles.map { |profile| format_profile(profile) }
else
profiles = Profile.active.open_to_work.get_profile_job_categories_json(params[:search])
profiles = Profile.active.open_to_work.order_by_premium.get_profile_job_categories_json(params[:search])
end
render status: :ok, json: { data: profiles }
end
Expand Down
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,11 +1,13 @@
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)
@projects_url = Rails.configuration.portfoliorrr_api_v1.projects_url
@free_user = current_user.subscription.inactive?
end

def create_invitation_request
Expand All @@ -20,6 +22,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,
portfoliorrrProjectsApiUrl: window.portfoliorrrProjectsApiUrl,
}
Expand Down Expand Up @@ -45,21 +46,23 @@ export default {
},

async created() {
try {
let response = await fetch(this.portfoliorrrProjectsApiUrl, { signal });
if (response.ok) {
let data = await response.json();
if (!data.message) {
this.projects = data;
if (!freeUser) {
try {
let response = await fetch(this.portfoliorrrProjectsApiUrl, { 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
32 changes: 18 additions & 14 deletions app/models/profile.rb
Original file line number Diff line number Diff line change
@@ -1,30 +1,30 @@
class Profile < ApplicationRecord
belongs_to :user

has_one_attached :photo
has_one :personal_info, dependent: :destroy

has_many :professional_infos, dependent: :destroy
has_many :education_infos, dependent: :destroy
has_many :profile_job_categories, dependent: :destroy

has_many :followers, class_name: 'Connection', foreign_key: :followed_profile_id, dependent: :destroy,
inverse_of: :follower

has_many :followed_profiles, class_name: 'Connection', foreign_key: :follower_id,
dependent: :destroy, inverse_of: :followed_profile

has_many :connections, foreign_key: :followed_profile_id, dependent: :destroy, inverse_of: :followed_profile

has_many :job_categories, through: :profile_job_categories
has_many :invitations, dependent: :destroy
has_many :notifications, dependent: :destroy
has_many :invitation_requests, dependent: :destroy

has_one_attached :photo
has_many :invitations, dependent: :destroy
has_many :posts, through: :user
has_many :notifications, dependent: :destroy
has_many :job_categories, through: :profile_job_categories

has_many :reports_submitted, class_name: 'Report', dependent: :destroy

has_many :reports_received, class_name: 'Report', as: :reportable, dependent: :destroy

has_many :connections, foreign_key: :followed_profile_id, dependent: :destroy, inverse_of: :followed_profile

has_many :followers, class_name: 'Connection', foreign_key: :followed_profile_id, dependent: :destroy,
inverse_of: :follower

has_many :followed_profiles, class_name: 'Connection', foreign_key: :follower_id, dependent: :destroy,
inverse_of: :followed_profile

accepts_nested_attributes_for :personal_info
accepts_nested_attributes_for :professional_infos
accepts_nested_attributes_for :education_infos
Expand All @@ -40,6 +40,10 @@ class Profile < ApplicationRecord

delegate :full_name, :email, to: :user

def self.order_by_premium
joins(user: :subscription).order('subscriptions.status DESC, users.full_name ASC')
end

def self.advanced_search(search_query)
left_outer_joins(:job_categories, :personal_info, :user).where(
'job_categories.name LIKE :term OR
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
Loading

0 comments on commit 425990e

Please sign in to comment.