-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #65 from ES2-UFPI/Gabriel
Gabriel
- Loading branch information
Showing
48 changed files
with
868 additions
and
409 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
class AdminController < ApplicationController | ||
before_action :authenticate_user! | ||
before_action :check_admin | ||
|
||
def index | ||
@games = Game.all | ||
@platforms = Platform.all | ||
@developers = Developer.all | ||
@publishers = Publisher.all | ||
@genres = Genre.all | ||
end | ||
|
||
def check_admin | ||
redirect_to root_path, alert: "Acesso negado!" unless current_user.is_admin? | ||
end | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,9 @@ | ||
class PagesController < ApplicationController | ||
def home | ||
end | ||
end | ||
class PagesController < ApplicationController | ||
|
||
def home | ||
if current_user | ||
@recommended_games = current_user.recommended_games | ||
end | ||
end | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,35 +1,37 @@ | ||
class ReviewsController < ApplicationController | ||
before_action :authenticate_user! | ||
|
||
def create | ||
@game = Game.find(params[:game_id]) | ||
@review = @game.reviews.new(review_params) | ||
@review.user = current_user | ||
@review.posted_at = Time.now | ||
|
||
if @review.save | ||
@game.update_attribute(:rate_game, @game.calculate_average_rating) | ||
redirect_to game_path(@game), notice: "Review enviada com sucesso!" | ||
else | ||
redirect_to game_path(@game), alert: "Não foi possível enviar a review." | ||
end | ||
end | ||
|
||
def destroy | ||
@review = Review.find(params[:id]) | ||
|
||
if @review.user_id == current_user.id | ||
@review.destroy | ||
redirect_to game_path(@review.game_id), notice: "Review excluída com sucesso!" | ||
else | ||
redirect_to game_path(@review.game_id), alert: "Você não tem permissão para excluir esta review." | ||
end | ||
end | ||
|
||
private | ||
|
||
def review_params | ||
params.require(:review).permit(:content, :score, :user_id) | ||
end | ||
|
||
end | ||
class ReviewsController < ApplicationController | ||
before_action :authenticate_user! | ||
|
||
def create | ||
@game = Game.find(params[:game_id]) | ||
@review = @game.reviews.build(review_params) | ||
@review.user = current_user | ||
@review.posted_at = Time.current | ||
|
||
if @review.save | ||
@game.update(rate_game: @game.calculate_average_rating) | ||
redirect_to game_path(@game), notice: "Review enviada com sucesso!" | ||
else | ||
redirect_to game_path(@game), alert: "Não foi possível enviar a review." | ||
end | ||
end | ||
|
||
def destroy | ||
@review = Review.find(params[:id]) | ||
|
||
if @review.user_id == current_user.id | ||
@review.destroy | ||
game = @review.game | ||
game.update(rate_game: game.calculate_average_rating) | ||
redirect_to game_path(game), notice: "Review excluída com sucesso!" | ||
else | ||
redirect_to game_path(@review.game_id), alert: "Você não tem permissão para excluir esta review." | ||
end | ||
end | ||
|
||
private | ||
|
||
def review_params | ||
params.require(:review).permit(:content, :score, :user_id) | ||
end | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
class UserGamesController < ApplicationController | ||
before_action :authenticate_user! | ||
|
||
def index | ||
@user = User.find(params[:user_id]) | ||
@user_games = @user.user_games | ||
@played_games = @user_games.played | ||
@in_progress_games = @user_games.playing | ||
@unfinished = @user_games.unfinished | ||
end | ||
|
||
def edit | ||
@user = current_user | ||
@user_games = @user.user_games | ||
@played_games = @user_games.played | ||
@in_progress_games = @user_games.playing | ||
@unfinished = @user_games.unfinished | ||
end | ||
|
||
def create | ||
@game = Game.find(params[:game_id]) | ||
@user_game = current_user.user_games.build(user_game_params) | ||
@user_game.game = @game | ||
|
||
if @user_game.save | ||
redirect_to @game, notice: "Jogo adicionado à biblioteca." | ||
else | ||
render 'games/show' | ||
end | ||
end | ||
|
||
def update | ||
user_id = params[:user_id] | ||
user_games_params = params[:user_game] | ||
|
||
user_games_params.each do |id, attrs| | ||
user_game = UserGame.find(id) | ||
user_game.update(status: attrs[:status]) | ||
end | ||
|
||
redirect_to user_library_path(user_id) | ||
end | ||
|
||
private | ||
|
||
def user_game_params | ||
params.require(:user_game).permit(:status) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
module AdminHelper | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
module UserGamesHelper | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
module WishlistHelper | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
class UserGame < ApplicationRecord | ||
validates :user, :game, presence: true | ||
validates :game_id, uniqueness: { scope: :user_id } | ||
belongs_to :user | ||
belongs_to :game | ||
enum status: [:played, :playing, :unfinished] | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
class Wishlist < ApplicationRecord | ||
belongs_to :user | ||
belongs_to :game | ||
end |
Oops, something went wrong.