@@ -19,6 +19,15 @@ public void addProduct(String productId, String name) {
1919
2020 public String placeOrder (String productId , int quantity ) throws ProductNotFoundException {
2121 Product product = products .get (productId );
22+ /*the reason why i put the throw here is due to the fact that the product is being declared and we know in the test cases
23+ * that we are given a product id, what we dont know is if thaat productId is correct so technically speaking we should check
24+ * if the productId is matched up to the hashmap at all using get and if it doesnt exist then product will be null because no such key exists
25+ * instead of trying to put it in every single instance we see an order id or product id our test cases check to see if the given
26+ * input is even available for us to grab not if there is any input at all since that itself in my opinion would be front end and not us
27+ * that would handle that sort of thing before it reaches this point
28+ *
29+ * If you need me to delete comments I can i just wrote this out incase people look at any pr's for their own reasoning or what not
30+ */
2231 if (product == null ) {
2332 throw new ProductNotFoundException ("Product with ID " + productId + " not found" );
2433 }
@@ -35,6 +44,10 @@ public String checkOrderStatus(String orderId)
3544 throws OrderNotFoundException , ProductNotFoundException {
3645
3746 Order order = orders .get (orderId );
47+ // Since order is set at this exact moment all we need to do is check if the given id is in the hashmap and if it isnt we know
48+ //that it would return a null value if no such key exists, hence why we would see if order == null and if it is throw that error
49+ //we do this instead of having an error at each exact moment because we know in the test cases we are given an orderId we just need to make sure
50+ //on our end that it is correct, not if it exists.
3851 if (order == null ) {
3952 throw new OrderNotFoundException ("Order with ID " + orderId + " not found" );
4053 }
0 commit comments