Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
dbd0179
added React frontend
sheenasany Sep 12, 2022
d54cacc
added models
sheenasany Sep 12, 2022
223152c
migrations completed
Ghostskwad Sep 13, 2022
96268a4
Merge pull request #1 from sheenasany/create
Ghostskwad Sep 13, 2022
900d7da
model relations created
Ghostskwad Sep 13, 2022
d07d247
schema changes
Ghostskwad Sep 13, 2022
a3ea7b8
Merge pull request #2 from sheenasany/seed_changes
Ghostskwad Sep 13, 2022
1243324
seeds data
sheenasany Sep 13, 2022
60679a4
initial commit, routing
jackB651 Sep 13, 2022
7df42be
all dem brooke magic routes
sheenasany Sep 13, 2022
0305a8f
updated user patch request
sheenasany Sep 13, 2022
565ec36
seeds
jackB651 Sep 13, 2022
3589f80
fix
jackB651 Sep 13, 2022
5bf095e
added destroy
Ghostskwad Sep 13, 2022
ee71e70
added new column for images and data on Template class
sheenasany Sep 14, 2022
800d27f
updated React and removed routes for single page fre front end
sheenasany Sep 14, 2022
458bcbe
react components fixed
Ghostskwad Sep 15, 2022
70d8358
react components fixed
Ghostskwad Sep 15, 2022
d50bbae
all the bug fixes
Ghostskwad Sep 15, 2022
77c98fc
killed the bugs
Ghostskwad Sep 15, 2022
8bd2981
Merge pull request #3 from sheenasany/playground
Ghostskwad Sep 15, 2022
383aedb
Css
jackB651 Sep 15, 2022
5248f50
Merge pull request #4 from sheenasany/J-Css
Ghostskwad Sep 15, 2022
5fff5ad
patch request
sheenasany Sep 15, 2022
86b3c3c
Merge branch 'main' into sheenaPatch2
Ghostskwad Sep 15, 2022
3eb3736
Merge pull request #5 from sheenasany/sheenaPatch2
Ghostskwad Sep 15, 2022
edac02e
fixed stuff
Ghostskwad Sep 15, 2022
a67b007
fixed stuff
Ghostskwad Sep 15, 2022
1550310
fixed the frustration
Ghostskwad Sep 15, 2022
4cbf7aa
fixed the frustration
Ghostskwad Sep 15, 2022
3dd43f8
css fixes
sheenasany Sep 15, 2022
4231cbc
background
jackB651 Sep 15, 2022
e88db97
added new font
sheenasany Sep 16, 2022
b8dab1f
slight additions to css and some cleaning up
sheenasany Sep 16, 2022
18782fb
new button!
sheenasany Sep 16, 2022
25a38fe
refactoring of http requests
Ghostskwad Nov 17, 2022
9c239f9
images not loading bug fixed
Ghostskwad Nov 17, 2022
e1f8c21
minor changes, deleted unncessary files and add dependency array to a…
sheenasany Mar 22, 2023
9ca302e
added new button and changed functionality for creation and selection…
sheenasany Mar 23, 2023
8069b61
added notes and cleaned up code
sheenasany Mar 23, 2023
544e869
cleaned up headings to use one state by adding div
sheenasany Mar 23, 2023
22012e2
testing
sheenasany Mar 23, 2023
4a24787
add sessions and refactoring
Ghostskwad Apr 19, 2024
96bd1ce
add backend sessions and routes
Ghostskwad Apr 19, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ gem "sinatra-activerecord", "~> 2.0"
# https://github.com/ruby/rake
gem "rake", "~> 13.0"

gem 'bcrypt'

# Provides functionality to interact with a SQLite3 database
gem "sqlite3", "~> 1.4"

Expand All @@ -50,3 +52,5 @@ group :test do
gem "rspec", "~> 3.10"
gem "rspec-json_expectations", "~> 2.2"
end

gem 'hirb'
100 changes: 53 additions & 47 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,96 +1,102 @@
GEM
remote: https://rubygems.org/
specs:
activemodel (6.1.4)
activesupport (= 6.1.4)
activerecord (6.1.4)
activemodel (= 6.1.4)
activesupport (= 6.1.4)
activesupport (6.1.4)
activemodel (6.1.7.7)
activesupport (= 6.1.7.7)
activerecord (6.1.7.7)
activemodel (= 6.1.7.7)
activesupport (= 6.1.7.7)
activesupport (6.1.7.7)
concurrent-ruby (~> 1.0, >= 1.0.2)
i18n (>= 1.6, < 2)
minitest (>= 5.1)
tzinfo (~> 2.0)
zeitwerk (~> 2.3)
bcrypt (3.1.20)
coderay (1.1.3)
concurrent-ruby (1.1.9)
daemons (1.4.0)
database_cleaner (2.0.1)
database_cleaner-active_record (~> 2.0.0)
database_cleaner-active_record (2.0.1)
concurrent-ruby (1.2.3)
daemons (1.4.1)
database_cleaner (2.0.2)
database_cleaner-active_record (>= 2, < 3)
database_cleaner-active_record (2.1.0)
activerecord (>= 5.a)
database_cleaner-core (~> 2.0.0)
database_cleaner-core (2.0.1)
diff-lcs (1.4.4)
diff-lcs (1.5.1)
eventmachine (1.2.7)
ffi (1.15.3)
i18n (1.8.10)
ffi (1.16.3)
hirb (0.7.3)
i18n (1.14.4)
concurrent-ruby (~> 1.0)
listen (3.5.1)
listen (3.9.0)
rb-fsevent (~> 0.10, >= 0.10.3)
rb-inotify (~> 0.9, >= 0.9.10)
method_source (1.0.0)
minitest (5.14.4)
mustermann (1.1.1)
method_source (1.1.0)
minitest (5.22.3)
mustermann (2.0.2)
ruby2_keywords (~> 0.0.1)
pry (0.14.1)
pry (0.14.2)
coderay (~> 1.1)
method_source (~> 1.0)
rack (2.2.3)
rack-contrib (2.3.0)
rack (~> 2.0)
rack (2.2.9)
rack-contrib (2.4.0)
rack (< 4)
rack-cors (1.1.1)
rack (>= 2.0.0)
rack-protection (2.1.0)
rack-protection (2.2.4)
rack
rack-test (1.1.0)
rack (>= 1.0, < 3)
rake (13.0.6)
rb-fsevent (0.11.0)
rake (13.2.1)
rb-fsevent (0.11.2)
rb-inotify (0.10.1)
ffi (~> 1.0)
require_all (3.0.0)
rerun (0.13.1)
rerun (0.14.0)
listen (~> 3.0)
rspec (3.10.0)
rspec-core (~> 3.10.0)
rspec-expectations (~> 3.10.0)
rspec-mocks (~> 3.10.0)
rspec-core (3.10.1)
rspec-support (~> 3.10.0)
rspec-expectations (3.10.1)
rspec (3.13.0)
rspec-core (~> 3.13.0)
rspec-expectations (~> 3.13.0)
rspec-mocks (~> 3.13.0)
rspec-core (3.13.0)
rspec-support (~> 3.13.0)
rspec-expectations (3.13.0)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.10.0)
rspec-support (~> 3.13.0)
rspec-json_expectations (2.2.0)
rspec-mocks (3.10.2)
rspec-mocks (3.13.0)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.10.0)
rspec-support (3.10.2)
ruby2_keywords (0.0.4)
sinatra (2.1.0)
mustermann (~> 1.0)
rspec-support (~> 3.13.0)
rspec-support (3.13.1)
ruby2_keywords (0.0.5)
sinatra (2.2.4)
mustermann (~> 2.0)
rack (~> 2.2)
rack-protection (= 2.1.0)
rack-protection (= 2.2.4)
tilt (~> 2.0)
sinatra-activerecord (2.0.23)
sinatra-activerecord (2.0.27)
activerecord (>= 4.1)
sinatra (>= 1.0)
sqlite3 (1.4.2)
thin (1.8.1)
sqlite3 (1.7.3-x86_64-darwin)
sqlite3 (1.7.3-x86_64-linux)
thin (1.8.2)
daemons (~> 1.0, >= 1.0.9)
eventmachine (~> 1.0, >= 1.0.4)
rack (>= 1, < 3)
tilt (2.0.10)
tzinfo (2.0.4)
tilt (2.3.0)
tzinfo (2.0.6)
concurrent-ruby (~> 1.0)
zeitwerk (2.4.2)
zeitwerk (2.6.13)

PLATFORMS
x86_64-darwin-19
x86_64-linux

DEPENDENCIES
activerecord (~> 6.1)
bcrypt
database_cleaner (~> 2.0)
hirb
pry (~> 0.14.1)
rack-contrib (~> 2.3)
rack-cors (~> 1.1)
Expand Down
116 changes: 114 additions & 2 deletions app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,121 @@
class ApplicationController < Sinatra::Base
set :default_content_type, 'application/json'
require 'pry'

enable :sessions
set :session_secret, 'production_secret'

# Add your routes here
get "/" do
{ message: "Good luck with your project!" }.to_json
post '/signup' do
if session[:user_id]
status 403
return { success: false, message: "You already have an account." }.to_json
end

user = User.new(username: params[:username].downcase, password: params[:password])

if user.save
session[:user_id] = user.id \
user = User.find_by(id: session[:user_id])
user.to_json except: :password_digest, include: :characters
else
status 422
{ success: false, message: "Unable to create user." }.to_json
end
end

post '/login' do
if session[:user_id]
status 403
{ success: false, message: "A user is already logged in." }.to_json
elsif (user = User.find_by(username: params[:username])) && user.authenticate(params[:password])
session[:user_id] = user.id
user = User.find_by(id: session[:user_id])
user.to_json except: :password_digest, include: :characters
else
status 401
{ success: false, message: "Invalid username or password." }.to_json
end
end

delete '/logout' do
session.clear

{ success: true, message: "Logged out successfully." }.to_json
end

get '/characters' do
# Check if a user is logged in by checking if session[:user_id] exists
if session[:user_id]
# Find the user in the database
user = User.find(session[:user_id])

# Access the characters associated with the user
characters = user.characters

# Convert the characters to JSON and return
characters.to_json
else
# If no user is logged in, return an error message
status 403
{ error: "User not logged in" }.to_json
end
end

get "/characters" do
character = Character.all
character.to_json
end

post "/characters" do
temp_id = Template.all.where(class_name: params[:class_name]).pluck(:id).sample
new_character = Character.create(name: params[:name], history: params[:history], user_id: params[:user_id], template_id: temp_id)
new_character.to_json
end

delete "/characters/:id" do
delete_character = Character.find_by(id: params[:id])
delete_character.destroy
delete_character.to_json
end

patch "/characters/:id" do
update_character = Character.find_by(id: params[:id])
update_character.update(name: params[:name], history: params[:history])
update_character.to_json
end

get "/templates" do
template = Template.all
template.to_json
end

get "/templates/class_name" do
class_name = Template.all.pluck(:class_name).uniq
class_name.to_json
end

get "/templates/:id" do
template_id = Template.find_by(id: params[:id])
template_id.to_json
end

get '/me' do
user = User.find_by(id: session[:user_id])

if user
user.to_json except: :password_digest, include: :characters
else
status 401
{ error: "Please login." }.to_json
end
end
end



# PRIVATE

# def character_params
# {name: params[:name], history: params[:history], user_id: params[:user_id], template_id: params[:template_id]}
# end
Empty file removed app/models/.gitkeep
Empty file.
9 changes: 9 additions & 0 deletions app/models/character.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
class Character < ActiveRecord::Base
belongs_to :user
belongs_to :template

def create_new_character(name, history, character_class)
Character.create(name: name, history: history, user_id: user.id, template_id: Template.all.where(character_class: character_class).pluck(:id).sample)
end

end
5 changes: 5 additions & 0 deletions app/models/template.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class Template < ActiveRecord::Base
has_many :characters
has_many :users, through: :characters

end
11 changes: 11 additions & 0 deletions app/models/user.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
require 'bcrypt'

class User < ActiveRecord::Base
has_secure_password

has_many :characters
has_many :templates, through: :characters

validates :username, presence: true, uniqueness: { case_sensitive: false }
validates :password_digest, presence: true
end
8 changes: 8 additions & 0 deletions db/migrate/20220912210535_create_users.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
class CreateUsers < ActiveRecord::Migration[6.1]
def change
create_table :users do |t|
t.string :username
t.string :password_digest
end
end
end
10 changes: 10 additions & 0 deletions db/migrate/20220912210543_create_characters.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
class CreateCharacters < ActiveRecord::Migration[6.1]
def change
create_table :characters do |t|
t.string :name
t.text :history
t.integer :user_id
t.integer :template_id
end
end
end
21 changes: 21 additions & 0 deletions db/migrate/20220912210555_create_templates.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
class CreateTemplates < ActiveRecord::Migration[6.1]
def change
create_table :templates do |t|
t.integer :level
t.string :class_name
t.string :race
t.integer :strength
t.integer :dexterity
t.integer :constitution
t.integer :intelligence
t.integer :wisdom
t.integer :charisma
t.string :spell1
t.string :spell2
t.string :ability1
t.string :ability2
t.string :weapon1
t.string :weapon2
end
end
end
5 changes: 5 additions & 0 deletions db/migrate/20220914015710_add_image_column.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class AddImageColumn < ActiveRecord::Migration[6.1]
def change
add_column :templates, :img_url, :string
end
end
Loading