diff options
author | sowgro <tpoke.ferrari@gmail.com> | 2025-02-16 13:28:28 -0500 |
---|---|---|
committer | sowgro <tpoke.ferrari@gmail.com> | 2025-02-16 13:28:28 -0500 |
commit | 43523d16696b0dcbbd1d44af3e31f08de702d921 (patch) | |
tree | 44dc309cc6b58155b65f068da5f9bf16ca662848 /ufund-api | |
parent | a4aa226955df2284a298b6ae35ee72d4996978a3 (diff) | |
parent | 384ba7ea4205196085a060b18db43f29aac3079b (diff) | |
download | JellySolutions-43523d16696b0dcbbd1d44af3e31f08de702d921.tar.gz JellySolutions-43523d16696b0dcbbd1d44af3e31f08de702d921.tar.bz2 JellySolutions-43523d16696b0dcbbd1d44af3e31f08de702d921.zip |
Merge remote-tracking branch 'origin/main'
Diffstat (limited to 'ufund-api')
-rw-r--r-- | ufund-api/src/main/java/com/ufund/api/ufundapi/controller/CupboardController.java | 37 |
1 files changed, 34 insertions, 3 deletions
diff --git a/ufund-api/src/main/java/com/ufund/api/ufundapi/controller/CupboardController.java b/ufund-api/src/main/java/com/ufund/api/ufundapi/controller/CupboardController.java index c99a95b..27185b0 100644 --- a/ufund-api/src/main/java/com/ufund/api/ufundapi/controller/CupboardController.java +++ b/ufund-api/src/main/java/com/ufund/api/ufundapi/controller/CupboardController.java @@ -1,19 +1,27 @@ package com.ufund.api.ufundapi.controller; +import java.util.logging.Level; +import java.util.logging.Logger; + import com.ufund.api.ufundapi.model.Cupboard; import com.ufund.api.ufundapi.model.Need; + +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.*; +import java.io.IOException; import java.util.ArrayList; @RestController @RequestMapping("cupboard") public class CupboardController { + private static final Logger LOG = Logger.getLogger(CupboardController.class.getName()); private ArrayList<Need> needs; private Cupboard cupboard; @PostMapping("") - public void createNeed(@RequestBody Need need) {; + public void createNeed(@RequestBody Need need) { cupboard.createNeed(need); } @@ -27,9 +35,32 @@ public class CupboardController { return cupboard.findNeeds(name); } + /** + * Responds to the GET request for a {@linkplain Need need} for the given id + * + * @param id The id used to locate the {@link Need need} + * + * @return ResponseEntity with {@link Need need} object and HTTP status of OK if found<br> + * ResponseEntity with HTTP status of NOT_FOUND if not found<br> + * ResponseEntity with HTTP status of INTERNAL_SERVER_ERROR otherwise + */ @GetMapping("/{id}") - public Need getNeed(@PathVariable int id) { - return cupboard.getNeed(id); + public ResponseEntity<Need> getNeed(@PathVariable int id) { + LOG.log(Level.INFO, "GET /need/{0}", id); + + try { + Need need = cupboard.getNeed(id); + if (need != null) { + return new ResponseEntity<>(need, HttpStatus.OK); + } else { + return new ResponseEntity<>(HttpStatus.NOT_FOUND); + } + + } catch (IOException e) { + LOG.log(Level.SEVERE, e.getLocalizedMessage()); + return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR); + } + } @PutMapping("") |