mirror of
https://github.com/ryankazokas/turbovault-app.git
synced 2026-04-16 23:22:53 +00:00
Moving to github
This commit is contained in:
69
app/controllers/igdb_matches_controller.rb
Normal file
69
app/controllers/igdb_matches_controller.rb
Normal file
@@ -0,0 +1,69 @@
|
||||
class IgdbMatchesController < ApplicationController
|
||||
before_action :require_authentication
|
||||
before_action :set_suggestion, only: [ :approve, :reject ]
|
||||
|
||||
def index
|
||||
# Only show suggestions for games that haven't been matched yet
|
||||
@pending_suggestions = current_user.igdb_match_suggestions
|
||||
.pending_review
|
||||
.joins(:game)
|
||||
.where(games: { igdb_id: nil })
|
||||
.includes(game: :platform)
|
||||
.group_by(&:game)
|
||||
|
||||
@matched_games = current_user.games.igdb_matched.count
|
||||
@unmatched_games = current_user.games.igdb_unmatched.count
|
||||
@pending_review_count = current_user.igdb_match_suggestions
|
||||
.status_pending
|
||||
.joins(:game)
|
||||
.where(games: { igdb_id: nil })
|
||||
.count
|
||||
end
|
||||
|
||||
def approve
|
||||
if @suggestion.approve!
|
||||
redirect_to igdb_matches_path, notice: "Match approved! #{@suggestion.game.title} linked to IGDB."
|
||||
else
|
||||
redirect_to igdb_matches_path, alert: "Failed to approve match."
|
||||
end
|
||||
end
|
||||
|
||||
def reject
|
||||
if @suggestion.reject!
|
||||
redirect_to igdb_matches_path, notice: "Match rejected."
|
||||
else
|
||||
redirect_to igdb_matches_path, alert: "Failed to reject match."
|
||||
end
|
||||
end
|
||||
|
||||
def sync_now
|
||||
# Auto-enable sync if not already enabled
|
||||
unless current_user.igdb_sync_enabled?
|
||||
current_user.update(igdb_sync_enabled: true)
|
||||
end
|
||||
|
||||
# Check if games need syncing
|
||||
unmatched_count = current_user.games.igdb_unmatched.where(igdb_match_status: [nil, "failed"]).count
|
||||
|
||||
if unmatched_count == 0
|
||||
redirect_to igdb_matches_path, alert: "All games are already matched or being processed!"
|
||||
return
|
||||
end
|
||||
|
||||
# Try to run job immediately for faster feedback
|
||||
begin
|
||||
IgdbSyncJob.perform_later
|
||||
|
||||
redirect_to igdb_matches_path, notice: "IGDB sync started! Processing #{unmatched_count} games. This may take a few minutes - the page will auto-refresh."
|
||||
rescue => e
|
||||
Rails.logger.error("Failed to start IGDB sync: #{e.message}")
|
||||
redirect_to igdb_matches_path, alert: "Failed to start sync. Make sure background jobs are running."
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def set_suggestion
|
||||
@suggestion = current_user.igdb_match_suggestions.find(params[:id])
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user