[fix]: Null Handling for getStockById
Open
Beginner friendly
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 methodgetStockByIdinOperationControllerreturnsnullwhen 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:
- Use ResponseEntity:
Modify the method to return aResponseEntityso that you can control the HTTP status. - Check for Null:
If the stock isnull, 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(); } - Test the Endpoint:
Use tools like Postman or cURL to ensure that a non-existent stock ID returns a 404 status.
- Use ResponseEntity:
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- 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