In the previous milestone (Milestone 5), I successfully developed the database for the property management system using Ruby on Rails. This involved creating the necessary tables and establishing their relationships to ensure smooth data management.
In today's milestone (Milestone 6), I will develop and test the essential API endpoints that enable the Create, Read, Update, and Delete (CRUD) functionalities for both users and houses.
Creating and Testing API endpoint for users and Houses
For Users
Thanks to the scaffold feature provided by Ruby on Rails, the user's table was automatically equipped with the required API endpoints. This means I can now create, read, update, and delete a user.
To enhance the integrity and reliability of the system, I added various associations for each table. This ensures that the relationships between entities are accurately represented and maintained throughout the application.
I also added validation rules for user and house models. For instance, attributes such as name, email, and password were made mandatory, ensuring that crucial information is provided before a user can be successfully created in the database.
I test the create and read API endpoints using a vscode extension called Thunder client which works exactly like Postman as shown below respectively.
For Houses
I implemented a nested attribute within the house parameters of the controller.
This simultaneously creates records of the related tables to the house table. Here is a screenshot of how I did it.
I test the create house API endpoint as shown below.
I modify the index method in the house controller to return the attributes of all the related tables as shown below.
I test the read house API endpoint as shown below.
Overcoming Challenges
- Throughout this milestone, I encountered some challenges that required thoughtful problem-solving. Two key hurdles I faced involved implementing the nested attribute in the house parameters and returning results from all other tables in the house controller. To overcome these obstacles, I conducted my research and found this article that provided valuable guidance. By leveraging the knowledge acquired, I successfully resolved these challenges, ensuring the smooth functioning of the system.
In my next milestone, I will be focusing on implementing authentication and authorization, improving the application's security and user privacy. Stay tuned for more updates!