mirror of
https://github.com/ryankazokas/turbovault-app.git
synced 2026-04-17 01:42:53 +00:00
Adds types
This commit is contained in:
@@ -1,20 +1,27 @@
|
||||
# typed: true
|
||||
|
||||
class CollectionsController < ApplicationController
|
||||
extend T::Sig
|
||||
before_action :require_authentication
|
||||
before_action :set_collection, only: [ :show, :edit, :update, :destroy, :games ]
|
||||
|
||||
sig { void }
|
||||
def index
|
||||
@root_collections = current_user.collections.root_collections.order(:name)
|
||||
end
|
||||
|
||||
sig { void }
|
||||
def show
|
||||
@games = @collection.games.includes(:platform, :genres).page(params[:page]).per(25)
|
||||
end
|
||||
|
||||
sig { void }
|
||||
def new
|
||||
@collection = current_user.collections.build
|
||||
@collections = current_user.collections.root_collections.order(:name)
|
||||
end
|
||||
|
||||
sig { void }
|
||||
def create
|
||||
@collection = current_user.collections.build(collection_params)
|
||||
|
||||
@@ -26,10 +33,12 @@ class CollectionsController < ApplicationController
|
||||
end
|
||||
end
|
||||
|
||||
sig { void }
|
||||
def edit
|
||||
@collections = current_user.collections.root_collections.where.not(id: @collection.id).order(:name)
|
||||
end
|
||||
|
||||
sig { void }
|
||||
def update
|
||||
if @collection.update(collection_params)
|
||||
redirect_to @collection, notice: "Collection was successfully updated."
|
||||
@@ -39,11 +48,13 @@ class CollectionsController < ApplicationController
|
||||
end
|
||||
end
|
||||
|
||||
sig { void }
|
||||
def destroy
|
||||
@collection.destroy
|
||||
redirect_to collections_path, notice: "Collection was successfully deleted."
|
||||
end
|
||||
|
||||
sig { void }
|
||||
def games
|
||||
# Same as show, but maybe with different view
|
||||
@games = @collection.games.includes(:platform, :genres).page(params[:page]).per(25)
|
||||
@@ -52,10 +63,12 @@ class CollectionsController < ApplicationController
|
||||
|
||||
private
|
||||
|
||||
sig { void }
|
||||
def set_collection
|
||||
@collection = current_user.collections.find(params[:id])
|
||||
end
|
||||
|
||||
sig { returns(T.untyped) }
|
||||
def collection_params
|
||||
permitted = params.require(:collection).permit(:name, :description, :parent_collection_id)
|
||||
# Convert empty string to nil for parent_collection_id
|
||||
|
||||
Reference in New Issue
Block a user