I created a Github repo for this coding challange.
The master branch includes the OrderController as was sent to me via the emailed order_api_cs.txt file.
My solution for this Coding Challange can be seen in this Pull Request:
https://github.com/pell-je/CodingChallange/pull/1/files
I will delete this repository when my application for the software positon is closed or when I am requested to do so.
- The Id was being set with a Random. This is not a reliable way to generate ids. The random could generate a value that is already used.
- The return value of Random.Next is an int. The ID value of the Order entity is a string.
- A semi-colon is needed after the last curly brace when instantiating the Order object.
- The AppDbContext does not exsist.
- I removed setting the Id in the backend. I left the database to use auto-increment/identity to set it.
- I changed the Id type of the Order entity to a long. This is a much better type for an entity that will likly be stored in a database. A string Id could also be used, especially if its used in a nosql database. I choose to use a long here. The Id database column could be a BIGINT if using a sql database.
- I added a semi-colon.
- I created a class for AppDbContext and added it to the dependency injection container.
- Use a service layer to access the database. Using a service layer in the controller allows for code reuse and decouples logic.
- Use swagger/OpenAPI to test endpoints easily.
- Use the ControllerExceptionFilter to handle exceptions globally
- Use the required keyword to reduce null pointer exceptions
- Validate entities before saving to database
- Add Test Coverage for OrderContoller and OrderService
- Remove commented out code for the Update functionality in OrderController