From 2ce68e60adbcc7e1f17f326387438dbfe7cc57cf Mon Sep 17 00:00:00 2001 From: Barak Rosner Date: Tue, 9 Mar 2021 10:38:04 -0500 Subject: [PATCH 01/14] update --- Rakefile | 2 ++ db/schema.rb | 32 ++++++++++++++++++++++++++++++ db/seeds.rb | 16 +++++++++++++++ lib/lesson.rb | 15 ++++++++++++++ lib/student.rb | 53 ++++++++++++++++++++++++++++++++++++++++++++++++++ lib/tutor.rb | 12 ++++++++++++ 6 files changed, 130 insertions(+) create mode 100644 db/schema.rb create mode 100644 db/seeds.rb create mode 100644 lib/lesson.rb create mode 100644 lib/student.rb create mode 100644 lib/tutor.rb diff --git a/Rakefile b/Rakefile index 508ef20e..d661ffdc 100644 --- a/Rakefile +++ b/Rakefile @@ -3,6 +3,8 @@ require 'sinatra/activerecord/rake' desc 'starts a console' task :console do + #Enables logging in Pry console whenever ActiveRecord writes SQL for us ActiveRecord::Base.logger = Logger.new(STDOUT) + #Open Pry console, similar to binding.pry. Pry.start end diff --git a/db/schema.rb b/db/schema.rb new file mode 100644 index 00000000..ca896bbc --- /dev/null +++ b/db/schema.rb @@ -0,0 +1,32 @@ +# 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. +# +# Note that this schema.rb definition is the authoritative source for your +# database schema. If you need to create the application database on another +# system, you should be using db:schema:load, not running all the migrations +# from scratch. The latter is a flawed and unsustainable approach (the more migrations +# you'll amass, the slower it'll run and the greater likelihood for issues). +# +# It's strongly recommended that you check this file into your version control system. + + ##ActiveRecord::Schema.define(version: 2021_03_09) do + + + +create_table "students" do |t| + t.string "name" + t.string "subject" +end + +create_table "tutors" do |t| + t.string "name" + t.string "subject" +end + +create_table "lessons" do |t| + t.string "topic" + t.string "date" + t.integer "student_id" + t.integer "tutor_id" +end \ No newline at end of file diff --git a/db/seeds.rb b/db/seeds.rb new file mode 100644 index 00000000..f986369f --- /dev/null +++ b/db/seeds.rb @@ -0,0 +1,16 @@ +require 'pry' + +require_relative 'lib/student.rb' +require_relative 'lib/lesson.rb' +require_relative 'lib/tutor.rb' + + +barak = User.create(username: "Barak", password: + +nyasha = Student.new(name = "Nyasha", subject = "Math") +barak = Tutor.new(name = "Barak", subject = "Math") +lesson = Lesson.new(topic = "math", date = "Monday", student_id = 1, tutor_id = 1) + + + +binding.pry \ No newline at end of file diff --git a/lib/lesson.rb b/lib/lesson.rb new file mode 100644 index 00000000..cf3b9760 --- /dev/null +++ b/lib/lesson.rb @@ -0,0 +1,15 @@ +class Lesson + + attr_reader :topic, :date, :student_id, :tutor_id + + def initialize (topic, date, student_id, tutor_id) + @topic = topic + @date = date + @student_id = student_id + @tutor_id = tutor_id + end + + def + end + +end \ No newline at end of file diff --git a/lib/student.rb b/lib/student.rb new file mode 100644 index 00000000..12d35f60 --- /dev/null +++ b/lib/student.rb @@ -0,0 +1,53 @@ + +class Student Date: Tue, 9 Mar 2021 11:32:25 -0500 Subject: [PATCH 02/14] changes --- {lib => app/models}/.keep | 0 app/models/interface.rb | 0 app/models/lesson.rb | 16 ++++++++++++++++ {lib => app/models}/student.rb | 19 +++++++++---------- app/models/tutor.rb | 12 ++++++++++++ lib/lesson.rb | 15 --------------- lib/tutor.rb | 12 ------------ 7 files changed, 37 insertions(+), 37 deletions(-) rename {lib => app/models}/.keep (100%) create mode 100644 app/models/interface.rb create mode 100644 app/models/lesson.rb rename {lib => app/models}/student.rb (81%) create mode 100644 app/models/tutor.rb delete mode 100644 lib/lesson.rb delete mode 100644 lib/tutor.rb diff --git a/lib/.keep b/app/models/.keep similarity index 100% rename from lib/.keep rename to app/models/.keep diff --git a/app/models/interface.rb b/app/models/interface.rb new file mode 100644 index 00000000..e69de29b diff --git a/app/models/lesson.rb b/app/models/lesson.rb new file mode 100644 index 00000000..d88443dc --- /dev/null +++ b/app/models/lesson.rb @@ -0,0 +1,16 @@ +class Lesson < ActiveRecord::Base + belongs_to :student + belongs_to :tutor + + +# def initialize (topic, date, student_id, tutor_id) +# @topic = topic +# @date = date +# @student_id = student_id +# @tutor_id = tutor_id +# end + + def + end + +end \ No newline at end of file diff --git a/lib/student.rb b/app/models/student.rb similarity index 81% rename from lib/student.rb rename to app/models/student.rb index 12d35f60..6d583cf3 100644 --- a/lib/student.rb +++ b/app/models/student.rb @@ -1,17 +1,16 @@ -class Student Date: Tue, 9 Mar 2021 11:59:43 -0500 Subject: [PATCH 03/14] updated --- app/models/interface.rb | 32 ++++++++++++++++++++++++++++++++ config/environment.rb | 3 ++- db/seeds.rb | 10 +++++----- 3 files changed, 39 insertions(+), 6 deletions(-) diff --git a/app/models/interface.rb b/app/models/interface.rb index e69de29b..74748d5e 100644 --- a/app/models/interface.rb +++ b/app/models/interface.rb @@ -0,0 +1,32 @@ +class Interface + attr_accessor :user + + def welcome + puts "Welcome to Full Stack Tutoring!" + end + + def login_or_register + puts "Login or Register" + answer = STDIN.gets.chomp + if answer == "login" + # login method + elsif answer == "register" + #register method + else + #error message + end + end + +end + +def login + +end + +def register + +end + +def error_message + puts "We make choices...that was a bad one." +end \ No newline at end of file diff --git a/config/environment.rb b/config/environment.rb index 4dbe13e5..246a9881 100644 --- a/config/environment.rb +++ b/config/environment.rb @@ -2,4 +2,5 @@ Bundler.require ActiveRecord::Base.establish_connection(adapter: 'sqlite3', database: 'db/development.db') -require_all 'lib' +require_all 'app' + diff --git a/db/seeds.rb b/db/seeds.rb index f986369f..81daf893 100644 --- a/db/seeds.rb +++ b/db/seeds.rb @@ -5,11 +5,11 @@ require_relative 'lib/tutor.rb' -barak = User.create(username: "Barak", password: - -nyasha = Student.new(name = "Nyasha", subject = "Math") -barak = Tutor.new(name = "Barak", subject = "Math") -lesson = Lesson.new(topic = "math", date = "Monday", student_id = 1, tutor_id = 1) +barak = User.create(username: "Barak", password: "123") +nyasha = User.create(username: "Nyasha", password: "1234") +# nyasha = Student.new(name = "Nyasha", subject = "Math") +# barak = Tutor.new(name = "Barak", subject = "Math") +# lesson = Lesson.new(topic = "math", date = "Monday", student_id = 1, tutor_id = 1) From 0123eb6c7dab58652634b7de3280c2eab7049eb3 Mon Sep 17 00:00:00 2001 From: fairyaddict0211 Date: Tue, 9 Mar 2021 15:05:50 -0500 Subject: [PATCH 04/14] changes --- Gemfile.lock | 69 ++++++++++++++++++------------------- app/models/interface.rb | 3 +- app/models/lesson.rb | 20 +++++------ app/models/student.rb | 76 +++++++++++++++++++++-------------------- app/models/tutor.rb | 4 +-- db/schema.rb | 9 +++-- db/seeds.rb | 2 +- 7 files changed, 95 insertions(+), 88 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index 9589226d..afa6b0c4 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,50 +1,49 @@ 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-linux DEPENDENCIES pry @@ -53,4 +52,4 @@ DEPENDENCIES sqlite3 BUNDLED WITH - 1.14.6 + 2.2.4 diff --git a/app/models/interface.rb b/app/models/interface.rb index 74748d5e..033d3db5 100644 --- a/app/models/interface.rb +++ b/app/models/interface.rb @@ -20,7 +20,8 @@ def login_or_register end def login - + puts "Login here" + @student = Student end def register diff --git a/app/models/lesson.rb b/app/models/lesson.rb index d88443dc..1769d736 100644 --- a/app/models/lesson.rb +++ b/app/models/lesson.rb @@ -1,16 +1,16 @@ class Lesson < ActiveRecord::Base - belongs_to :student - belongs_to :tutor + belongs_to :students + belongs_to :tutors -# def initialize (topic, date, student_id, tutor_id) -# @topic = topic -# @date = date -# @student_id = student_id -# @tutor_id = tutor_id -# end +# # def initialize (topic, date, student_id, tutor_id) +# # @topic = topic +# # @date = date +# # @student_id = student_id +# # @tutor_id = tutor_id +# # end - def - end +# def +# end end \ No newline at end of file diff --git a/app/models/student.rb b/app/models/student.rb index 6d583cf3..4cfb606a 100644 --- a/app/models/student.rb +++ b/app/models/student.rb @@ -1,50 +1,52 @@ class Student < ActiveRecord::Base - has_many :lesson - has_many :tutor, through: :lesson + has_many :lessons + has_many :tutors, through: :lessons + def self.login_method + puts "Enter Username" + username = STDIN.gets.chomp + puts "Enter Password" + password = STDIN.gets.chomp - - - #def initialize (new, subject) - # @name = name - # @subject = subject - # end - - - def login - #Allow user to log in. - #If login info is invalid return error message using "puts" statement - end - - def register - #Allow new user to create username and password. - #Return to login method once user info is established. - end - - def schedule_lesson - #Enable user to schedule lesson - #Enable user to choose topic. - #Enable user to view available tutors - make sure tutor has topic in their instance. - #Have puts statement to confirm lesson. - #Set date for lesson. + #find a way to check validity of username and password end + - def past_lessons - #Enable user to see previous lessons. - #Push scheduled lessons into array - end + def self.register_method + puts "Create Username" + username = STDIN.gets.chomp + puts "Create Password" + password = STDIN.gets.chomp - def cancel_lesson - #Allow user to cancel lesson that has been scheduled. - #Returns cancelation confirmation. + + # Allow new user to create username and password. + # Return to login method once user info is established. end - def reschedule_lesson - #Allows user to RESCHEDULE scheduled lessons. - #Return confirmation for new lesson. - end +# def schedule_lesson +# #Enable user to schedule lesson +# #Enable user to choose topic. +# #Enable user to view available tutors - make sure tutor has topic in their instance. +# #Have puts statement to confirm lesson. +# #Set date for lesson. +# end + +# def past_lessons +# #Enable user to see previous lessons. +# #Push scheduled lessons into array +# end + +# def cancel_lesson +# #Allow user to cancel lesson that has been scheduled. +# #Returns cancelation confirmation. +# end + +# def reschedule_lesson +# #Allows user to RESCHEDULE scheduled lessons. +# #Return confirmation for new lesson. +# end end diff --git a/app/models/tutor.rb b/app/models/tutor.rb index 3d6bf1d5..713fadc5 100644 --- a/app/models/tutor.rb +++ b/app/models/tutor.rb @@ -1,6 +1,6 @@ class Tutor < ActiveRecord::Base - belongs_to :student - has_many :student, through: :lesson + belongs_to :students + has_many :students, through: :lessons # def initialize (name, subject) diff --git a/db/schema.rb b/db/schema.rb index ca896bbc..fc9f5dcc 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. - ##ActiveRecord::Schema.define(version: 2021_03_09) do +ActiveRecord::Schema.define(version: 2021_03_09) do @@ -29,4 +29,9 @@ t.string "date" t.integer "student_id" t.integer "tutor_id" -end \ No newline at end of file +end + +Questions: +1. How do we know what we need to set up the appropriate enviroment? +2. What do we have to setup to test/ are we missing something in our program to test? +3. \ No newline at end of file diff --git a/db/seeds.rb b/db/seeds.rb index 81daf893..995d0e88 100644 --- a/db/seeds.rb +++ b/db/seeds.rb @@ -5,7 +5,7 @@ require_relative 'lib/tutor.rb' -barak = User.create(username: "Barak", password: "123") +barak = Student.create(username: "Barak", password: "123") nyasha = User.create(username: "Nyasha", password: "1234") # nyasha = Student.new(name = "Nyasha", subject = "Math") # barak = Tutor.new(name = "Barak", subject = "Math") From 8effca04678c84e1197d9c01a625b92786db4a51 Mon Sep 17 00:00:00 2001 From: fairyaddict0211 Date: Tue, 9 Mar 2021 17:01:06 -0500 Subject: [PATCH 05/14] commited changes --- app/models/interface.rb | 27 +++++++++------------------ app/models/student.rb | 2 ++ db/schema.rb | 30 +++++++++++++++--------------- db/seeds.rb | 13 ++++++++++++- 4 files changed, 38 insertions(+), 34 deletions(-) diff --git a/app/models/interface.rb b/app/models/interface.rb index 033d3db5..084a7212 100644 --- a/app/models/interface.rb +++ b/app/models/interface.rb @@ -1,33 +1,24 @@ -class Interface - attr_accessor :user +class Interface < ActiveRecord::Base + has_many :students + has_many :tutors + # attr_accessor :student - def welcome + def self.welcome puts "Welcome to Full Stack Tutoring!" end - def login_or_register + def self.login_or_register puts "Login or Register" answer = STDIN.gets.chomp if answer == "login" - # login method + Student.login_method elsif answer == "register" - #register method + Student.register_method else - #error message + puts "We make choices...that was a bad one." end end end -def login - puts "Login here" - @student = Student -end - -def register - -end -def error_message - puts "We make choices...that was a bad one." -end \ No newline at end of file diff --git a/app/models/student.rb b/app/models/student.rb index 4cfb606a..c8205c4c 100644 --- a/app/models/student.rb +++ b/app/models/student.rb @@ -12,6 +12,8 @@ def self.login_method #find a way to check validity of username and password end + + def self.register_method diff --git a/db/schema.rb b/db/schema.rb index fc9f5dcc..331433f5 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -14,24 +14,24 @@ -create_table "students" do |t| +create_table (:students) do |t| t.string "name" t.string "subject" end -create_table "tutors" do |t| - t.string "name" - t.string "subject" -end +# create_table "tutors" do |t| +# t.string "name" +# t.string "subject" +# end -create_table "lessons" do |t| - t.string "topic" - t.string "date" - t.integer "student_id" - t.integer "tutor_id" -end +# create_table "lessons" do |t| +# t.string "topic" +# t.string "date" +# t.integer "student_id" +# t.integer "tutor_id" +# end -Questions: -1. How do we know what we need to set up the appropriate enviroment? -2. What do we have to setup to test/ are we missing something in our program to test? -3. \ No newline at end of file +# Questions: +# 1. How do we know what we need to set up the appropriate enviroment? +# 2. What do we have to setup to test/ are we missing something in our program to test? +# 3. \ No newline at end of file diff --git a/db/seeds.rb b/db/seeds.rb index 995d0e88..22e78995 100644 --- a/db/seeds.rb +++ b/db/seeds.rb @@ -6,7 +6,18 @@ barak = Student.create(username: "Barak", password: "123") -nyasha = User.create(username: "Nyasha", password: "1234") +nyasha = Student.create(username: "Nyasha", password: "1234") + +eric = Tutor.create(name: "Eric", subject: "Math") +sean = Tutor.create(name: "Sean", subject: "English") +toni = Tutor.create(name: "Toni", subject: "Math") +justin = Tutor.create(name: "Justin", subject: "Science") + +math = Lesson.create(topic: "Math", date: "Monday", student_id: , tutor_id: ) +english = Lesson.create(topic: "English", date: "Tuesday", student_id: , tutor_id: ) +science = Lesson.create(topic: "Science", date: "Wednesday", student_id: , tutor_id: ) +math2 = Lesson.create(topic: "Math", date: "Thursday", student_id: , tutor_id: ) + # nyasha = Student.new(name = "Nyasha", subject = "Math") # barak = Tutor.new(name = "Barak", subject = "Math") # lesson = Lesson.new(topic = "math", date = "Monday", student_id = 1, tutor_id = 1) From 0d5449ab750cc3e4efe67271d620195ac9bb5186 Mon Sep 17 00:00:00 2001 From: Barak Rosner Date: Tue, 9 Mar 2021 20:50:01 -0500 Subject: [PATCH 06/14] newest version --- Gemfile.lock | 3 +- Rakefile | 2 +- app/models/interface.rb | 22 +++++--- app/models/lesson.rb | 49 ++++++++++++++---- app/models/student.rb | 8 +-- app/models/tutor.rb | 4 +- db/migrate/20210309224650_create_students.rb | 11 ++++ db/migrate/20210309224919_create_tutors.rb | 9 ++++ db/migrate/20210309225016_create_lessons.rb | 11 ++++ db/schema.rb | 53 +++++++++++--------- db/seeds.rb | 17 ++++--- 11 files changed, 134 insertions(+), 55 deletions(-) create mode 100644 db/migrate/20210309224650_create_students.rb create mode 100644 db/migrate/20210309224919_create_tutors.rb create mode 100644 db/migrate/20210309225016_create_lessons.rb diff --git a/Gemfile.lock b/Gemfile.lock index afa6b0c4..511c4a10 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -43,6 +43,7 @@ GEM zeitwerk (2.4.2) PLATFORMS + x86_64-darwin-20 x86_64-linux DEPENDENCIES @@ -52,4 +53,4 @@ DEPENDENCIES sqlite3 BUNDLED WITH - 2.2.4 + 2.2.11 diff --git a/Rakefile b/Rakefile index d661ffdc..1c53ff9d 100644 --- a/Rakefile +++ b/Rakefile @@ -7,4 +7,4 @@ task :console do ActiveRecord::Base.logger = Logger.new(STDOUT) #Open Pry console, similar to binding.pry. Pry.start -end +end \ No newline at end of file diff --git a/app/models/interface.rb b/app/models/interface.rb index 084a7212..4aa4fe6f 100644 --- a/app/models/interface.rb +++ b/app/models/interface.rb @@ -5,20 +5,28 @@ class Interface < ActiveRecord::Base 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.login_method - elsif answer == "register" - Student.register_method - else - puts "We make choices...that was a bad one." - end + if answer == "login" + @student = Student.login + elsif answer == "register" + @student = Student.register + else + puts "We make choices...that was a bad one." + end + if @student + Lesson.start(@student) + end end + + + + end diff --git a/app/models/lesson.rb b/app/models/lesson.rb index 1769d736..47b08a78 100644 --- a/app/models/lesson.rb +++ b/app/models/lesson.rb @@ -1,16 +1,45 @@ class Lesson < ActiveRecord::Base - belongs_to :students - belongs_to :tutors + belongs_to :student + belongs_to :tutor + def self.start(student) + puts "1. Schedule lessons" + 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" + #Call view scheduled lessons method + else + puts "Try again" + end + end -# # def initialize (topic, date, student_id, tutor_id) -# # @topic = topic -# # @date = date -# # @student_id = student_id -# # @tutor_id = tutor_id -# # end + def self.schedule_lesson(student) + puts "What would you like to learn?" + answer = STDIN.gets.chomp + tutors = Tutor.where(subject: answer) + if tutors.exists? + tutors.each do |tutor| + puts tutor.name + end + end -# def -# end + + end + + def self.past_lessons(student) + lessons = Lesson.where(student: student) + if lessons.exists? + lessons.each do |lesson| + puts lesson.date + puts lesson.topic + puts lesson.tutor.name + end + end + end end \ No newline at end of file diff --git a/app/models/student.rb b/app/models/student.rb index c8205c4c..2299b8f4 100644 --- a/app/models/student.rb +++ b/app/models/student.rb @@ -4,25 +4,27 @@ class Student < ActiveRecord::Base has_many :tutors, through: :lessons - def self.login_method + 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_method + 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 diff --git a/app/models/tutor.rb b/app/models/tutor.rb index 713fadc5..d63a30e1 100644 --- a/app/models/tutor.rb +++ b/app/models/tutor.rb @@ -1,7 +1,9 @@ class Tutor < ActiveRecord::Base - belongs_to :students + + has_many :lessons has_many :students, through: :lessons + # def initialize (name, subject) # @name = name diff --git a/db/migrate/20210309224650_create_students.rb b/db/migrate/20210309224650_create_students.rb new file mode 100644 index 00000000..7d3a533b --- /dev/null +++ b/db/migrate/20210309224650_create_students.rb @@ -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 diff --git a/db/migrate/20210309224919_create_tutors.rb b/db/migrate/20210309224919_create_tutors.rb new file mode 100644 index 00000000..9961039b --- /dev/null +++ b/db/migrate/20210309224919_create_tutors.rb @@ -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 diff --git a/db/migrate/20210309225016_create_lessons.rb b/db/migrate/20210309225016_create_lessons.rb new file mode 100644 index 00000000..bcb8e345 --- /dev/null +++ b/db/migrate/20210309225016_create_lessons.rb @@ -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 diff --git a/db/schema.rb b/db/schema.rb index 331433f5..5c9db1c0 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -2,36 +2,41 @@ # of editing this file, please use the migrations feature of Active Record to # incrementally modify your database, and then regenerate this schema definition. # -# Note that this schema.rb definition is the authoritative source for your -# database schema. If you need to create the application database on another -# system, you should be using db:schema:load, not running all the migrations -# from scratch. The latter is a flawed and unsustainable approach (the more migrations -# you'll amass, the slower it'll run and the greater likelihood for issues). +# 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_09) do +ActiveRecord::Schema.define(version: 2021_03_09_225016) do + create_table "lessons", force: :cascade do |t| + t.string "topic" + t.string "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) do |t| + create_table "students", force: :cascade do |t| t.string "name" t.string "subject" -end - -# create_table "tutors" do |t| -# t.string "name" -# t.string "subject" -# end + 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 "lessons" do |t| -# t.string "topic" -# t.string "date" -# t.integer "student_id" -# t.integer "tutor_id" -# 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 -# Questions: -# 1. How do we know what we need to set up the appropriate enviroment? -# 2. What do we have to setup to test/ are we missing something in our program to test? -# 3. \ No newline at end of file +end diff --git a/db/seeds.rb b/db/seeds.rb index 22e78995..8dad3190 100644 --- a/db/seeds.rb +++ b/db/seeds.rb @@ -1,8 +1,10 @@ require 'pry' -require_relative 'lib/student.rb' -require_relative 'lib/lesson.rb' -require_relative 'lib/tutor.rb' +require_all + +Student.destroy_all +Tutor.destroy_all +Lesson.destroy_all barak = Student.create(username: "Barak", password: "123") @@ -13,10 +15,10 @@ toni = Tutor.create(name: "Toni", subject: "Math") justin = Tutor.create(name: "Justin", subject: "Science") -math = Lesson.create(topic: "Math", date: "Monday", student_id: , tutor_id: ) -english = Lesson.create(topic: "English", date: "Tuesday", student_id: , tutor_id: ) -science = Lesson.create(topic: "Science", date: "Wednesday", student_id: , tutor_id: ) -math2 = Lesson.create(topic: "Math", date: "Thursday", student_id: , tutor_id: ) +math = Lesson.create(topic: "Math", date: "Monday", student: barak, tutor: eric ) +english = Lesson.create(topic: "English", date: "Tuesday", student: nyasha, tutor: sean ) +science = Lesson.create(topic: "Science", date: "Wednesday", student: barak, tutor: toni ) +math = Lesson.create(topic: "Math", date: "Thursday", student: nyasha, tutor: justin ) # nyasha = Student.new(name = "Nyasha", subject = "Math") # barak = Tutor.new(name = "Barak", subject = "Math") @@ -24,4 +26,3 @@ -binding.pry \ No newline at end of file From bde65fe20ada5d23caee783b9f32f129b7d296cd Mon Sep 17 00:00:00 2001 From: Barak Rosner Date: Wed, 10 Mar 2021 10:47:53 -0500 Subject: [PATCH 07/14] most recent updates 3/10 --- Rakefile | 3 ++- app/models/lesson.rb | 6 +++--- config/environment.rb | 1 + 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/Rakefile b/Rakefile index 1c53ff9d..782fd679 100644 --- a/Rakefile +++ b/Rakefile @@ -4,7 +4,8 @@ require 'sinatra/activerecord/rake' desc 'starts a console' task :console do #Enables logging in Pry console whenever ActiveRecord writes SQL for us - ActiveRecord::Base.logger = Logger.new(STDOUT) + #ActiveRecord::Base.logger = Logger.new(STDOUT) + #Above outputs SQL #Open Pry console, similar to binding.pry. Pry.start end \ No newline at end of file diff --git a/app/models/lesson.rb b/app/models/lesson.rb index 47b08a78..ff283319 100644 --- a/app/models/lesson.rb +++ b/app/models/lesson.rb @@ -24,11 +24,11 @@ def self.schedule_lesson(student) tutors = Tutor.where(subject: answer) if tutors.exists? tutors.each do |tutor| - puts tutor.name + puts tutor.name + #Allow student to select a tutor (Toni or Eric) and schedule lesson + #Output lesson confirmation with puts statement. end end - - end def self.past_lessons(student) diff --git a/config/environment.rb b/config/environment.rb index 246a9881..e1cb24cc 100644 --- a/config/environment.rb +++ b/config/environment.rb @@ -1,6 +1,7 @@ require 'bundler' Bundler.require + ActiveRecord::Base.establish_connection(adapter: 'sqlite3', database: 'db/development.db') require_all 'app' From 32b5f293dc9289ac7aa495b783b52c42ed8cf712 Mon Sep 17 00:00:00 2001 From: fairyaddict0211 Date: Wed, 10 Mar 2021 15:53:37 -0500 Subject: [PATCH 08/14] changes --- app/models/lesson.rb | 39 ++++++++++++++++++++++++++++++--------- 1 file changed, 30 insertions(+), 9 deletions(-) diff --git a/app/models/lesson.rb b/app/models/lesson.rb index ff283319..f3827199 100644 --- a/app/models/lesson.rb +++ b/app/models/lesson.rb @@ -20,15 +20,32 @@ def self.start(student) def self.schedule_lesson(student) puts "What would you like to learn?" - answer = STDIN.gets.chomp - tutors = Tutor.where(subject: answer) - if tutors.exists? - tutors.each do |tutor| - puts tutor.name - #Allow student to select a tutor (Toni or Eric) and schedule lesson - #Output lesson confirmation with puts statement. - end - end + answer = STDIN.gets.chomp + puts "When would you like to have your lesson?" + date = STDIN.gets.chomp + puts "Please enter your username." + name = STDIN.gets.chomp + puts "Who would you like to learn with?" + puts Tutor.all + tutor = STDIN.gets.chomp + # tutors = Tutor.where(subject: answer) + # if tutors.exists? + # tutors.each do |tutor| + # puts tutor.name + # end + # puts "Please select a tutor." + # response = STDIN.gets.chomp + # Tutor.find_by(name: response) + Lesson.create(topic: answer, date: date, student: name, tutor: tutor) + # if response == tutors.name + # return "Your lesson has been scheduled." + + + # + # puts "Your lesson has been scheduled." + # #Allow student to select a tutor (Toni or Eric) and schedule lesson + # #Output lesson confirmation with puts statement. + end def self.past_lessons(student) @@ -42,4 +59,8 @@ def self.past_lessons(student) end end + def self.scheduled_lessons(student) + + end + end \ No newline at end of file From 631ffdcc2f851ff5b84101ab26d50297f1d431a4 Mon Sep 17 00:00:00 2001 From: Barak Rosner Date: Wed, 10 Mar 2021 16:00:57 -0500 Subject: [PATCH 09/14] Playing around --- app/models/interface.rb | 9 ++++----- app/models/lesson.rb | 26 +++++++++++++++++++++++--- app/models/student.rb | 24 +----------------------- 3 files changed, 28 insertions(+), 31 deletions(-) diff --git a/app/models/interface.rb b/app/models/interface.rb index 4aa4fe6f..81ea20bb 100644 --- a/app/models/interface.rb +++ b/app/models/interface.rb @@ -16,16 +16,15 @@ def self.login_or_register elsif answer == "register" @student = Student.register else - puts "We make choices...that was a bad one." + puts "We make all choices...that was a bad one." end if @student Lesson.start(@student) + elsif @student + #Lesson.view_scheduled_lessons(@student) end - end - - - + end end diff --git a/app/models/lesson.rb b/app/models/lesson.rb index ff283319..3b6e767c 100644 --- a/app/models/lesson.rb +++ b/app/models/lesson.rb @@ -3,7 +3,7 @@ class Lesson < ActiveRecord::Base belongs_to :tutor def self.start(student) - puts "1. Schedule lessons" + puts "1. Schedule lesson" puts "2. View past lessons" puts "3. View scheduled lessons" answer = STDIN.gets.chomp @@ -12,7 +12,8 @@ def self.start(student) elsif answer == "2" past_lessons(student) elsif answer == "3" - #Call view scheduled lessons method + view_scheduled_lessons(student) + #Calling scheduled_lessons method else puts "Try again" end @@ -24,9 +25,15 @@ def self.schedule_lesson(student) tutors = Tutor.where(subject: answer) if tutors.exists? tutors.each do |tutor| - puts tutor.name + puts tutor.name + answer = STDIN.gets.chomp + if answer == tutor.name + puts "Your lesson has been scheduled with"[:tutor.name] + elsif answer == "Toni" + puts "Your lesson has been scheduled with"[:tutor.name] #Allow student to select a tutor (Toni or Eric) and schedule lesson #Output lesson confirmation with puts statement. + end end end end @@ -42,4 +49,17 @@ def self.past_lessons(student) end end + #Have below method called at end of schedule_lesson method above + def self.view_scheduled_lessons(student) + lessons = Lesson.where(student: student) + if lessons.exists? + lessons.each do |lesson| + puts lesson.date + puts lesson.topic + puts lesson.tutor.name + end + end + end + # puts "These are your lessons" + # end end \ No newline at end of file diff --git a/app/models/student.rb b/app/models/student.rb index 2299b8f4..1068ea67 100644 --- a/app/models/student.rb +++ b/app/models/student.rb @@ -29,29 +29,7 @@ def self.register # Return to login method once user info is established. end -# def schedule_lesson -# #Enable user to schedule lesson -# #Enable user to choose topic. -# #Enable user to view available tutors - make sure tutor has topic in their instance. -# #Have puts statement to confirm lesson. -# #Set date for lesson. -# end - -# def past_lessons -# #Enable user to see previous lessons. -# #Push scheduled lessons into array -# end - -# def cancel_lesson -# #Allow user to cancel lesson that has been scheduled. -# #Returns cancelation confirmation. -# end - -# def reschedule_lesson -# #Allows user to RESCHEDULE scheduled lessons. -# #Return confirmation for new lesson. -# end - + end From f8fd66a1ea32bd926af1f056f8d9e056c91c686d Mon Sep 17 00:00:00 2001 From: Barak Rosner Date: Wed, 10 Mar 2021 18:40:31 -0500 Subject: [PATCH 10/14] final version --- app/models/lesson.rb | 78 ++++++++++++------- .../20210310225540_change_date_on_lessons.rb | 5 ++ db/schema.rb | 4 +- db/seeds.rb | 9 +-- 4 files changed, 61 insertions(+), 35 deletions(-) create mode 100644 db/migrate/20210310225540_change_date_on_lessons.rb diff --git a/app/models/lesson.rb b/app/models/lesson.rb index 68c6ea4e..cf445373 100644 --- a/app/models/lesson.rb +++ b/app/models/lesson.rb @@ -12,7 +12,7 @@ def self.start(student) elsif answer == "2" past_lessons(student) elsif answer == "3" - view_scheduled_lessons(student) + scheduled_lessons(student) #Calling scheduled_lessons method else puts "Try again" @@ -21,45 +21,67 @@ def self.start(student) def self.schedule_lesson(student) puts "What would you like to learn?" - answer = STDIN.gets.chomp + answer = STDIN.gets.chomp puts "When would you like to have your lesson?" - date = STDIN.gets.chomp - puts "Please enter your username." - name = STDIN.gets.chomp - puts "Who would you like to learn with?" - puts Tutor.all - binding.pry - tutor = STDIN.gets.chomp - # tutors = Tutor.where(subject: answer) - # if tutors.exists? - # tutors.each do |tutor| - # puts tutor.name - # end - # puts "Please select a tutor." - # response = STDIN.gets.chomp - # Tutor.find_by(name: response) - Lesson.create(topic: answer, date: date, student: name, tutor: tutor) - # if response == tutors.name - # return "Your lesson has been scheduled." - # - # puts "Your lesson has been scheduled." - # #Allow student to select a tutor (Toni or Eric) and schedule lesson - # #Output lesson confirmation with puts statement. + 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." + + end def self.past_lessons(student) - lessons = Lesson.where(student: student) + lessons = Lesson.where(student: student).where("date < ?", Time.current) if lessons.exists? lessons.each do |lesson| - puts lesson.date - puts lesson.topic - puts lesson.tutor.name + puts "#{student.username} had a #{lesson.topic} lesson on #{lesson.date} with #{lesson.tutor.name}" + # puts lesson.topic + # puts lesson.tutor.name end end end def self.scheduled_lessons(student) + lessons = Lesson.where(student: student).where("date > ?", Time.current) + if lessons.exists? + lessons.each do |lesson| + puts "#{lesson.id}. #{student.username} has a #{lesson.topic} lesson on #{lesson.date} with #{lesson.tutor.name}" + end + puts "Pick a lesson to reschedule or cancel." + 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" + reschedule_lesson(lesson) + elsif student_choice == "2" + cancel_lesson(lesson) + end + end + end + + def self.reschedule_lesson(lesson) + puts "When would you like to reschedule your lesson?" + lesson_reschedule = STDIN.get.chomp + lesson.update(date: lesson_reschedule) + puts "Your lesson has been rescheduled!" + end + def self.cancel_lesson(lesson) + lesson.destroy + puts "Your lesson has been cancelled." end end \ No newline at end of file diff --git a/db/migrate/20210310225540_change_date_on_lessons.rb b/db/migrate/20210310225540_change_date_on_lessons.rb new file mode 100644 index 00000000..d217d43c --- /dev/null +++ b/db/migrate/20210310225540_change_date_on_lessons.rb @@ -0,0 +1,5 @@ +class ChangeDateOnLessons < ActiveRecord::Migration[6.1] + def change + change_column :lessons, :date, :datetime + end +end diff --git a/db/schema.rb b/db/schema.rb index 5c9db1c0..a308bf4e 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,11 +10,11 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 2021_03_09_225016) do +ActiveRecord::Schema.define(version: 2021_03_10_225540) do create_table "lessons", force: :cascade do |t| t.string "topic" - t.string "date" + t.datetime "date" t.integer "student_id" t.integer "tutor_id" t.datetime "created_at", precision: 6, null: false diff --git a/db/seeds.rb b/db/seeds.rb index 8dad3190..4245f6cc 100644 --- a/db/seeds.rb +++ b/db/seeds.rb @@ -15,14 +15,13 @@ toni = Tutor.create(name: "Toni", subject: "Math") justin = Tutor.create(name: "Justin", subject: "Science") -math = Lesson.create(topic: "Math", date: "Monday", student: barak, tutor: eric ) -english = Lesson.create(topic: "English", date: "Tuesday", student: nyasha, tutor: sean ) -science = Lesson.create(topic: "Science", date: "Wednesday", student: barak, tutor: toni ) -math = Lesson.create(topic: "Math", date: "Thursday", student: nyasha, tutor: justin ) +math = Lesson.create(topic: "Math", date: "08/08/2021 9:00am", student: barak, tutor: eric ) +english = Lesson.create(topic: "English", date: "08/08/2021 10:00am", student: nyasha, tutor: sean ) +science = Lesson.create(topic: "Science", date: "22/02/2021 11:00am", student: barak, tutor: toni ) +math = Lesson.create(topic: "Math", date: "22/02/2021 8:00am", student: nyasha, tutor: justin ) # nyasha = Student.new(name = "Nyasha", subject = "Math") # barak = Tutor.new(name = "Barak", subject = "Math") # lesson = Lesson.new(topic = "math", date = "Monday", student_id = 1, tutor_id = 1) - From a00876146494099162736aa4126a25e5494005ff Mon Sep 17 00:00:00 2001 From: Barak Rosner Date: Thu, 11 Mar 2021 13:24:13 -0500 Subject: [PATCH 11/14] Baraks changes --- app/models/interface.rb | 4 +--- app/models/lesson.rb | 32 ++++++++++++++++++++------------ 2 files changed, 21 insertions(+), 15 deletions(-) diff --git a/app/models/interface.rb b/app/models/interface.rb index 81ea20bb..f3d452c2 100644 --- a/app/models/interface.rb +++ b/app/models/interface.rb @@ -20,10 +20,8 @@ def self.login_or_register end if @student Lesson.start(@student) - elsif @student - #Lesson.view_scheduled_lessons(@student) + #elseif @student end - end end diff --git a/app/models/lesson.rb b/app/models/lesson.rb index cf445373..49586f4c 100644 --- a/app/models/lesson.rb +++ b/app/models/lesson.rb @@ -3,9 +3,10 @@ class Lesson < ActiveRecord::Base belongs_to :tutor def self.start(student) + puts "Main Menu" puts "1. Schedule lesson" puts "2. View past lessons" - puts "3. View scheduled lessons" + puts "3. View scheduled lessons" answer = STDIN.gets.chomp if answer == "1" schedule_lesson(student) @@ -13,7 +14,6 @@ def self.start(student) past_lessons(student) elsif answer == "3" scheduled_lessons(student) - #Calling scheduled_lessons method else puts "Try again" end @@ -21,6 +21,7 @@ def self.start(student) 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 @@ -46,27 +47,27 @@ def self.past_lessons(student) if lessons.exists? lessons.each do |lesson| puts "#{student.username} had a #{lesson.topic} lesson on #{lesson.date} with #{lesson.tutor.name}" - # puts lesson.topic - # puts lesson.tutor.name end end end def self.scheduled_lessons(student) + puts "Pick a lesson to reschedule or cancel." lessons = Lesson.where(student: student).where("date > ?", Time.current) if lessons.exists? lessons.each do |lesson| - puts "#{lesson.id}. #{student.username} has a #{lesson.topic} lesson on #{lesson.date} with #{lesson.tutor.name}" - end - puts "Pick a lesson to reschedule or cancel." - lesson_id = STDIN.gets.chomp + puts "#{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 @@ -74,14 +75,21 @@ def self.scheduled_lessons(student) def self.reschedule_lesson(lesson) puts "When would you like to reschedule your lesson?" - lesson_reschedule = STDIN.get.chomp - lesson.update(date: lesson_reschedule) + lesson_reschedule = STDIN.gets.chomp + Lesson.update(date: lesson_reschedule) puts "Your lesson has been rescheduled!" + Lesson.start(@student) end def self.cancel_lesson(lesson) - lesson.destroy + lesson.destroy(lesson) puts "Your lesson has been cancelled." + Lesson.start(@student) end -end \ No newline at end of file + +end + +# user_option = STDIN.gets.chomp +# if user_option == "yes" +# Lesson.start(@student) \ No newline at end of file From 4b91b43c6cf2c8cfd642e3e0fc731986b7401dbd Mon Sep 17 00:00:00 2001 From: Barak Rosner Date: Thu, 11 Mar 2021 14:33:08 -0500 Subject: [PATCH 12/14] almost finished --- Rakefile | 7 ++++++- app/models/interface.rb | 5 ++--- app/models/lesson.rb | 21 ++++++++++++--------- 3 files changed, 20 insertions(+), 13 deletions(-) diff --git a/Rakefile b/Rakefile index 782fd679..89cb92bc 100644 --- a/Rakefile +++ b/Rakefile @@ -8,4 +8,9 @@ task :console do #Above outputs SQL #Open Pry console, similar to binding.pry. Pry.start -end \ No newline at end of file +end + + +task :start do +Interface.welcome +end diff --git a/app/models/interface.rb b/app/models/interface.rb index f3d452c2..4606f9e7 100644 --- a/app/models/interface.rb +++ b/app/models/interface.rb @@ -1,6 +1,5 @@ -class Interface < ActiveRecord::Base - has_many :students - has_many :tutors +class Interface + # attr_accessor :student def self.welcome diff --git a/app/models/lesson.rb b/app/models/lesson.rb index 49586f4c..62762b1c 100644 --- a/app/models/lesson.rb +++ b/app/models/lesson.rb @@ -43,7 +43,7 @@ def self.schedule_lesson(student) end def self.past_lessons(student) - lessons = Lesson.where(student: student).where("date < ?", Time.current) + 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} with #{lesson.tutor.name}" @@ -53,10 +53,10 @@ def self.past_lessons(student) def self.scheduled_lessons(student) puts "Pick a lesson to reschedule or cancel." - lessons = Lesson.where(student: student).where("date > ?", Time.current) + lessons = student.lessons.where("date > ?", Time.current) if lessons.exists? lessons.each do |lesson| - puts "#{student.username} has a #{lesson.topic} lesson on #{lesson.date}" # #{lesson.id}. with #{lesson.tutor.name} + 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) @@ -65,7 +65,7 @@ def self.scheduled_lessons(student) student_choice = STDIN.gets.chomp if student_choice == "1" puts "Pick a lesson to reschedule." - reschedule_lesson(lesson) + reschedule_lesson(lesson) elsif student_choice == "2" puts "Pick a lesson to cancel." cancel_lesson(lesson) @@ -76,20 +76,23 @@ def self.scheduled_lessons(student) def self.reschedule_lesson(lesson) puts "When would you like to reschedule your lesson?" lesson_reschedule = STDIN.gets.chomp - Lesson.update(date: lesson_reschedule) + lesson.update(date: lesson_reschedule) puts "Your lesson has been rescheduled!" - Lesson.start(@student) + Interface.welcome end def self.cancel_lesson(lesson) - lesson.destroy(lesson) + lesson.destroy puts "Your lesson has been cancelled." - Lesson.start(@student) + 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) \ No newline at end of file From bb4699376d6036ce38e22b8d365f994dbb930c1f Mon Sep 17 00:00:00 2001 From: fairyaddict0211 Date: Thu, 11 Mar 2021 17:31:36 -0500 Subject: [PATCH 13/14] changes --- app/models/interface.rb | 3 ++- app/models/lesson.rb | 9 +++++---- app/models/student.rb | 2 +- 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/app/models/interface.rb b/app/models/interface.rb index 4606f9e7..39c93ba4 100644 --- a/app/models/interface.rb +++ b/app/models/interface.rb @@ -19,7 +19,8 @@ def self.login_or_register end if @student Lesson.start(@student) - #elseif @student + elsif + Interface.welcome end end diff --git a/app/models/lesson.rb b/app/models/lesson.rb index 62762b1c..962e2286 100644 --- a/app/models/lesson.rb +++ b/app/models/lesson.rb @@ -13,7 +13,7 @@ def self.start(student) elsif answer == "2" past_lessons(student) elsif answer == "3" - scheduled_lessons(student) + scheduled_lessons(student) else puts "Try again" end @@ -38,7 +38,7 @@ def self.schedule_lesson(student) 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 @@ -46,9 +46,10 @@ 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} with #{lesson.tutor.name}" + puts "#{student.username} had a #{lesson.topic} lesson on #{lesson.date}." end end + Interface.welcome end def self.scheduled_lessons(student) @@ -56,7 +57,7 @@ def self.scheduled_lessons(student) 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} + 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) diff --git a/app/models/student.rb b/app/models/student.rb index 1068ea67..a0d3bb79 100644 --- a/app/models/student.rb +++ b/app/models/student.rb @@ -11,7 +11,7 @@ def self.login password = STDIN.gets.chomp Student.find_by(username: username, password: password) -#Search db for entered username and password + #Search db for entered username and password #find a way to check validity of username and password end From 8198cd69b0035ec6855e059dbdd6ff748357a193 Mon Sep 17 00:00:00 2001 From: fairyaddict0211 Date: Thu, 11 Mar 2021 17:40:04 -0500 Subject: [PATCH 14/14] final --- app/models/lesson.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/models/lesson.rb b/app/models/lesson.rb index 962e2286..ba4e4a1e 100644 --- a/app/models/lesson.rb +++ b/app/models/lesson.rb @@ -37,9 +37,9 @@ def self.schedule_lesson(student) 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 + puts "Your lesson has been scheduled." + Interface.welcome end def self.past_lessons(student)