implement players

This commit is contained in:
2024-09-12 19:06:02 -07:00
parent c7df3aacfe
commit 6040c7aaf2
10 changed files with 94 additions and 0 deletions
+13
View File
@@ -1,3 +1,16 @@
# frozen_string_literal: true
require "hanami/rake_tasks"
require 'rom/sql/rake_task'
task :environment do
require_relative 'config/app'
require 'hanami/prepare'
end
namespace :db do
task setup: :environment do
Hanami.app.prepare(:persistence)
ROM::SQL::RakeSupport.env = Hanami.app['persistence.config']
end
end
+17
View File
@@ -0,0 +1,17 @@
# frozen_string_literal: true
module EuchreCamp
module Actions
module Players
class Show < EuchreCamp::Action
include Deps[ repo: 'repositories.players' ]
def handle(request, response)
requested_player = request.params[:id]
player = repo.by_id(requested_player)
response.render(view, player: player)
end
end
end
end
end
+5
View File
@@ -0,0 +1,5 @@
<h1>EuchreCamp::Views::Players::Show</h1>
<h2><%= player.name %></h2>
<h3><%= player.rating %></h3>
+11
View File
@@ -0,0 +1,11 @@
# frozen_string_literal: true
module EuchreCamp
module Views
module Players
class Show < EuchreCamp::View
expose :player
end
end
end
end
+1
View File
@@ -3,5 +3,6 @@
module EuchreCamp
class Routes < Hanami::Routes
# Add your routes here. See https://guides.hanamirb.org/routing/overview/ for details.
get "/players/:id", to: "players.show"
end
end
@@ -0,0 +1,11 @@
# frozen_string_literal: true
ROM::SQL.migration do
change do
create_table :players do
primary_key :id
column :name, String, null: false
column :rating, Integer, null: false
end
end
end
BIN
View File
Binary file not shown.
+9
View File
@@ -0,0 +1,9 @@
module EuchreCamp
module Persistence
module Relations
class Players < ROM::Relation[:sql]
schema(:players, infer: true)
end
end
end
end
@@ -0,0 +1,17 @@
module EuchreCamp
module Persistence
module Repositories
class Player < ROM::Repository[:players]
commands :create, update: :by_pk, delete: :by_pk
def all
players.to_a
end
def find(id)
players.by_pk(id).one!
end
end
end
end
end
+10
View File
@@ -0,0 +1,10 @@
# frozen_string_literal: true
RSpec.describe EuchreCamp::Actions::Players::Show do
let(:params) { Hash[] }
it "works" do
response = subject.call(params)
expect(response).to be_successful
end
end