Krishnan's Personal Website


Home | About | Blog | Interesting Reads | Tutorials | Skills | Personal Projects | Books | Fun | Connect with me


Building create Chuckle api


Published On: Jul 08 2023
Written By: Krishnan Sethuraman
Category: Building Chuckle


The exciting time in Building Chuckle has started. From now onwards there will be lots of code to write. I don’t know why but for some reason writing code is my favorite activity. 

Last weekend I did some planning in terms of what features I will be building as part of Phase 1.

You can read more about Planning Chuckle features here

With that in mind the plan for this week was to create chuckle api. Before beginning to code I did some basic planning on what tables I need and what their structure should be. 

Please note that though I have a basic idea on how the overall DB structure would look like, I am not creating all the tables on day 1. I will only create tables for the task I am working on. 

With that being said, I deleted some unwanted default migrations and create new migrations. 

$ php artisan make:migration create_users_table
$ php artisan make:migration create_cuckles_table

After the migrations I also created some controllers and models. 

$ php artisan make:controller ChucklesController
$ php artisan make:model Users
$ php artisan make:model Chuckles

Though it is optional I always like adding the table name to the models as it makes things easier if you want to double check the table name while writing code. 

At this point I did not have a database. So I went ahead and created it and updated the .env file with the database name and mysql username and password. 

$ mysql -u username -p 
> create database chuckledb;

The next step was to add columns to the migrations file created above, which I did and ran migrate command to build the database. 

$ php artisan migrate

With the tables created I wanted a temporary user. I do not have any plans of building a login and signup feature. However I do have planed a feature that will help me in indentifying unique users. But for the time being to indetify Chuckles form a particular user I am using a temporary user account which I created manually with INSERT command.

> INSERT INTO users (fname, lname, email, username, user_key, password, created_on) VALUES ('Elon', 'Musk', 'hiddendata', 'ElonMusk', hiddendata, 'hiddendata', '2023-07-08'); 

I will be using this user’s id hard coded into the code base for the time being. However later in the project I will introduce an authentication module to identify unique users and this temporary user will be retired. 

Some decisions taken

Using uuids

I wanted to use uuids instead of ids for users and chuckles. However uuids take more memory compared to ids and as this is just a demo project with zero possibility of production roll out I decided to stick with id to ensure low resource consumption. 

Deploying to the server

I will only be deploying Chuckle to the server at the end of Phase 1. I have taken this decision so that when I launch Chuckle it should have some basic features. After Phase 1 I will release new changes in frequent intervals. 

The pull request for this can be found below. 

Building create Chuckle api