Chitter Challenge and Half Way!
Chitter
Today we started the Friday challenge, which this week was to create a Twitter-like program, called Chitter. Here was our brief:
Features:
USER STORIES
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
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. samm@makersacademy.com, 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.
After doing the Bookmark Manager through the week, todays challenge wasn’t too bad. It worked in a very similar way; instead of saving bookmarks it is posting ‘Peeps’, users had to now include username and name as well as email and password, tags still worked in roughly the same way, and comments would be similar to replies on chitter.
I set up in much the same way as in Bookmark Manager, creating the database and test database, setting up the web and spec helpers, and writing the first basic test to see if it works.
Working from there I added the functionality user story by user story. I managed to complete all the stories bar 2; tagging someone should email them (I am not really sure how to do this, I might look into it next week), and the css, currently it still looks awful!
One of the differences between Bookmark Manager and Chitter was the verification that an email address or username hadn’t already been used. This meant I had to add them to the sign up process, then check the database to see if they existed. Here is the updated code to make this happen:
def self.create(email:, password:, name:, username:)
emailcheck = DatabaseConnection.query("SELECT * FROM users WHERE email = '#{email}';")
return "Email Taken" if emailcheck.any?
usernamecheck = DatabaseConnection.query("SELECT * FROM users WHERE username = '#{username}';")
return "Username Taken" if usernamecheck.any?
encrypted_password = BCrypt::Password.create(password)
result = DatabaseConnection.query("INSERT INTO users (email, password, name, username) VALUES('#{email}', '#{encrypted_password}', '#{name}', '#{username}') RETURNING id, email, name, username;")
User.new(id: result[0]['id'], email: result[0]['email'], name: result[0]['name'], username: result[0]['username'])
end
Basically it runs the username and email entered through the database to see if they already exist and returns an error if they do. Here is how that looks:


I did something similar with tags, as if someone has been tagged on a post already I don’t want them to be tagged again. The code in the controller had to be a little different for this one though. As you can post without a tag, the post is created no matter what the status of the tag is. I couldn’t simply have it error if the tag is being used, as the post would still be created. To get round this I made it so if there was an error, it deleted the post that had just been made, so it would never actually get posted:
post '/peeps' do
@peep = Peeps.create(message: params[:peep], user_id: session[:user_id])
if params[:taggeduser] != ""
tagged = Tags.create(tag: params[:taggeduser], id: @peep.id)
if tagged == 'Username Not Found'
Peeps.delete(id: @peep.id)
flash[:notice] = 'Username Not Found'
redirect back
elsif tagged == 'Already Tagged'
Peeps.delete(id: @peep.id)
flash[:notice] = 'Already Tagged'
redirect back
else
redirect '/peeps'
end
end
redirect '/peeps'
end
Half Way Through!
Today was the end of our 6th week here at Makers Academy. That means we are now officially half way through our 12 week course. I cannot believe how fast it has gone, it has really flown by so quickly, and I have really enjoyed every second of it. Whilst I am very nervous about the fact that in another 6 weeks we will be starting our proper jobs, I look back at how much I have already learnt in the past 6 weeks and this reassures me that when that time comes, I will be ready for it. If I told myself 6 weeks ago that I would be able to make a simple twitter clone in a day on my own, I wouldn’t have believed that, so clearly a lot can change in 6 weeks!
The other group of apprentices have also now officially left, which means we are now the only cohort left in the office! That means when the next lot starts in a couple of weeks, we will be the senior cohort, and they will be looking at us as if we know what we are doing like I did when I started. That’s also a scary thought, but hopefully I will be ready for that too!
Todays song of the day:

