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

Chitter Challenge, Louis Claremont #2188

Open
wants to merge 41 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
8b8f4d6
pg setup
May 9, 2023
2cf63ac
sql tables designed
May 9, 2023
a7725cd
designed repo and model classes
May 9, 2023
a16edee
model classes implemented
May 9, 2023
6aa3bec
test driven repository classes
May 9, 2023
0ebd4f3
updated find_with_peeps to contain peep objects
May 9, 2023
9cf70ba
sinatra project setup
May 9, 2023
9e18e11
ensured username and email are unique in create method
May 9, 2023
7c43331
GET / route implementation started
May 9, 2023
31d0c1e
post /peep route design complete
May 9, 2023
5c06ef1
post /peep 200 OK response implemented
May 9, 2023
d8af789
post /peep route completed (no links yet)
May 9, 2023
147fec1
added formatter class to display peeps
May 10, 2023
e3f4275
created all_with_users to peeps repo, so we can format posts with use…
May 10, 2023
a3b1143
added new peep form onto home page
May 10, 2023
b8d1154
validated parameters in POST /peep
May 10, 2023
468f908
post peep route designed
May 10, 2023
71e29d8
post /user route complete
May 10, 2023
a32a126
get user/id route test driven
May 10, 2023
8d28720
added links to user page from each peep username
May 10, 2023
95d960c
added links to tags in peep content
May 10, 2023
09ea8d8
added to spec helper
May 10, 2023
24c012b
put reset tables method into spec helper
May 11, 2023
2cb2565
refactored app.rb
May 11, 2023
8011c20
login helper class setup
May 11, 2023
923ec7e
login helper implemented
May 11, 2023
137da14
get /login route complete
May 11, 2023
06dbff5
attempted login methods in login helper
May 11, 2023
fe07143
manually implemented login feature
May 11, 2023
ab8b5d5
added README
May 11, 2023
64ab0e0
updated readme
May 11, 2023
0594bba
readme test
May 11, 2023
f32da0a
readme update
May 11, 2023
8dfd5ef
updated readme
May 12, 2023
45dbca4
sessions used for login
May 13, 2023
7b5eb1b
removed login helper class
May 13, 2023
a9e1582
used session in the get / route
May 13, 2023
1ae5e3e
updated readme
May 13, 2023
040af8a
updated the readme
May 14, 2023
a29f1b6
setup for render
May 19, 2023
d08c47d
updated dbconnection to connect to render render db url
May 19, 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 "pg", "~> 1.5"

gem "sinatra", "~> 3.0"
gem "sinatra-contrib", "~> 3.0"
gem "webrick", "~> 1.8"
gem "rack-test", "~> 2.1"
29 changes: 29 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,18 @@ GEM
ast (2.4.2)
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)
pg (1.5.3)
rack (2.2.7)
rack-protection (3.0.6)
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,18 +56,37 @@ GEM
terminal-table
simplecov-html (0.12.3)
simplecov_json_formatter (0.1.3)
sinatra (3.0.6)
mustermann (~> 3.0)
rack (~> 2.2, >= 2.2.4)
rack-protection (= 3.0.6)
tilt (~> 2.0)
sinatra-contrib (3.0.6)
multi_json
mustermann (~> 3.0)
rack-protection (= 3.0.6)
sinatra (= 3.0.6)
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
x86_64-linux

DEPENDENCIES
pg (~> 1.5)
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
Expand Down
142 changes: 35 additions & 107 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,123 +1,51 @@
Chitter Challenge
=================
# 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
A twitter clone, my first complete web application as part of Makers Academy.

Challenge:
-------
This project has been designed to improve our understanding of HTTP requests and responses, designing routes and structuring web applications. It contains:

As usual please start by forking this repo.
- Users who are able to make posts.
- A homepage displaying all posts and their creator and time
- A sign up form to create a new user and start making posts.
- A user specific page in which you can view only their posts.
- Tagging functionality within posts so users can tag other users (with `@username`) which will contain a link to that user's page
- A login page in which a user can login and only post as them

This was a challenging and enjoyable project.
The most difficult part was implementing a login feature which I first did manually. I attempted this by creating a GET '/:id' route which goes to a specific user's homepage. Once logged in, the main homepage is redirected to a specific page where only they are able to make posts. I did this by redirecting the GET '/' route to the user specific homepage. However this is not secure, since anybody could manually call upon the '/1', for example, and be logged in as user with ID=1. This was an interesting learning experience in understanding and developing new routes which are connected to each other! But not best practise.

We are going to write a small Twitter clone that will allow the users to post messages to a public stream.
So I researched the sessions functionality in Sinatra which allows us to create a session associated with the user's ID number after they login. Then, in the homepage route, we simplt have to check the session[:user_id] value and return a different HTML page if that value is not nil (ie, a user is logged in).

Features:
-------
Going further, I will look into the Bcrypt password encryption

```
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
## Process
I first designed the table schema for users and peeps.
Then created and test drove the model and repository classes for both Users and Peeps. These repository classes allow our application to interact with the database through the PG gem and PostgreSQL.
Then I began designing the routes for our sinatra application and test drove those one by one.

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

HARDER
```shell
# Make the DB:
createdb chitter_site

As a Maker
So that only I can post messages on Chitter as me
I want to log in to Chitter
# Install gems:
bundle install

As a Maker
So that I can avoid others posting messages on Chitter as me
I want to log out of Chitter
# Run the tests:
rspec

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
# Run server
rackup
```

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
```
## Built with
- Ruby
- Rspec
- Sinatra
- PostgreSQL

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!
## Still to add
- Bcrypt functionality
Loading