Implementation of the Stock Take Command

After finishing up the logic of the update command and doing the unit testing as well, I moved on to the accept command. The accept command involve a few logic where the accept command will take the list of item in stock take and compare it to the existing item location and update the stock quantity. To ensure that the process of updating the stock quantity of the item location is not executed properly, the entire logic is put inside of transaction so that any error that occurred will roll back any changes made.

Next, in order to compare the item in stock take and existing item location, an algorithm was needed. After doing some research online, I found LINQ to be somewhat suitable for the job. Then, I tried to implement the LINQ and tested it out and it worked. During the testing of the accept command, I encounter an error where another transaction was being created while the first transaction was still going on. After discussing with Mr. Peter, I was able to fix the error.

Lastly, after some discussion with Mr. Peter regarding the logic of the accept command, I needed change it so that the update process can be done much more faster. I also needed to stress test the LINQ algorithm to see how long it will take for the algorithm process a large amount of data.

Further Development of The Stock Take Feature

In this week, I managed to complete the create command of the stock take API. Moving on to the next part, I managed to finish the update and delete command together with the queries as well. In the delete command, the command will take the stock take id as an input. A unit test was done to ensure that the delete command was working properly.

After that, the queries for the stock take was either query to get the list of stock take or get the stock take by the id. Similarly, unit test was also made for the queries as well. In the get stock take list query, the stock take will have an item count to show to the user how many there are in the stock take. While, get stock take by id will have the list of item display with it.

Lastly, the logic of the update command was rework again after discussing with Mr.Peter. The rework was to ensure that every time the stock take item is updated that it wouldn’t crash the software. Currently, I’m still working on the reworking the logic of the update command, After that is done, I only have the accept command left for the stock take.

Implementation of Stock Take Feature

After finishing the stock feature of the sandbox application, I was assigned to create the stock take feature next. Inside the stock take feature will have the create, update, delete and accepted commands together with the get stock take list and get stock take by id queries. The first thing that I need to work on was the create the entity relationship diagram (ERD).

After finalizing the ERD, I moved on to creating the API of the stock take. The part that I am currently working on is the create stock take command. After figuring out what the user need to input for the create command, I moved on to the create command handler. After completing the command handler, I moved on to the validation and the response of the command.

Next, I created the unit testing for the create command and tested out the POST method of the create command. After running the test, the test resulted in a bad gateway result. Then I went to debug the code itself. After sometime, I found out that in the create command handler there was a null exception when I tried to map the child class of the stock take. Currently I am working on trying to resolve the bug.

Introduction to WPF

On the forth week of my internship, I was introduce to WPF. WPF is the main UI component of the sandbox application that I was working on. After going through an introduction of it together with prism. The main design pattern used when developing the WPF page was the MVVM model where the code that implement the business logic is separated from the UI code where it usually consist of the view and view model.

Afterward, I have to convert the existing feature of the stock threshold so that it uses the API end point that I have created previously. Firstly, I registered the container which will connect to the API. The first page I was working on was the page which display the list of the stock threshold. In this page, the entire list of the existing stock threshold from the database will be display to the user. Not only that, I also added a feature to allow the user search for the desired stock threshold through the item name search bar.

Next, when I tried running the application and navigated to the stock threshold page, the code return a 404 not found response. I realized that the container was mapped to the wrong API end point which resulted in 404 not found response. After registering the proper API end point, the page was able to display the stock threshold list.

Lastly, the next page I was working was the page which is responsible for the create, update and delete of the stock threshold. At first, I was having some difficultly in understanding the code. After some guidance, I was able to figure out what needed to do. The mapping of the data was mainly done with the Auto Mapper.

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.

Second Week in Tong Hin

On the second week of my internship, I begin to dwell deeper into the concept like ASP.NET Core, RESTful API and TDD. In ASP.NET Core, I learned the best practices to use whenever I work with the framework. Not only that, in ASP.NET Core, I learned on how to create an API where API allow for communication between 2 different application that uses different programming language. Lastly is the mediator pattern and CQRS. The mediator pattern is how two object communicate between each other and this promote loose coupling between the 2 objects. CQRS is the separation between the command model and query model where the command model is usually the create, update and delete operation which can change the data but doesn’t return data to the user. Meanwhile, the query model is the read operation in which it doesn’t change the data and return a result to the user.

The RESTful API is the communication between to application when it’s based on the CRUD (Create, Read, Update and Delete) operation. In an API, the client will send a request to the server through the API using the HTTP method like GET, POST, PUT and DELETE request. Afterward, the API will then fetch the appropriate data and send it back to the client. The REST is the constraint applied when creating the API. The constraints are usually, client-server architecture, stateless, cache-able, uniform interface and layered system.

Lastly is the concept of Test Driven Development (TDD). In TDD, the development of a software usually start with the testing first. The cycle of TDD involve creating a failing test first then applying the logic of the code to make the test green. Finally the last part of the TDD cycle is to refactor the code to make sure the code is clean. The process is then repeated again for the other part of the code. TDD allow for easier to test to code and provide a fast feedback to know whether or not the logic is working properly.

First week of Internship at Tong Hin

The first week I spent at the company was mainly focusing on learning the technology that will be used in the subsequent week. First thing I learnt was how to use git. In git, I learned the command in git, how to create repository, committing to changes, merging repositories and push any changes made in the repositories.

Next, I also touch up on my C# fundamentals again in order to fully prepare myself to learn the new concepts as listed below. From the C# fundamental course, I revised on the syntax used in C#, how to work on the classes and objects, testing my code through unit testing, differentiating between reference types and value types and the object oriented programming in C# as well.

Lastly, I was introduced to the concept of asynchronous programming. Asynchronous programming allow for 2 operations, operation A and operation B, which doesn’t depend on each other to run asynchronously when compare to synchronous programming which has to wait for operation A to finish first then it will execute the operation B. Asynchronous programming mainly uses the keyword async, await and task. The other concepts that I have briefly gone through are ASP.NET Core, RESTful API and Test Driven Development(TDD).