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

my version of the challenge #2202

Open
wants to merge 47 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
47 commits
Select commit Hold shift + click to select a range
1c8360f
Project setup
Shakhrai8 Jun 2, 2023
0e5c8a5
File setup
Shakhrai8 Jun 2, 2023
07b50b4
add user class, add unit test, pass test
Shakhrai8 Jun 2, 2023
d02368c
created main database schema
Shakhrai8 Jun 2, 2023
560ab81
add database connection
Shakhrai8 Jun 2, 2023
3932646
add test sql seed
Shakhrai8 Jun 2, 2023
c959162
initital code structure for model and repository classes
Shakhrai8 Jun 2, 2023
49f1eb8
add method to reset tables before each test
Shakhrai8 Jun 2, 2023
2427c27
updated the model class and test for it
Shakhrai8 Jun 2, 2023
9c7a8fe
updated spec helper
Shakhrai8 Jun 2, 2023
4e5655d
add new methods
Shakhrai8 Jun 2, 2023
f3fbeba
add new tests, pass tests
Shakhrai8 Jun 2, 2023
a598357
add new methods
Shakhrai8 Jun 3, 2023
c54dcb7
add new tests, pass tests
Shakhrai8 Jun 3, 2023
85a12e7
updated model class
Shakhrai8 Jun 3, 2023
1ec7b9c
refactor
Shakhrai8 Jun 3, 2023
8240038
updated model class
Shakhrai8 Jun 3, 2023
4979cee
add new methods
Shakhrai8 Jun 3, 2023
a6671f5
add new tests, pass tests
Shakhrai8 Jun 3, 2023
b54b2f9
add new methods
Shakhrai8 Jun 3, 2023
d4c794f
add new methods, add new tests, pass tests
Shakhrai8 Jun 3, 2023
e5e45a6
add new methods, add new tests, pass tests
Shakhrai8 Jun 3, 2023
1f67bea
now peep captures time when created, updated tests, pass tests
Shakhrai8 Jun 3, 2023
9c31e45
add new erb files
Shakhrai8 Jun 4, 2023
eeed35d
updated methods
Shakhrai8 Jun 4, 2023
835859f
new method
Shakhrai8 Jun 4, 2023
21374d1
add new route
Shakhrai8 Jun 4, 2023
d67fa94
config
Shakhrai8 Jun 4, 2023
4e87c6f
new tests
Shakhrai8 Jun 4, 2023
678ed69
new erb view files
Shakhrai8 Jun 4, 2023
99f6e3d
working routes
Shakhrai8 Jun 4, 2023
5e03666
new routes
Shakhrai8 Jun 4, 2023
bd8725f
refactor
Shakhrai8 Jun 4, 2023
c7b1cea
add new route to see pop up window with info in it
Shakhrai8 Jun 4, 2023
8fdd5b5
updated design
Shakhrai8 Jun 4, 2023
6cb4212
solved missing path to the style.css
Shakhrai8 Jun 4, 2023
8d84923
add new view routes, works
Shakhrai8 Jun 4, 2023
4fad1cb
updated route
Shakhrai8 Jun 4, 2023
2720e3b
add new styles
Shakhrai8 Jun 4, 2023
248a674
add new banner
Shakhrai8 Jun 4, 2023
d229af0
updated route
Shakhrai8 Jun 4, 2023
9c38371
setup for deploy
Shakhrai8 Jun 4, 2023
77cffc5
ready for deploy
Shakhrai8 Jun 4, 2023
fcf3b29
add diagram
Shakhrai8 Jun 4, 2023
3fbade1
Update README.md
Shakhrai8 Jun 4, 2023
6afc73e
Create LICENSE
Shakhrai8 Jun 4, 2023
4d6b22d
Merge branch 'main' of https://github.com/Shakhrai8/chitter-challenge
Shakhrai8 Jun 4, 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
8 changes: 8 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,11 @@ 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 "pg", "~> 1.5"
gem 'rackup', '~> 1.0'
35 changes: 34 additions & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,21 @@ 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)
rackup (1.0.0)
rack (< 3)
webrick
rainbow (3.0.0)
regexp_parser (2.1.1)
rexml (3.2.5)
Expand Down Expand Up @@ -36,6 +48,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 +59,41 @@ 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)
rackup (~> 1.0)
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.13
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2023 Yevhen Shakhrai

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
144 changes: 59 additions & 85 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,123 +1,97 @@
Chitter Challenge
=================
# CyberTwitter

* 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
CyberTwitter is a small Twitter clone web application built with Ruby, Sinatra, and JavaScript. It allows users to sign up, log in, post "peeps" (tweets), and view a feed of peeps from other users.

Challenge:
-------
## Features

As usual please start by forking this repo.
- User authentication: Sign up and log in securely.
- Posting peeps: Share your thoughts and updates with other users.
- Feed: View a chronological list of peeps from all users.
- Profile page: See your own profile with your posted peeps.

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

Features:
-------
The CyberTwitter application is deployed and can be accessed at [https://chitter-yuhm.onrender.com](https://chitter-yuhm.onrender.com) on Render.

```
STRAIGHT UP
## Local Development

As a Maker
So that I can let people know what I am doing
I want to post a message (peep) to chitter
To run CyberTwitter locally, follow the instructions below:

As a maker
So that I can see what others are saying
I want to see all peeps in reverse chronological order
1. Clone the repository:

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
`git clone https://github.com/your-username/cybertwitter.git`

As a Maker
So that I can post messages on Chitter as me
I want to sign up for Chitter
2. Navigate to the project directory:

HARDER
`cd cybertwitter`

As a Maker
So that only I can post messages on Chitter as me
I want to log in to Chitter
3. Install the required gems:

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

ADVANCED
4. Set up the database:

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
```
- Ensure you have PostgreSQL installed and running.
- Create a new database for CyberTwitter.
- Import the database schema using the `psql` command:

Technical Approach:
-----
```
psql -h 127.0.0.1 -d your_database_name < path/to/schema.sql
```

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.
Replace `your_database_name` with the name of your PostgreSQL database, and `path/to/schema.sql` with the actual path to your schema file.

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).
5. Start the server:

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.
`rackup`

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)
The application will be running on `http://localhost:9292`.

Notes on functionality:
------
## Dependencies

* 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.
CyberTwitter relies on the following technologies, libraries, and tools:

Bonus:
-----
- Ruby 2.7+
- Sinatra web framework
- WEBrick server
- JavaScript
- PostgreSQL database
- ActiveRecord ORM
- BCrypt for password hashing
- RSpec for testing
- SecureRandom for generating secure random tokens

If you have time you can implement the following:
## Testing

* In order to start a conversation as a maker I want to reply to a peep from another maker.
CyberTwitter includes a suite of RSpec tests to ensure its functionality is working correctly. You can run the tests using the following command:

And/Or:
`rspec`

* Work on the CSS to make it look good.

Good luck and let the chitter begin!
## Routes

Code Review
-----------
CyberTwitter includes the following routes:

In code review we'll be hoping to see:
- `GET /`: Home page of the application.
- `GET /signup`: Sign up page for creating a new user account.
- `POST /signup`: Endpoint for creating a new user account.
- `GET /login`: Login page for existing users.
- `POST /login`: Endpoint for user login.
- `GET /logout`: Endpoint for user logout.
- `GET /feed`: View the feed of all peeps.
- `GET /profile`: View the user's profile page.

* 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.
Please refer to the application code for more details on each route's functionality.

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.
## Contributing

Notes on test coverage
----------------------
Contributions are welcome! If you find any bugs or have suggestions for improvements, please open an issue or submit a pull request. Make sure to follow the existing code style and guidelines.

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:
## License

```ruby
require 'simplecov'
require 'simplecov-console'
This project is licensed under the [MIT License](LICENSE).

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

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!
CyberTwitter was developed as part of a learning project and is inspired by the Chitter Challenge. Special thanks to the contributors and the open-source community for their valuable resources and guidance.
34 changes: 34 additions & 0 deletions app.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
require 'sinatra'
require 'base64'
require 'sinatra/base'
require 'sinatra/reloader'
require 'securerandom'
require_relative 'lib/database_connection'
require_relative 'routes/users'
require_relative 'routes/feed'

DatabaseConnection.connect

class Application < Sinatra::Base
configure :development do
register Sinatra::Reloader
also_reload 'lib/repositories/user_repository'
also_reload 'lib/repositories/tag_repository'
also_reload 'lib/repositories/peep_tag_repository'
also_reload 'lib/repositories/peep_repository'
also_reload 'lib/repositories/reply_repository'
end

configure do
enable :sessions
set :session_secret, "5cdde102f6f68294e1cff23f341aaaaf2d2725453eaccc8ebc239629e724fc53"
end

use Users
use Feed

get '/' do
erb :index
end

end
2 changes: 2 additions & 0 deletions config.ru
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
require_relative 'app'
run Application
Binary file added designs/design_diagram.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
40 changes: 40 additions & 0 deletions lib/database_connection.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# file: lib/database_connection.rb

require 'pg'

# This class is a thin "wrapper" around the
# PG library. We'll use it in our project to interact
# with the database using SQL.

class DatabaseConnection
# This method connects to PostgreSQL using the
# PG gem. We connect to 127.0.0.1, and select
# the database name given in argument.
def self.connect
# If the environment variable (set by Render)
# is present, use this to open the connection.
if ENV['DATABASE_URL'] != nil
@connection = PG.connect(ENV['DATABASE_URL'])
return
end

if ENV['ENV'] == 'test'
database_name = 'chitter_test'
else
database_name = 'chitter'
end
@connection = PG.connect({ host: '127.0.0.1', dbname: database_name })
end

# This method executes an SQL query
# on the database, providing some optional parameters
# (you will learn a bit later about when to provide these parameters).
def self.exec_params(query, params)
if @connection.nil?
raise 'DatabaseConnection.exec_params: Cannot run a SQL query as the connection to'\
'the database was never opened. Did you make sure to call first the method '\
'`DatabaseConnection.connect` in your app.rb file (or in your tests spec_helper.rb)?'
end
@connection.exec_params(query, params)
end
end
11 changes: 11 additions & 0 deletions lib/models/peep.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
class Peep
attr_accessor :id, :content, :timestamp, :user_id

def author
UserRepository.find(user_id)
end

def tags
PeepTagRepository.find_by_peep(id)
end
end
3 changes: 3 additions & 0 deletions lib/models/peep_tag.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
class PeepTag
attr_accessor :peep_id, :tag_id
end
Loading