iiitl / iiitl/Stoxs

[fix]: Null Handling for getStockById

Open Beginner friendly
#3 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

easy fix java spring spring-boot
Dominant language
TypeScript
Stars
1
Forks
1
PR merge metrics
No merged PRs in 30d

Description

Description

  • Detailed Description:
    The method getStockById in OperationController returns null when no stock is found, which is not an informative response for API consumers. A proper HTTP 404 Not Found should be returned.
  • How to Solve:
    1. Use ResponseEntity:
      Modify the method to return a ResponseEntity so that you can control the HTTP status.
    2. Check for Null:
      If the stock is null, return a 404 response:
      @GetMapping("/{id}")
      public ResponseEntity<Stock> getStockById(@PathVariable Long id) {
          Stock stock = operationService.getStockById(id);
          return (stock != null) ? ResponseEntity.ok(stock) : ResponseEntity.notFound().build();
      }
      
    3. Test the Endpoint:
      Use tools like Postman or cURL to ensure that a non-existent stock ID returns a 404 status.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in OperationController at the getStockById endpoint and inspect how it calls operationService.getStockById. Make the endpoint return HTTP 404 when no stock is found and verify the behavior for an existing and a nonexistent ID with Postman or cURL.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, spring-boot
Domain
api, backend
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
68/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.