Giter VIP home page Giter VIP logo

msa-order's Introduction

msa-order

Codacy Badge CodeFactor

It's a minimal example of a microservice which manipulates the 'Orders'.

What It Does

  • gets a list of orders
    • shows the details of the product instead of the product ID only
  • finds if a specific product is used in an order
  • gets an order by the ID
    • shows the details of the product instead of the product ID only
  • places an order with a single product
    • an order can't be made with non-existing product
  • changes an order
    • an order can't be made with non-existing product
  • deletes an order

Related Repositories

  • Another microservice about 'Products': msa-product
  • The frontend to test the microservices: msa-demo

msa-order's People

Contributors

attacktive avatar

Watchers

 avatar

msa-order's Issues

Avoid Throwing `NullPointerException`

Why is this an issue?

Since: PMD 1.8

Avoid throwing NullPointerExceptions manually. These are confusing because most people will assume that the virtual machine threw it. To avoid a method being called with a null parameter, you may consider using an IllegalArgumentException instead, making it clearly seen as a programmer-initiated exception. However, there are better ways to handle this:

Effective Java, 3rd Edition, Item 72: Favor the use of standard exceptions > >Arguably, every erroneous method invocation boils down to an illegal argument or state, but other exceptions are standardly used for certain kinds of illegal arguments and states. If a caller passes null in some parameter for which null values are prohibited, convention dictates that NullPointerException be thrown rather than IllegalArgumentException.

To implement that, you are encouraged to use java.util.Objects.requireNonNull() (introduced in Java 1.7). This method is designed primarily for doing parameter validation in methods and constructors with multiple parameters.

https://app.codacy.com/gh/Attacktive/msa-order/issues/current?categories=ErrorProne

Restructure

The business logics are in the adapter layer which should be in the domain.

The Status Code Is Misleading

โฏ curl 'http://localhost:8081/orders' -v -H 'Content-Type: application/json' -d '{ "productId": 4 }'
* Host localhost:8081 was resolved.
* IPv6: ::1
* IPv4: 127.0.0.1
*   Trying [::1]:8081...
* Connected to localhost (::1) port 8081
> POST /orders HTTP/1.1
> Host: localhost:8081
> User-Agent: curl/8.8.0
> Accept: */*
> Content-Type: application/json
> Content-Length: 18
> 
* upload completely sent off: 18 bytes
< HTTP/1.1 500 
< Vary: Origin
< Vary: Access-Control-Request-Method
< Vary: Access-Control-Request-Headers
< Content-Type: application/json
< Transfer-Encoding: chunked
< Date: Wed, 05 Jun 2024 04:30:30 GMT
< Connection: close
< 
* Closing connection
{"message":"404 Not Found from GET http://localhost:8080/products/4","httpStatus":500}

I believe it should return 404 not 500.

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.