Skip to content

Instantly share code, notes, and snippets.

@d30jeff
Created February 12, 2016 13:34
Show Gist options
  • Save d30jeff/23d993a672c06b53c846 to your computer and use it in GitHub Desktop.
Save d30jeff/23d993a672c06b53c846 to your computer and use it in GitHub Desktop.
Pseudocode for Alphalab
Hi,
Due to hardware limitation I'm afraid I have to write a pseudocote for this task.
If neccessary, I am willing to go there to code it in front of you guys, with your computers.
Here's my way of solving this particular problem.
Note that this current solution doesn't escape or sanitize user input, SQL injection is very possible at this point.
Database Design:
Database name: test-database
Table: employees
Column:
- id (primary key, 3)
- first_name (varchar, 50)
- last_name (varchar, 50)
- ic_no (varchar, 16)
- email (varchar, 255 [Reason: some people have looong email address], unique, nullable)
- mobile_no (varchar, 14, unique)
- address_line1 (varchar, 100)
- address_line2 (varchar, 100, nullable)
- created_on (date)
- updated_on (date, nullable)
- created_by (int, 3)
- updated_by (int, 3, nullable)
- edit_seq (integer,3)
- active(bool/boolean, default true)
Flow:
- HTML form with these fields:
first name, last_name, ic_no, email, mobile_no, address_line1, address_line2, active
Creation:
1) establish connection to database.
2) check if email exists. if exists, show already exists message without inserting.
3) check if mobile_no exists. if exists, show already exists message without inserting.
4) if email and mobile_no do not exists, insert fields to database with the *_by to be the id of currently logged in user.
5) close connection, flash message successfully inserted.
Edit:
1) (Own data) Select fields from table where unique id equals to currently logged in user's session_id.
2) (Other users') Select fields where unique id equals to corresponding primary key.
Take the data and fill the value in HTMl forms.
Update:
1) check unique for email and mobile_no, if fails, flash message for unique to users.
2) check edit_seq no to match current value, if it doesn't match, throw edit-conflict error message.
3) update column set (fields, values) [updated_by is the currently logged in user that's updating] where id is matching the corresponding id.
Delete:
1) check if user is authorized to delete the user.
if yes:
delete from table where id is equal to corresponding row.
else:
flash 'action error' to user.
Search:
First example without any filtering:
1) select fields from table where first name or last name like '%search_query%'.
2) select num_row of fields from the previous query, if there is any,
fetch the associative array from the query and display as a list.
3) if no result if found, return message:
"No result found for '{$search_query}."
Second example with active filtering:
1) select fields from table where first name or last name like '%search_query%' and 'active' is true.
2) select num_row of fields from the previous query, if there is any,
fetch the associative array from the query and display as a list.
3) if no result if found, return message:
"No result found for '{$search_query}."
AJAX: for both create and update
1) create a onChange event handler to submit an ajax request with the value of corresponding fields, check their existense against the current database, if exists,
return "'{input}' already exists."(red) error, else return "'{field}' is available"(green).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment