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

Sidra Version Of Chitter Challenge #2175

Open
wants to merge 56 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
56 commits
Select commit Hold shift + click to select a range
c87132a
setup
Apr 6, 2023
ce566f2
seeds creation
Apr 6, 2023
623bf1b
add user repo test
Apr 6, 2023
7a71896
all user test driven
Apr 6, 2023
159a12a
find method complete
Apr 6, 2023
69b5f55
create new_user method added and tested
Apr 6, 2023
861c0ff
BCRypt on the find_by_email and all methods for password de-encryption
Apr 6, 2023
a22c5ff
extra test expect for create user
Apr 6, 2023
b0cd2a9
peep_repo all method
Apr 6, 2023
eaf128f
create new pip rspec created
Apr 6, 2023
bdcd5a8
peep creation
Apr 6, 2023
6095bef
renamed folder for recipe
Apr 6, 2023
8cc1f85
add comment for time.now
Apr 6, 2023
dd334b4
added Time.now in create_peep
Apr 6, 2023
3c3fce0
set up Sinatra project
Apr 6, 2023
8e6b3cd
get homepage method:
Apr 7, 2023
6004883
get '/' with peeps done
Apr 7, 2023
9b3334e
register page
Apr 7, 2023
2461081
register page added
Apr 7, 2023
24b1aee
post '/' for user registration added
Apr 7, 2023
0e3c4b9
post register
Apr 7, 2023
7a3ad97
reversed the extra validation for email etc
Apr 7, 2023
a8fd8f8
rubocop tidying
Apr 7, 2023
f856d31
login pending
Apr 7, 2023
5532034
login post changes
Apr 8, 2023
379c4cc
login and logout done
Apr 9, 2023
c19ca13
new_peep route
Apr 9, 2023
ef89d18
fixed the login where incorrect email put in
Apr 9, 2023
1ba516d
sort posts by newest first
Apr 9, 2023
7b35be6
refactor login post
Apr 9, 2023
c65f134
add css
Apr 10, 2023
543a254
trying to add username to no avail
Apr 10, 2023
e7ca13d
Failed to add username
Apr 10, 2023
bb3ca20
Setup for deploy
Apr 10, 2023
9c73d93
ENV in database connection
Apr 10, 2023
4f1f4dc
update to add bcrypt
Apr 10, 2023
a3d2c94
removed comments from database connection
Apr 10, 2023
94fb625
add an argument
Apr 10, 2023
ba54fd7
Updating README.md
Apr 11, 2023
0141dd4
update Readme
Apr 11, 2023
8b3938e
readme
Apr 11, 2023
ce97f53
readme
Apr 11, 2023
52cd439
readme
Apr 11, 2023
d528711
readme
Apr 11, 2023
944ff84
README
Apr 11, 2023
859e379
README
Apr 11, 2023
dc63846
README
Apr 11, 2023
f4ad071
README
Apr 11, 2023
5d7f969
README
Apr 11, 2023
77ed7ea
README
Apr 11, 2023
88ebaa2
README
Apr 11, 2023
6701c63
Add image
Apr 11, 2023
ac6ffeb
Add image
Apr 11, 2023
c37b463
Add image
Apr 11, 2023
d6afa48
Add image
Apr 11, 2023
627b4d1
Add image
Apr 11, 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
9 changes: 9 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,12 @@ end
group :development, :test do
gem 'rubocop', '1.20'
end

gem "pg", "~> 1.4"

gem "sinatra", "~> 3.0"
gem "sinatra-contrib", "~> 3.0"
gem "webrick", "~> 1.8"
gem "rack-test", "~> 2.1"
gem 'bcrypt', '~> 3.1.7'

79 changes: 55 additions & 24 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3,27 +3,37 @@ GEM
specs:
ansi (1.5.0)
ast (2.4.2)
diff-lcs (1.4.4)
bcrypt (3.1.18)
diff-lcs (1.5.0)
docile (1.4.0)
parallel (1.20.1)
parser (3.0.2.0)
multi_json (1.15.0)
mustermann (3.0.0)
ruby2_keywords (~> 0.0.1)
parallel (1.22.1)
parser (3.2.2.0)
ast (~> 2.4.1)
rainbow (3.0.0)
regexp_parser (2.1.1)
pg (1.4.6)
rack (2.2.6.4)
rack-protection (3.0.5)
rack
rack-test (2.1.0)
rack (>= 1.3)
rainbow (3.1.1)
regexp_parser (2.7.0)
rexml (3.2.5)
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.12.0)
rspec-core (~> 3.12.0)
rspec-expectations (~> 3.12.0)
rspec-mocks (~> 3.12.0)
rspec-core (3.12.1)
rspec-support (~> 3.12.0)
rspec-expectations (3.12.2)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.10.0)
rspec-mocks (3.10.2)
rspec-support (~> 3.12.0)
rspec-mocks (3.12.5)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.10.0)
rspec-support (3.10.2)
rspec-support (~> 3.12.0)
rspec-support (3.12.0)
rubocop (1.20.0)
parallel (~> 1.10)
parser (>= 3.0.0.0)
Expand All @@ -33,10 +43,11 @@ GEM
rubocop-ast (>= 1.9.1, < 2.0)
ruby-progressbar (~> 1.7)
unicode-display_width (>= 1.4.0, < 3.0)
rubocop-ast (1.11.0)
parser (>= 3.0.1.1)
ruby-progressbar (1.11.0)
simplecov (0.21.2)
rubocop-ast (1.28.0)
parser (>= 3.2.1.0)
ruby-progressbar (1.13.0)
ruby2_keywords (0.0.5)
simplecov (0.22.0)
docile (~> 1.1)
simplecov-html (~> 0.11)
simplecov_json_formatter (~> 0.1)
Expand All @@ -45,22 +56,42 @@ GEM
simplecov
terminal-table
simplecov-html (0.12.3)
simplecov_json_formatter (0.1.3)
terminal-table (3.0.1)
simplecov_json_formatter (0.1.4)
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.2)
unicode-display_width (>= 1.1.1, < 3)
unicode-display_width (2.0.0)
tilt (2.1.0)
unicode-display_width (2.4.2)
webrick (1.8.1)

PLATFORMS
ruby
x86_64-linux

DEPENDENCIES
bcrypt (~> 3.1.7)
pg (~> 1.4)
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
138 changes: 43 additions & 95 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,73 +1,36 @@
Chitter Challenge
=================
<a name="readme-top"></a>

* 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
# _Chitter Challenge_

Challenge:
-------
#### By _**Sidra Iqbal, adapted from Makers Academy**_

As usual please start by forking this repo.
Technologies Used
-----

We are going to write a small Twitter clone that will allow the users to post messages to a public stream.
* Ruby
* CSS
* HTML
* Postgresql
* Sinatra

Features:
Description:
-------

```
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:
-----
This project is designed to mimic the popular 'Twitter' app for Makers student use. Chitter will have basic functionality like: creating peeps, viewing peeps (including the time of peep in chronological order), as well as login, sign-up and logout capabilities.

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.
The user should have visibility to the login and register links when they are not logged in and similarly only have visibility to the sign-out link when they are logged in, to give a positive user experience.

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).
[![Screenshot of main page](https://i.imgur.com/g3bzkKR.png)](https://chitter-app-59gf.onrender.com/)

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/)
Features:
-------

**ActiveRecord**
- [ActiveRecord ORM](https://guides.rubyonrails.org/active_record_basics.html)
- [Sinatra & ActiveRecord setup](https://learn.co/lessons/sinatra-activerecord-setup)
* Register: User can register to Chitter with their email and create an account with a username and password.
* Login: User can login to their account from the homepage by entering their email address and password.
* Logout: User can logout from the homepage by clicking on the logout link.
* New Peep: Logged in user can have the option to create a new peep by clicking the new peep link on the homepage, where they are directed to the /new_peep page and can submit a peep
* View Peeps: Irrespective of logged in status, peeps will be shown on the homepage in order of the most recent peep first. The peep contents and time are shown on the homepage.

Notes on functionality:
------
Expand All @@ -76,48 +39,33 @@ Notes on functionality:
* 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
-----------
Installation & Requirements
------

In code review we'll be hoping to see:
Clone the repo and add the relevant gems:

* 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.
```
git clone https://github.com/siqbal181/chitter-challenge.git
gem install sinatra -v '~> 3.0'
gem install sinatra-contrib -v '~> 3.0'
gem install webrick -v '~> 1.8'
gem install rack-test -v '~> 2.1'
gem install bcrypt -v '~> 3.1.7'
gem install pg -v '~> 1.4'
```

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.
Testing:
```ruby
gem 'rspec'
gem 'simplecov', require: false
gem 'simplecov-console', require: false
```

Notes on test coverage
----------------------
## Contact

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:
Sidra Iqbal

```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
```
Project Link: [https://github.com/siqbal181/chitter-challenge](https://github.com/siqbal181/chitter-challenge)

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!
<p align="right">(<a href="#readme-top">back to top</a>)</p>
99 changes: 99 additions & 0 deletions app.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
require 'sinatra'
require "sinatra/reloader"
require_relative 'lib/database_connection'
require_relative 'lib/peep_repository'
require_relative 'lib/user_repository'
require 'date'

DatabaseConnection.connect('chitter_database')

class Application < Sinatra::Base
configure :development do
register Sinatra::Reloader
end

enable :sessions

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

if session[:email_address]
user_repo = UserRepository.new
@user = user_repo.find_by_email(session[:email_address])
end

return erb(:homepage)
end

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

post '/register' do # once user has registered
unless params[:email_address].include?('@')
status 400
return ''
end

repo = UserRepository.new
user = User.new
user.email_address = params['email_address']
user.username = params['username']
user.password = params['password']
repo.create(user)

redirect '/'
end

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

post '/login' do
email_address = params[:email_address]
password = params[:password]

user = UserRepository.new.find_by_email(email_address)

if user && user.password == password
session[:email_address] = user.email_address

peep_repo = PeepRepository.new
@peeps = peep_repo.all
@user = user
erb(:homepage)
else
@error = true
erb(:login)
end
end

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

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

post '/new_peep' do
contents = params[:contents]

if session[:email_address]
@user = UserRepository.new.find_by_email(session[:email_address])
end

peep_repo = PeepRepository.new
new_peep = Peep.new
new_peep.contents = contents
new_peep.time = Time.now.strftime("%d/%m/%Y %H:%M")
new_peep.user_id = @user.id
new_peep.username = @user.username
peep_repo.create_peep(new_peep)
@peeps = peep_repo.all

return erb(:homepage)
end
end
3 changes: 3 additions & 0 deletions config.ru
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# file: config.ru
require './app'
run Application
Loading