Scheduler Challenge

Source: https://github.com/wheniwork/standards/blob/master/project.md

REST Scheduler API

While we will accept a framework of your choice, and a language of your choice, we highly encourage using PHP* and one of the following frameworks: Spark, Radar, or Proton.

If you choose to use another language, please be prepared to show fluency in multiple languages (including at least one C-family language), and knowledge of multiple design principles (DRY, Open/Closed, etc) and patterns (Factory, DataMapper, etc).

* Our core application is written almost entirely in PHP and JS.

Requirements

The API must follow REST specification:

  • POST should be used to create
  • GET should be used to read
  • PUT should be used to update (and optionally to create)
  • DELETE should be used to delete

Additional methods can be used for expanded functionality.

The API should include the following roles:

  • employee (read)
  • manager (write)

The employee will have much more limited access than a manager . The specifics of what each role should be able to do is listed below in User Stories.

Data Types

All data structures use the following types:

type description
int a integer number
float a floating point number
string a string
bool a boolean
id a unique identifier
fk a reference to another id
date an RFC 2822 formatted date string

Data Structures

User

field type
id id
name string
role string
email string
phone string
created_at date
updated_at date

The role must be either employee or manager. At least one of phone or email must be defined.

Shift

field type
id id
manager_id fk
employee_id fk
break float
start_time date
end_time date
created_at date
updated_at date

Both start_time and end_time are required. Unless defined, the manager_id should always default to the manager that created the shift. Any shift without an employee_id will be visible to all employees.

User stories

Please note that this not intended to be a CRUD application. Only the functionality described by the user stories should be exposed via the API.

  • [ ] As an employee, I want to know when I am working, by being able to see all of the shifts assigned to me.
  • [ ] As an employee, I want to know who I am working with, by being able see the employees that are working during the same time period as me.
  • [ ] As an employee, I want to know how much I worked, by being able to get a summary of hours worked for each week.
  • [ ] As an employee, I want to be able to contact my managers, by seeing manager contact information for my shifts.
  • [ ] As a manager, I want to schedule my employees, by creating shifts for any employee.
  • [ ] As a manager, I want to see the schedule, by listing shifts within a specific time period.
  • [ ] As a manager, I want to be able to change a shift, by updating the time details.
  • [ ] As a manager, I want to be able to assign a shift, by changing the employee that will work a shift.
  • [ ] As a manager, I want to contact an employee, by seeing employee details.

Scheduler Solution

The solution is the underlying API created in ShiftsController(link) and UserController(link) classes.

*NOTE: These buttons make AJAX requests (link) to the API, they are not just rendering static JSON results.

  1. As an employee, I want to know when I am working, by being able to see all of the shifts assigned to me.
  2. As an employee, I want to know who I am working with, by being able see the employees that are working during the same time period as me.
  3. As an employee, I want to know how much I worked, by being able to get a summary of hours worked for each week.
  4. As an employee, I want to be able to contact my managers, by seeing manager contact information for my shifts.
  5. As a manager, I want to schedule my employees, by creating shifts for any employee.
  6. As a manager, I want to see the schedule, by listing shifts within a specific time period.
  7. As a manager, I want to be able to change a shift, by updating the time details.
  8. As a manager, I want to be able to assign a shift, by changing the employee that will work a shift.
  9. As a manager, I want to contact an employee, by seeing employee details.

Example Request:

request

Example Response:

results

My Thoughts

Over all pretty simple and straight forward challenge, no tricks or anything like that. The only real issue I ran into was dumbing down the built in Yii2 ActiveController actions. By default the ActiveController offers all the basic CRUD options and the challenge states only the provided User Stories be exposed. I could have created my own class to handle the API curling but I just decided to use Guzzle instead.

It seemed logical, so I combined stories 1 and 4.

I like these types of "real world" challenges rather than "trick puzzles".

TODO:

  • Need to add authentication to the User API request
  • Story 1,2, and 4 currently retrieve all shifts (past & future) for the employee. By default it should search future shifts only but if a start and/or end date is supplied use that range instead.
  • Combine 2 with 1 & 4?