GithubHelp home page GithubHelp logo

Comments (2)

DavidAJohn avatar DavidAJohn commented on July 20, 2024

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.

DavidAJohn avatar DavidAJohn commented on July 20, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.