Creating CRUD using CQRS Pattern (part 1)

This week marked the beginning of my opportunity to apply the knowledge that I gained from the courses that I learnt from the previous weeks. Mr. Peter gave me my first task: creating CRUD for an entity using CQRS pattern. However, before diving into the task at hand, it was necessary to set up the environment by launching the SandBox app, which Mr. Peter graciously guided me through. This included various debugging processes essential for successfully launching the system. First, I needed to create a database and import the existing tables into it. Then, cloned a git repository from an existing repository named Sandbox(which is the main solution used for trying out new features first before implementing it on a real application). There’s also another repo for context and modules under the main repository where this is the first I discover that there can be more repositories created under an existing git repository. 

Launching the Sandbox app took quite some time as there’s a bit of debugging needed which most of it was solved by Mr Peter. One of the issues that arose was due to my carelessness in setting up the credentials of the API. I unwittingly included a space in a word that was not supposed to have one, causing the issue of invalid authentication. From this experience, I learned a valuable lesson that even the slightest error, such as a space, can cause significant time wastage during debugging. As a result, I now realize the importance of paying attention to the smallest of details. 

Throughout the week when I’m completely lost on what to and what should I debug, I instead just go through the codes from an existing project to guide me through creating the CRUD for an entity while also watching the courses again to have deeper understanding on how the code works. Moreover, I learned about a new git method known as git stash, which allows you to temporarily shelve changes you’ve made to your working copy so that you can work on something else and then re-apply them later. When it came time to create the CRUD for the entity, I initially created all folders and pages at once for creating, updating, deleting, and getting information. However, Mr. Peter advised that it would be best to create them one by one and test each unit immediately to ensure the stability of the code before moving on to the next feature.

Overall, I am grateful for the opportunity to learn from Mr. Peter this week. While I feel that I did not make significant progress personally, I am eager to continue learning and growing. I look forward to the challenges that lie ahead, particularly in creating the CRUD for an entity next week.

Application of What I have Learnt

On the third week of my internship, I learnt on how to apply what I have learn so far. After setting up the sandbox application to practice the concepts like API, TDD and loose coupling. My task was to convert the stock threshold function of the existing app into an API. At the beginning, I was struggling to create the API for the stock threshold. After some guides from Mr Peter, I begin to understand on how to create the API.

Firstly, using the CQRS pattern, I separated the commands and the queries into separate files. In the queries folder contains the different Query which will return the entire list of the existing stock threshold to the user when it is called. Not only that, there’s also GetById Query which will return a stock threshold to the user based on the requested Id of the stock threshold.

Next, in the commands folder contains the create, update and delete functions for the stock threshold. The create command will take the item Id with the quantity for the stock threshold. Using the given item Id, the code will look for the item in the item database and map it to the stock threshold that was created.

Similar to the create command, the update command will take the stock threshold Id, item Id together with the quantity as well. In the update command, the code will take the item Id and check if the existing item Id is different with the inputted item Id. If the item Id is different, the code will look for the new item in the item database and update the existing item to the new one. As for the delete command, the user just has to input the stock threshold Id and the code will delete it. The Http method was implemented in the controller folder.

Lastly, the unit test was created for each of the function to make sure they are working properly. At the first, I was struggling to create the unit test as I was inexperience in creating unit test but after reference the other unit testing I was able to get the hang of it. The unit test was also accompany with some dummy data. All the unit test was able to pass without much problem.