-
Notifications
You must be signed in to change notification settings - Fork 2.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Week 4 Weekend challenge #1721
base: main
Are you sure you want to change the base?
Week 4 Weekend challenge #1721
Conversation
get '/peeps' do | ||
@user = User.find(session[:user_id]) | ||
@peeps = Peep.all | ||
erb :'peeps/index' | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think your route has been kept skinny, very clean and easy to follow the flow of requests. One question on RESTful route, could you have used parameters in some of the routes?
default: &default | ||
adapter: postgresql | ||
encoding: unicode | ||
pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %> | ||
|
||
development: | ||
<<: *default | ||
database: peep_manager | ||
|
||
production: | ||
<<: *default | ||
database: peepmanager | ||
username: myapp | ||
password: <%= ENV['MYAPP_DATABASE_PASSWORD'] %> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice one! you really took the time to work on the travis file!
require 'pg' | ||
|
||
class DatabaseConnection | ||
def self.setup(dbname) | ||
@connection = PG.connect(dbname: dbname) | ||
end | ||
|
||
def self.query(sql) | ||
@connection.exec(sql) | ||
end | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great user of SRP, having a DatabaseConnection class makes the files cleaner - 100%!
class Peep | ||
def self.create(content:, user:) | ||
time = Time.now.strftime('%T') | ||
result = DatabaseConnection.query("INSERT INTO peeps (content, user_id, time_created) VALUES ($$#{content}$$, #{user.id}, '#{time}') RETURNING id, content, time_created;") | ||
Peep.new( | ||
id: result[0]['id'], | ||
content: result[0]['content'], | ||
time: result[0]['time_created'], | ||
user: user | ||
) | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Having the database class allows you to keep your other classes net
class User | ||
def self.create(email:, password:, name:, username:) | ||
encrypted_password = BCrypt::Password.create(password) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great use of bcrytp
Great use of SRP, encapsulation, MVC and keeping a skinny controller. Very impressive used of the new technologies like Travis or the BCrypt. |
User can sign up, log in, log out. Posting a peep is only possible when authenticated as a user. Most user stories completed except for the last one (sending an email when tagged in a 'peep'). Also didn't implement replies functionality. Minimal css was also used. Probably could have done better in making the controller neater and need to make unit tests more isolated as some (Peep class) were dependent on the User class.