Skip to content
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

Q Chitter Challenge #2178

Open
wants to merge 17 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
64ed792
created databases and seed file for RSpec
SomthingInteresting Apr 10, 2023
1d82ed6
created integration test file, database connection and spec helper code
SomthingInteresting Apr 10, 2023
5788555
started first test for peeps and setting up sinatra, left with databa…
SomthingInteresting Apr 10, 2023
ea0ff81
created first test for integration and moved onto PeepRepository
SomthingInteresting Apr 11, 2023
43cb12f
first PeepRepository test passes
SomthingInteresting Apr 11, 2023
4a266fd
got all peeps showing with time plus date on the peeps path
SomthingInteresting Apr 11, 2023
5f7b5b0
added user repo cass to get peeps route. Unfinished.
SomthingInteresting Apr 12, 2023
5f4fd0b
added username to peeps
SomthingInteresting Apr 12, 2023
27c33a9
create method tested for peeps repo class
SomthingInteresting Apr 12, 2023
7d01919
sign up button with styling added to signup erb along with test
SomthingInteresting Apr 12, 2023
69dd847
updated create method with bcrypt
SomthingInteresting Apr 12, 2023
805aed9
tests now working, along with web up sign up, moving onto login page
SomthingInteresting Apr 13, 2023
f95c76f
loggin and loggedin page working, next up is logout
SomthingInteresting Apr 13, 2023
39af8ac
logout working as intended and updated all page styles but need to ma…
SomthingInteresting Apr 13, 2023
e3acb56
major functions for web app now work, updated chitter_diagram which h…
SomthingInteresting Apr 13, 2023
b98804c
started on README
SomthingInteresting Apr 13, 2023
8966eaf
rubocop auto corrections and readme update
SomthingInteresting Apr 13, 2023
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
7 changes: 7 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,10 @@ end
group :development, :test do
gem 'rubocop', '1.20'
end

gem "sinatra", "~> 3.0"
gem "sinatra-contrib", "~> 3.0"
gem "webrick", "~> 1.8"
gem "rack-test", "~> 2.1"
gem 'bcrypt', '~> 3.1'
gem 'pg', '~> 1.2'
30 changes: 29 additions & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,20 @@ GEM
specs:
ansi (1.5.0)
ast (2.4.2)
bcrypt (3.1.18)
diff-lcs (1.4.4)
docile (1.4.0)
multi_json (1.15.0)
mustermann (3.0.0)
ruby2_keywords (~> 0.0.1)
parallel (1.20.1)
parser (3.0.2.0)
ast (~> 2.4.1)
rack (2.2.6.4)
rack-protection (3.0.5)
rack
rack-test (2.1.0)
rack (>= 1.3)
rainbow (3.0.0)
regexp_parser (2.1.1)
rexml (3.2.5)
Expand Down Expand Up @@ -36,6 +45,7 @@ GEM
rubocop-ast (1.11.0)
parser (>= 3.0.1.1)
ruby-progressbar (1.11.0)
ruby2_keywords (0.0.5)
simplecov (0.21.2)
docile (~> 1.1)
simplecov-html (~> 0.11)
Expand All @@ -46,21 +56,39 @@ GEM
terminal-table
simplecov-html (0.12.3)
simplecov_json_formatter (0.1.3)
sinatra (3.0.5)
mustermann (~> 3.0)
rack (~> 2.2, >= 2.2.4)
rack-protection (= 3.0.5)
tilt (~> 2.0)
sinatra-contrib (3.0.5)
multi_json
mustermann (~> 3.0)
rack-protection (= 3.0.5)
sinatra (= 3.0.5)
tilt (~> 2.0)
terminal-table (3.0.1)
unicode-display_width (>= 1.1.1, < 3)
tilt (2.1.0)
unicode-display_width (2.0.0)
webrick (1.8.1)

PLATFORMS
ruby

DEPENDENCIES
bcrypt (~> 3.1)
rack-test (~> 2.1)
rspec
rubocop (= 1.20)
simplecov
simplecov-console
sinatra (~> 3.0)
sinatra-contrib (~> 3.0)
webrick (~> 1.8)

RUBY VERSION
ruby 3.0.2p107

BUNDLED WITH
2.2.26
2.4.10
144 changes: 21 additions & 123 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,123 +1,21 @@
Chitter Challenge
=================

* Feel free to use Google, your notes, books, etc. but work on your own
* If you refer to the solution of another coach or student, please put a link to that in your README
* If you have a partial solution, **still check in a partial solution**
* You must submit a pull request to this repo with your code by 10am Monday morning

Challenge:
-------

As usual please start by forking this repo.

We are going to write a small Twitter clone that will allow the users to post messages to a public stream.

Features:
-------

```
STRAIGHT UP

As a Maker
So that I can let people know what I am doing
I want to post a message (peep) to chitter

As a maker
So that I can see what others are saying
I want to see all peeps in reverse chronological order

As a Maker
So that I can better appreciate the context of a peep
I want to see the time at which it was made

As a Maker
So that I can post messages on Chitter as me
I want to sign up for Chitter

HARDER

As a Maker
So that only I can post messages on Chitter as me
I want to log in to Chitter

As a Maker
So that I can avoid others posting messages on Chitter as me
I want to log out of Chitter

ADVANCED

As a Maker
So that I can stay constantly tapped in to the shouty box of Chitter
I want to receive an email if I am tagged in a Peep
```

Technical Approach:
-----

In the last two weeks, you integrated a database using the `pg` gem and Repository classes. You also implemented small web applications using Sinatra, RSpec, HTML and ERB views to make dynamic webpages. You can continue to use this approach when building Chitter Challenge.

You can refer to the [guidance on Modelling and Planning a web application](https://github.com/makersacademy/web-applications/blob/main/pills/modelling_and_planning_web_application.md), to help you in planning the different web pages you will need to implement this challenge. If you'd like to deploy your app to Heroku so other people can use it, [you can follow this guidance](https://github.com/makersacademy/web-applications/blob/main/html_challenges/07_deploying.md).

If you'd like more technical challenge now, try using an [Object Relational Mapper](https://en.wikipedia.org/wiki/Object-relational_mapping) as the database interface, instead of implementing your own Repository classes.

Some useful resources:
**Ruby Object Mapper**
- [ROM](https://rom-rb.org/)

**ActiveRecord**
- [ActiveRecord ORM](https://guides.rubyonrails.org/active_record_basics.html)
- [Sinatra & ActiveRecord setup](https://learn.co/lessons/sinatra-activerecord-setup)

Notes on functionality:
------

* You don't have to be logged in to see the peeps.
* Makers sign up to chitter with their email, password, name and a username (e.g. [email protected], password123, Sam Morgan, sjmog).
* The username and email are unique.
* Peeps (posts to chitter) have the name of the maker and their user handle.
* Your README should indicate the technologies used, and give instructions on how to install and run the tests.

Bonus:
-----

If you have time you can implement the following:

* In order to start a conversation as a maker I want to reply to a peep from another maker.

And/Or:

* Work on the CSS to make it look good.

Good luck and let the chitter begin!

Code Review
-----------

In code review we'll be hoping to see:

* All tests passing
* High [Test coverage](https://github.com/makersacademy/course/blob/main/pills/test_coverage.md) (>95% is good)
* The code is elegant: every class has a clear responsibility, methods are short etc.

Reviewers will potentially be using this [code review rubric](docs/review.md). Referring to this rubric in advance may make the challenge somewhat easier. You should be the judge of how much challenge you want at this moment.

Notes on test coverage
----------------------

Please ensure you have the following **AT THE TOP** of your spec_helper.rb in order to have test coverage stats generated
on your pull request:

```ruby
require 'simplecov'
require 'simplecov-console'

SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter.new([
SimpleCov::Formatter::Console,
# Want a nice code coverage website? Uncomment this next line!
# SimpleCov::Formatter::HTMLFormatter
])
SimpleCov.start
```

You can see your test coverage when you run your tests. If you want this in a graphical form, uncomment the `HTMLFormatter` line and see what happens!
Todo list:

Must do
- separate CSS from erbs
- clean up code and add comments
- reminder to remove code that isn't being used
- time needs to be parsed in new peeps?
- create README with breakdown of new learnings and credits
- reminder to discuss sessions, bcrypt, and how to use them
- ensure it works on other computers if code copied
- implement advised changes from code review
- ensure rubocop and test coverage is 100%
- rubocop --auto-correct

Optional
- make styles uniform
- try to use layout erb to extend the objects between pages

Advanced
- ORM implementation
- reply feature
98 changes: 98 additions & 0 deletions chitter_app.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
require 'sinatra'
require "sinatra/reloader"
require 'bcrypt'
require_relative 'lib/database_connection'
require_relative 'lib/users_repository'
require_relative 'lib/peeps_repository'

DatabaseConnection.connect

class ChitterApp < Sinatra::Base
enable :sessions

helpers do
def current_user
@current_user ||= UserRepository.new.find_user_by_email(session[:email])
end
end

configure :development do
register Sinatra::Reloader
also_reload 'lib/users_repository'
also_reload 'lib/peeps_repository'
end

get '/' do
peeps_repo = PeepRepository.new
@peeps = peeps_repo.all

# Debug statement
# puts "@peeps: #{@peeps.inspect}"

return erb(:peep)
end

get '/signup' do
return erb(:signup)
end

post '/signup' do
username = params['username']
name = params['name']
email = params['email']
password = params['password']
password_hash = BCrypt::Password.create(password)

UserRepository.new.create(username: username, name: name, email: email,
password_hash: password_hash)

redirect '/login'
end

get '/login' do
return erb(:login)
end

post '/login' do
email = params['email']
password = params['password']

user = UserRepository.new.find_user_by_email(email)

if user.nil?
puts "User not found."
redirect '/login'
else
puts "User: #{user.inspect}"
puts "Entered password: #{password}"
puts "Stored password hash: #{user.password_hash}"
puts "Password comparison result: #{BCrypt::Password.new(user.password_hash) == password}"
end

if user && BCrypt::Password.new(user.password_hash) == password
session[:user_id] = user.id
session[:email] = user.email
redirect '/loggedin'
else
redirect '/login'
end
end

get '/loggedin' do
peeps_repo = PeepRepository.new
@peeps = peeps_repo.all
return erb(:loggedin)
end

get '/logout' do
session.clear
redirect '/'
end

post '/peeps' do
content = params['content']
user_id = current_user.id
PeepRepository.new.create(content: content, user_id: user_id)
redirect '/loggedin'
end
end
Binary file added chitter_diagram.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading