Comments (2)
Although this is a bit of an edge case - because it would probably only happen on a fresh database with no orders in it - I do think that returning a 200 OK response with an empty dataset is preferable in this case.
There are currently two client app pages that display order information: the Store,BlazorWasm shows a customer their previous orders (Pages/Account/Orders.razor) and in Admin.BlazorServer there is a page that shows admins a list of all orders (Pages/Orders/CustomerOrders.razor), which can be filtered via a dropdown.
Both of those pages are actually already set up to deal with empty datasets being returned. They initially create an order list object as null, then there is branching logic to display a list of orders if the object becomes non null and the count of orders is > 0. If it is not null and the order count is 0, then it displays 'no orders were found'. If the order service (which makes the HTTP request to the API) throws an exception, the error message variable is filled and that is displayed on screen instead.
Looking at the Orders Controller in the Ordering API, it feels as if there was some rather careless copying and pasting of methods, but if the two methods that return lists of orders are changed to return a 200 OK with an empty list instead of a 404, then I think everything else will probably continue to work as intended.
from fotostoriomicroservices.
While I was working on this, I noticed another little quirk in the Ordering API.
There are two methods in the order repository that return lists of orders to the controller endpoint methods that I mentioned above. The repository methods use LINQ to return orders via the db context, but they both end with a ToListAsync(), which always returns a list even if no items are found.
The null checks after this were obviously never being hit. It didn't matter because AutoMapper was handling the data returned to the controller methods either way, but I wanted it to be clear to the controller if there were no orders found so that it could intentionally return an empty list of orders (and perhaps log this fact for informational purposes).
As a result, I changed the null check for a check on the count of items in the list of orders, returning null if it equals zero.
from fotostoriomicroservices.
Related Issues (20)
- Product details and Inventory HOT 5
- Time to consider .NET 7 HOT 4
- Extending Serilog and Seq to all projects
- Marketing client application HOT 2
- Email confirmation when registering
- Exception Middleware HOT 1
- Integration Tests using SQL Server and EF
- Use OpenIddict for identity HOT 1
- Identity API refactor in Accounts Controller
- Update to .NET 8 HOT 2
- Breaking changes in .NET 8 Docker images HOT 1
- Health Checks failing & missing icons HOT 2
- Migrate gateways from Ocelot to YARP? HOT 1
- Use of AutoMapper in Discount Grpc HOT 1
- Basket API and AutoMapper
- Adding an Ordering/Marketing Aggregator?
- Stripe API updates HOT 2
- Move site images from imgbb.com HOT 2
- Hard-coded image references should be dynamic
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from fotostoriomicroservices.