Practical Approach: This project, to be completed in one day, aims to quickly validate a concept focusing on presence management in a housing unit. The concept will be implemented through a Ruby API, allowing both the listing of absences and the injection of presence periods associated with one or more housing units.
Objectives to Validate:
Question 1: Calculate absences associated with a housing unit based on initially submitted presence records and provide an endpoint to return them.
Question 2: Provide an endpoint to update the recorded absences.
Contextual Approach: For this test, the discovery of a new framework will be considered, with a strong need to explain the choices made and the different steps involved.
Step 1: Architecture / Project Initialization
- Build a Rails project in API mode. Ruby version
3.3.3
& Rails version7.7.2.beta3
- Create the
Studio
class. - Create the
Stay
class containing a start and end date.
Step 2: Persistence and Data
- Create the database (SQLite or PostgreSQL).
- Initialize the data (Seeds).
Step 3: Business Logic Implementation and Validation
- The
Stay
class is a dependent reference of theStudio
class. - The start date is mandatory.
- The end date must be after the start date.
Step 4: Providing Absences by Studio
- Create a
Studios
controller. - Create an internal function for calculating absences
- Generate an absences array per studio and provide it as a JSON output.
Step 5: Allow Updating Studio Presence Records
- Create a
Stays
controller. - Create a
Create
method to handle an HTTP POST request, which receives a list of absences and returns the execution result. - Implement the
Create
method to introduce new presence and absence periods based on the provided dates.
Step 6: Expose New Interactions and Test Them
- Update the application routes.
- Use Postman or curl to make a GET request to
http://XXXX/studios
. - Use Postman or curl to make a POST request to
http://XXXX/stays
(Content-Type: application/JSON); Body: { }. - Add RSpec test
Toolbox
- Run project
gem install bundler bundle install rails db:create rails db:migrate rails db:seed rails server
- (Altenative) Run RSpec tests
bundle exec rspec