-
Notifications
You must be signed in to change notification settings - Fork 235
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 - Rhys #212
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
@import url('https://fonts.googleapis.com/css2?family=Anybody&display=swap'); | ||
|
||
* { | ||
margin: 0; | ||
padding: 0; | ||
box-sizing: border-box; | ||
font-family: 'Anybody', fantasy; | ||
} | ||
|
||
body{ | ||
background-image: linear-gradient(to bottom right, rgba(45, 85, 255, 1), rgba(255, 255, 255, 0)); | ||
min-height: 100vh; | ||
justify-items: center; | ||
align-items: center; | ||
} | ||
|
||
.topnav { | ||
position: static; | ||
top: 0; | ||
left: 0; | ||
right: 0; | ||
display: flex; | ||
justify-content: center; | ||
align-items: center; | ||
} | ||
|
||
.logo{ | ||
float: left; | ||
font-size: 2em; | ||
padding: 0 15px; | ||
} | ||
|
||
ul{ | ||
padding: 0; | ||
} | ||
|
||
li{ | ||
list-style-type: none; | ||
} | ||
|
||
.peepContainer{ | ||
background-image: linear-gradient(to top left, rgba(45, 85, 255, 1), rgba(255, 255, 255, 0)); | ||
margin: 15px auto; | ||
border: 2.5px; | ||
border-style: solid; | ||
border-radius: 25px; | ||
width: 75%; | ||
padding: 25px; | ||
display: flex; | ||
flex-direction: column; | ||
} | ||
|
||
.peepMessage{ | ||
margin: 15px auto; | ||
border: 2.5px; | ||
border-style: solid; | ||
border-radius: 25px; | ||
width: 95%; | ||
padding: 25px; | ||
font-size: 1.25em; | ||
} | ||
|
||
p{ | ||
margin: auto; | ||
font-size: 0.75em; | ||
float:right; | ||
} | ||
|
||
.createPeepCon{ | ||
display: flex; | ||
justify-items: center; | ||
align-items: center; | ||
flex-direction: column; | ||
flex-wrap: wrap; | ||
} | ||
|
||
.createPeep{ | ||
color: blue; | ||
cursor: pointer; | ||
margin: auto; | ||
border: 2.5px; | ||
border-style: solid; | ||
border-radius: 25px; | ||
width: 40%; | ||
padding: 5px 25px; | ||
transition: 0.3s; | ||
text-decoration: underline; | ||
} | ||
|
||
.createPeep:hover{ | ||
text-decoration: none; | ||
background-color: azure; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
@import url('https://fonts.googleapis.com/css2?family=Anybody&display=swap'); | ||
|
||
* { | ||
margin: 0; | ||
padding: 0; | ||
box-sizing: border-box; | ||
font-family: 'Anybody', fantasy; | ||
} | ||
|
||
body{ | ||
background-image: linear-gradient(to bottom right, rgba(45, 85, 255, 1), rgba(255, 255, 255, 0)); | ||
min-height: 100vh; | ||
justify-items: center; | ||
align-items: center; | ||
} | ||
|
||
.container{ | ||
margin: auto; | ||
padding: 15px; | ||
width: 100%; | ||
display: flex; | ||
flex-direction: column; | ||
} | ||
|
||
form{ | ||
padding: 5px; | ||
display: flex; | ||
justify-content: center; | ||
align-items: center; | ||
flex-direction: column; | ||
} | ||
|
||
.newContainer{ | ||
display: flex; | ||
flex-direction: column; | ||
} | ||
|
||
.messageLabel{ | ||
float: left; | ||
} | ||
|
||
form input{ | ||
border-radius: 5px; | ||
font-size: 1.25em; | ||
} | ||
|
||
form .submitButton{ | ||
align-items: center; | ||
justify-content: center; | ||
float: right; | ||
} | ||
|
||
label{ | ||
font-size: 1.25em; | ||
} | ||
|
||
.submitButton{ | ||
margin: 2.5px 0; | ||
padding: 2.5px 15px; | ||
cursor: pointer; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,25 @@ | ||
require 'sinatra/base' | ||
require 'sinatra/reloader' | ||
require './lib/peeps' | ||
|
||
class Chitter < Sinatra::Base | ||
get '/test' do | ||
'Test page' | ||
end | ||
|
||
get '/' do | ||
@peeps = Peeps.all | ||
erb :index | ||
end | ||
|
||
get '/new_peep' do | ||
erb :new_peep | ||
end | ||
|
||
post '/' do | ||
Peeps.create(message: params[:message]) | ||
redirect '/' | ||
end | ||
|
||
run! if app_file == $0 | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
ALTER TABLE peeps ADD COLUMN peep_date DATE DEFAULT CURRENT_DATE; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good use of the DATE column type! |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
require 'pg' | ||
|
||
class Peeps | ||
attr_reader :id, :message, :date | ||
|
||
def initialize(id:, message:, date:) | ||
@id = id | ||
@message = message | ||
@date = date | ||
end | ||
|
||
def self.all | ||
if ENV['ENVIRONMENT'] == 'test' | ||
connection = PG.connect(dbname: 'chitter_test') | ||
else | ||
connection = PG.connect(dbname: 'chitter') | ||
end | ||
|
||
result = connection.exec('SELECT * FROM peeps ORDER BY peep_date DESC') | ||
result.map do |peep| | ||
Peeps.new(id: peep['id'], message: peep['message'], date: peep['peep_date']) | ||
end | ||
end | ||
|
||
def self.create(message:) | ||
if ENV['ENVIRONMENT'] == 'test' | ||
connection = PG.connect(dbname: 'chitter_test') | ||
else | ||
connection = PG.connect(dbname: 'chitter') | ||
end | ||
Comment on lines
+26
to
+30
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This piece of code appears twice in this file. How might you remove this duplication? |
||
|
||
post = connection.exec_params("INSERT INTO peeps (message) VALUES('#{message}') | ||
RETURNING id, message, peep_date;") | ||
Peeps.new(id: post[0]['id'], message: post[0]['message'], date: post[0]['peep_date']) | ||
end | ||
|
||
# def self.filter(filter:) | ||
# if ENV['ENVIRONMENT'] == 'test' | ||
# connection = PG.connect(dbname: 'chitter_test') | ||
# else | ||
# connection = PG.connect(dbname: 'chitter') | ||
# end | ||
|
||
# connection.exec_params("SELECT * FROM peeps WHERE peeps.message LIKE '%#{filter}%'") | ||
# end | ||
Comment on lines
+37
to
+45
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's always a good idea to remove commented out code from code you submit for code review (anywhere, not just at Makers) |
||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
feature 'posting a new peep' do | ||
scenario 'A user can post a peep to chitter' do | ||
visit('/new_peep') | ||
fill_in('message', with: 'Today was a great day') | ||
click_button('Post') | ||
|
||
expect(page).to have_content("Today was a great day") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nice feature test! |
||
end | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
feature 'Viewing peeps' do | ||
scenario 'A user can see all peeps' do | ||
Peeps.create(message: "Today was a great day") | ||
Peeps.create(message: "Today was a greater day") | ||
Peeps.create(message: "Today was the greatest day") | ||
|
||
visit('/') | ||
|
||
expect(page).to have_content('Today was a great day') | ||
expect(page).to have_content('Today was a greater day') | ||
expect(page).to have_content('Today was the greatest day') | ||
Comment on lines
+9
to
+11
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since you added the date feature, there should also be a feature test for that. |
||
end | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
require 'peeps' | ||
|
||
describe Peeps do | ||
describe '.all' do | ||
it 'returns all peeps' do | ||
connection = PG.connect(dbname: 'chitter_test') | ||
|
||
# connection.exec("INSERT INTO peeps (message) VALUES('Hey, Welcome to my chitter page');") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Best to delete old notes if not required |
||
Peeps.create(message: "Hey, Welcome to my chitter page") | ||
peeps = Peeps.all | ||
|
||
expect(peeps[0]).to be_a Peeps | ||
end | ||
end | ||
|
||
describe '.create' do | ||
it 'creates a new peep' do | ||
peep = Peeps.create(message: 'Today was a great day') | ||
|
||
expect(peep).to be_a Peeps | ||
expect(peep.message).to eq 'Today was a great day' | ||
expect(DateTime.parse(peep.date)).to be_an_instance_of(DateTime) | ||
end | ||
end | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
<!DOCTYPE html> | ||
|
||
<html> | ||
<head> | ||
<link rel="stylesheet" type="text/css" href="/CSS/index.css"> | ||
</head> | ||
|
||
<body> | ||
<nav class="topnav"> | ||
<h1 class="logo"> | ||
<span>CHITTER</span> | ||
</h1> | ||
</nav> | ||
|
||
<div class="peepContainer"> | ||
<h2>Posts: </h2> | ||
<ul> | ||
<% @peeps.each do |peep| %> | ||
<li class="peepMessage"> | ||
<%= peep.message %> | ||
<br> | ||
<br> | ||
<p class="createdOn">Created on <%= peep.date %></p> | ||
</li> | ||
<% end %> | ||
</ul> | ||
</div> | ||
|
||
<div class="createPeepCon"> | ||
<h3><a class="createPeep" href="/new_peep">New Peep</a></h3> | ||
</div> | ||
</body> | ||
</html> |
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.
If you'd like to use more standard names for you routes, check out this blog post on RESTful routing: https://medium.com/@shubhangirajagrawal/the-7-restful-routes-a8e84201f206