diff options
| author | Gunther6070 <haydenhartman10@yahoo.com> | 2025-02-16 14:14:06 -0500 | 
|---|---|---|
| committer | Gunther6070 <haydenhartman10@yahoo.com> | 2025-02-16 14:14:06 -0500 | 
| commit | 02375260e51380499f3c7e2e5abbabf606fdd0c8 (patch) | |
| tree | 617236ea85fd331e9c58e943d1f703dcaa396ad2 /ufund-api/src/main/java/com/ufund/api | |
| parent | 5e073d64d3d364c090f21c5e34ae273955009a1a (diff) | |
| download | JellySolutions-02375260e51380499f3c7e2e5abbabf606fdd0c8.tar.gz JellySolutions-02375260e51380499f3c7e2e5abbabf606fdd0c8.tar.bz2 JellySolutions-02375260e51380499f3c7e2e5abbabf606fdd0c8.zip  | |
Implemented getNeeds method
Diffstat (limited to 'ufund-api/src/main/java/com/ufund/api')
| -rw-r--r-- | ufund-api/src/main/java/com/ufund/api/ufundapi/controller/CupboardController.java | 22 | 
1 files changed, 18 insertions, 4 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 106b2e0..255eba0 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 @@ -11,13 +11,11 @@ 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("") @@ -25,9 +23,25 @@ public class CupboardController {          cupboard.createNeed(need);      } +    /** +     * Responds to the GET request for all {@linkplain Need needs} +     *  +     * @return ResponseEntity with array of {@link Need needs} objects (may be empty) +     *         and +     *         HTTP status of OK<br> +     *         ResponseEntity with HTTP status of INTERNAL_SERVER_ERROR otherwise +     */      @GetMapping("") -    public Need[] getNeeds() { -        return cupboard.getNeeds(); +    public ResponseEntity<Need[]> getNeeds() { +        LOG.info("GET /needs"); + +        try { +            Need[] needs = cupboard.getNeeds(); +            return new ResponseEntity<>(needs, HttpStatus.OK); +        } catch (IOException e) { +            LOG.log(Level.SEVERE, e.getLocalizedMessage()); +            return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR); +        }      }      @GetMapping("/")  | 
