Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
70 changes: 35 additions & 35 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,50 +1,50 @@
GEM
remote: https://rubygems.org/
specs:
activemodel (6.0.3.1)
activesupport (= 6.0.3.1)
activerecord (6.0.3.1)
activemodel (= 6.0.3.1)
activesupport (= 6.0.3.1)
activesupport (6.0.3.1)
activemodel (6.1.3)
activesupport (= 6.1.3)
activerecord (6.1.3)
activemodel (= 6.1.3)
activesupport (= 6.1.3)
activesupport (6.1.3)
concurrent-ruby (~> 1.0, >= 1.0.2)
i18n (>= 0.7, < 2)
minitest (~> 5.1)
tzinfo (~> 1.1)
zeitwerk (~> 2.2, >= 2.2.2)
coderay (1.1.1)
concurrent-ruby (1.1.6)
i18n (1.8.2)
i18n (>= 1.6, < 2)
minitest (>= 5.1)
tzinfo (~> 2.0)
zeitwerk (~> 2.3)
coderay (1.1.3)
concurrent-ruby (1.1.8)
i18n (1.8.9)
concurrent-ruby (~> 1.0)
method_source (0.8.2)
minitest (5.14.1)
mustermann (1.0.3)
pry (0.10.4)
coderay (~> 1.1.0)
method_source (~> 0.8.1)
slop (~> 3.4)
method_source (1.0.0)
minitest (5.14.4)
mustermann (1.1.1)
ruby2_keywords (~> 0.0.1)
pry (0.14.0)
coderay (~> 1.1)
method_source (~> 1.0)
rack (2.2.3)
rack-protection (2.0.7)
rack-protection (2.1.0)
rack
require_all (1.3.3)
sinatra (2.0.7)
require_all (3.0.0)
ruby2_keywords (0.0.4)
sinatra (2.1.0)
mustermann (~> 1.0)
rack (~> 2.0)
rack-protection (= 2.0.7)
rack (~> 2.2)
rack-protection (= 2.1.0)
tilt (~> 2.0)
sinatra-activerecord (2.0.12)
activerecord (>= 3.2)
sinatra-activerecord (2.0.22)
activerecord (>= 4.1)
sinatra (>= 1.0)
slop (3.6.0)
sqlite3 (1.3.13)
thread_safe (0.3.6)
sqlite3 (1.4.2)
tilt (2.0.10)
tzinfo (1.2.7)
thread_safe (~> 0.1)
zeitwerk (2.3.0)
tzinfo (2.0.4)
concurrent-ruby (~> 1.0)
zeitwerk (2.4.2)

PLATFORMS
ruby
x86_64-darwin-20
x86_64-linux

DEPENDENCIES
pry
Expand All @@ -53,4 +53,4 @@ DEPENDENCIES
sqlite3

BUNDLED WITH
1.14.6
2.2.11
10 changes: 9 additions & 1 deletion Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,14 @@ require 'sinatra/activerecord/rake'

desc 'starts a console'
task :console do
ActiveRecord::Base.logger = Logger.new(STDOUT)
#Enables logging in Pry console whenever ActiveRecord writes SQL for us
#ActiveRecord::Base.logger = Logger.new(STDOUT)
#Above outputs SQL
#Open Pry console, similar to binding.pry.
Pry.start
end


task :start do
Interface.welcome
end
File renamed without changes.
29 changes: 29 additions & 0 deletions app/models/interface.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
class Interface

# attr_accessor :student

def self.welcome
puts "Welcome to Full Stack Tutoring!"
login_or_register
end

def self.login_or_register
puts "Login or Register"
answer = STDIN.gets.chomp
if answer == "login"
@student = Student.login
elsif answer == "register"
@student = Student.register
else
puts "We make all choices...that was a bad one."
end
if @student
Lesson.start(@student)
elsif
Interface.welcome
end
end

end


99 changes: 99 additions & 0 deletions app/models/lesson.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
class Lesson < ActiveRecord::Base
belongs_to :student
belongs_to :tutor

def self.start(student)
puts "Main Menu"
puts "1. Schedule lesson"
puts "2. View past lessons"
puts "3. View scheduled lessons"
answer = STDIN.gets.chomp
if answer == "1"
schedule_lesson(student)
elsif answer == "2"
past_lessons(student)
elsif answer == "3"
scheduled_lessons(student)
else
puts "Try again"
end
end

def self.schedule_lesson(student)
puts "What would you like to learn?"
#Puts giving list of subject options
answer = STDIN.gets.chomp
puts "When would you like to have your lesson?"
date = STDIN.gets.chomp
puts "Who would you like to learn with?"
tutors = Tutor.where(subject: answer)

if tutors.exists?
tutors.each do |tutor|
puts "#{tutor.id}. #{tutor.name}"
end
end

tutor_number = STDIN.gets.chomp
tutor = Tutor.find_by(id: tutor_number)
Lesson.create(topic: answer, date: date, student: student, tutor: tutor)
puts "Your lesson has been scheduled."

Interface.welcome
end

def self.past_lessons(student)
lessons = student.lessons.where("date < ?", Time.current)
if lessons.exists?
lessons.each do |lesson|
puts "#{student.username} had a #{lesson.topic} lesson on #{lesson.date}."
end
end
Interface.welcome
end

def self.scheduled_lessons(student)
puts "Pick a lesson to reschedule or cancel."
lessons = student.lessons.where("date > ?", Time.current)
if lessons.exists?
lessons.each do |lesson|
puts "#{lesson.id}. #{student.username} has a #{lesson.topic} lesson on #{lesson.date}." # #{lesson.id}. with #{lesson.tutor.name}
end
lesson_id = STDIN.gets.chomp
lesson = Lesson.find_by(id: lesson_id)
puts "1. Reschedule"
puts "2. Cancel"
student_choice = STDIN.gets.chomp
if student_choice == "1"
puts "Pick a lesson to reschedule."
reschedule_lesson(lesson)
elsif student_choice == "2"
puts "Pick a lesson to cancel."
cancel_lesson(lesson)
end
end
end

def self.reschedule_lesson(lesson)
puts "When would you like to reschedule your lesson?"
lesson_reschedule = STDIN.gets.chomp
lesson.update(date: lesson_reschedule)
puts "Your lesson has been rescheduled!"
Interface.welcome
end

def self.cancel_lesson(lesson)
lesson.destroy
puts "Your lesson has been cancelled."
Interface.welcome
end

def display_nicely
puts "#You had a #{topic} lesson on #{date} with #{tutor.name}"
end
end


# user_option = STDIN.gets.chomp
# if user_option == "yes"
# Lesson.start(@student)
36 changes: 36 additions & 0 deletions app/models/student.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@

class Student < ActiveRecord::Base
has_many :lessons
has_many :tutors, through: :lessons


def self.login
puts "Enter Username"
username = STDIN.gets.chomp
puts "Enter Password"
password = STDIN.gets.chomp

Student.find_by(username: username, password: password)
#Search db for entered username and password
#find a way to check validity of username and password
end




def self.register
puts "Create Username"
username = STDIN.gets.chomp
puts "Create Password"
password = STDIN.gets.chomp

Student.create(username: username, password: password)
# Allow new user to create username and password.
# Return to login method once user info is established.
end



end


14 changes: 14 additions & 0 deletions app/models/tutor.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
class Tutor < ActiveRecord::Base

has_many :lessons
has_many :students, through: :lessons



# def initialize (name, subject)
# @name = name
# @subject = subject
# end


end
4 changes: 3 additions & 1 deletion config/environment.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
require 'bundler'
Bundler.require


ActiveRecord::Base.establish_connection(adapter: 'sqlite3', database: 'db/development.db')
require_all 'lib'
require_all 'app'

11 changes: 11 additions & 0 deletions db/migrate/20210309224650_create_students.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
class CreateStudents < ActiveRecord::Migration[6.1]
def change
create_table :students do |t|
t.string :name
t.string :subject
t.string :username
t.string :password
t.timestamps
end
end
end
9 changes: 9 additions & 0 deletions db/migrate/20210309224919_create_tutors.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
class CreateTutors < ActiveRecord::Migration[6.1]
def change
create_table :tutors do |t|
t.string :name
t.string :subject
t.timestamps
end
end
end
11 changes: 11 additions & 0 deletions db/migrate/20210309225016_create_lessons.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
class CreateLessons < ActiveRecord::Migration[6.1]
def change
create_table :lessons do |t|
t.string :topic
t.string :date
t.references :student
t.references :tutor
t.timestamps
end
end
end
5 changes: 5 additions & 0 deletions db/migrate/20210310225540_change_date_on_lessons.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class ChangeDateOnLessons < ActiveRecord::Migration[6.1]
def change
change_column :lessons, :date, :datetime
end
end
42 changes: 42 additions & 0 deletions db/schema.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# This file is auto-generated from the current state of the database. Instead
# of editing this file, please use the migrations feature of Active Record to
# incrementally modify your database, and then regenerate this schema definition.
#
# This file is the source Rails uses to define your schema when running `bin/rails
# db:schema:load`. When creating a new database, `bin/rails db:schema:load` tends to
# be faster and is potentially less error prone than running all of your
# migrations from scratch. Old migrations may fail to apply correctly if those
# migrations use external dependencies or application code.
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema.define(version: 2021_03_10_225540) do

create_table "lessons", force: :cascade do |t|
t.string "topic"
t.datetime "date"
t.integer "student_id"
t.integer "tutor_id"
t.datetime "created_at", precision: 6, null: false
t.datetime "updated_at", precision: 6, null: false
t.index ["student_id"], name: "index_lessons_on_student_id"
t.index ["tutor_id"], name: "index_lessons_on_tutor_id"
end

create_table "students", force: :cascade do |t|
t.string "name"
t.string "subject"
t.string "username"
t.string "password"
t.datetime "created_at", precision: 6, null: false
t.datetime "updated_at", precision: 6, null: false
end

create_table "tutors", force: :cascade do |t|
t.string "name"
t.string "subject"
t.datetime "created_at", precision: 6, null: false
t.datetime "updated_at", precision: 6, null: false
end

end
Loading