diff options
| author | Gunther6070 <haydenhartman10@yahoo.com> | 2025-02-16 13:15:27 -0500 | 
|---|---|---|
| committer | Gunther6070 <haydenhartman10@yahoo.com> | 2025-02-16 13:15:27 -0500 | 
| commit | 384ba7ea4205196085a060b18db43f29aac3079b (patch) | |
| tree | 941432296cf97a62d07d333141ed86983651a43f /ufund-api/src/main/java/com | |
| parent | 3707c91f4c260cede04ddff7e7270057cb628798 (diff) | |
| download | JellySolutions-384ba7ea4205196085a060b18db43f29aac3079b.tar.gz JellySolutions-384ba7ea4205196085a060b18db43f29aac3079b.tar.bz2 JellySolutions-384ba7ea4205196085a060b18db43f29aac3079b.zip  | |
Implemented getNeed method
Diffstat (limited to 'ufund-api/src/main/java/com')
| -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("")  | 
