diff options
| -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 1fdd435..8af3fee 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;      /** @@ -36,9 +34,25 @@ public class CupboardController {          }      } +    /** +     * 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("/")  | 
