aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAkash Keshav <112591754+domesticchores@users.noreply.github.com>2025-02-16 17:04:48 -0500
committerAkash Keshav <112591754+domesticchores@users.noreply.github.com>2025-02-16 17:04:48 -0500
commitad68ff259acd63818112b9997d093051dd3344ca (patch)
treeb958bf84f9afb794635f631c1d7072750170d80e
parentae0bff7e12edbd6f4e76cf32468f5d5607e770a6 (diff)
parentb25ec2813c14d21824e8d1af78ac478b35bac8bc (diff)
downloadJellySolutions-ad68ff259acd63818112b9997d093051dd3344ca.tar.gz
JellySolutions-ad68ff259acd63818112b9997d093051dd3344ca.tar.bz2
JellySolutions-ad68ff259acd63818112b9997d093051dd3344ca.zip
Merge branch 'main' of https://github.com/RIT-SWEN-261-02/team-project-2245-swen-261-02-2b
-rw-r--r--ufund-api/data/cupboard.json1
-rw-r--r--ufund-api/src/main/java/com/ufund/api/ufundapi/controller/CupboardController.java30
-rw-r--r--ufund-api/src/main/java/com/ufund/api/ufundapi/model/Cupboard.java51
-rw-r--r--ufund-api/src/main/java/com/ufund/api/ufundapi/model/Need.java16
-rw-r--r--ufund-api/src/main/java/com/ufund/api/ufundapi/persistence/CupboardFileDao.java2
-rw-r--r--ufund-api/src/main/resources/application.properties1
6 files changed, 31 insertions, 70 deletions
diff --git a/ufund-api/data/cupboard.json b/ufund-api/data/cupboard.json
new file mode 100644
index 0000000..4be246d
--- /dev/null
+++ b/ufund-api/data/cupboard.json
@@ -0,0 +1 @@
+[{"name":"Test","id":1,"maxGoal":100.0,"type":"PHYSICAL","filterAttributes":null,"Current":0.0}] \ No newline at end of file
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 3018ac1..5099bbe 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
@@ -3,9 +3,9 @@ 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 com.ufund.api.ufundapi.persistence.CupboardDAO;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
@@ -16,7 +16,16 @@ import java.io.IOException;
@RequestMapping("cupboard")
public class CupboardController {
private static final Logger LOG = Logger.getLogger(CupboardController.class.getName());
- private Cupboard cupboard;
+ private final CupboardDAO cupboardDAO;
+
+ /**
+ * Create a cupboard controller to receive REST signals
+ *
+ * @param cupboardDAO The Data Access Object
+ */
+ public CupboardController(CupboardDAO cupboardDAO) {
+ this.cupboardDAO = cupboardDAO;
+ }
/**
* Creates a Need with the provided object
@@ -27,7 +36,7 @@ public class CupboardController {
@PostMapping("")
public ResponseEntity<Need> createNeed(@RequestBody Need need) {
try {
- cupboard.createNeed(need);
+ cupboardDAO.createNeed(need);
return new ResponseEntity<>(need, HttpStatus.OK);
} catch (IOException ex) {
return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR);
@@ -47,7 +56,7 @@ public class CupboardController {
LOG.info("GET /needs");
try {
- Need[] needs = cupboard.getNeeds();
+ Need[] needs = cupboardDAO.getNeeds();
return new ResponseEntity<>(needs, HttpStatus.OK);
} catch (IOException e) {
LOG.log(Level.SEVERE, e.getLocalizedMessage());
@@ -71,8 +80,8 @@ public class CupboardController {
LOG.info("GET /need/?name="+name);
try {
- Need[] needArray = cupboard.findNeeds(name);
- return new ResponseEntity<Need[]>(needArray,HttpStatus.OK);
+ Need[] needArray = cupboardDAO.findNeeds(name);
+ return new ResponseEntity<>(needArray, HttpStatus.OK);
} catch (IOException e) {
LOG.log(Level.SEVERE,e.getLocalizedMessage());
return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR);
@@ -94,7 +103,7 @@ public class CupboardController {
LOG.log(Level.INFO, "GET /need/{0}", id);
try {
- Need need = cupboard.getNeed(id);
+ Need need = cupboardDAO.getNeed(id);
if (need != null) {
return new ResponseEntity<>(need, HttpStatus.OK);
} else {
@@ -118,7 +127,7 @@ public class CupboardController {
@PutMapping("")
public ResponseEntity<Need> updateNeed(@RequestBody Need need) {
try {
- need = cupboard.updateNeed(need);
+ need = cupboardDAO.updateNeed(need);
return new ResponseEntity<>(need, HttpStatus.OK);
} catch (IOException e) {
return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR);
@@ -130,13 +139,12 @@ public class CupboardController {
*
* @param id The need's ID
* @return OK if the need was deleted, NOT_FOUND if the need was not found, or INTERNAL_SERVER_ERROR if an error occurred
-
*/
@DeleteMapping("/{id}")
public ResponseEntity<Need> deleteNeed(@PathVariable int id) {
try {
- if (cupboard.getNeed(id) != null) {
- cupboard.removeNeed(id);
+ if (cupboardDAO.getNeed(id) != null) {
+ cupboardDAO.deleteNeed(id);
return new ResponseEntity<>(HttpStatus.OK);
} else {
return new ResponseEntity<>(HttpStatus.NOT_FOUND);
diff --git a/ufund-api/src/main/java/com/ufund/api/ufundapi/model/Cupboard.java b/ufund-api/src/main/java/com/ufund/api/ufundapi/model/Cupboard.java
deleted file mode 100644
index 0ce015c..0000000
--- a/ufund-api/src/main/java/com/ufund/api/ufundapi/model/Cupboard.java
+++ /dev/null
@@ -1,51 +0,0 @@
-package com.ufund.api.ufundapi.model;
-
-import com.ufund.api.ufundapi.persistence.CupboardDAO;
-import com.ufund.api.ufundapi.persistence.CupboardFileDao;
-
-import java.io.IOException;
-
-public class Cupboard {
- CupboardDAO dao = new CupboardFileDao();
-
- public void createNeed(Need need) throws IOException {
- int id = dao.getNeeds().length;
- dao.createNeed(need);
- }
-
-// public void updateID(int id) throws IOException {
-// for (int i = 0; i < getNeeds().length; i++) {
-// needs.get(i).setID(i);
-// }
-// }
-
- public Need[] findNeeds(String name) throws IOException {
- return dao.findNeeds(name);
- }
-
- public Need updateNeed(Need need) throws IOException {
- return dao.updateNeed(need);
- }
-
- public void removeNeed(int id) throws IOException {
- dao.deleteNeed(id);
- }
-
- public void removeNeed(String name) throws IOException {
- for (Need need : getNeeds()) {
- if (need.getName().equals(name)) {
- dao.deleteNeed(need.getId());
- return;
- }
- }
- }
-
- public Need[] getNeeds() throws IOException {
- return dao.getNeeds();
- }
-
- public Need getNeed(int id) throws IOException {
- return dao.getNeed(id);
- }
-
-}
diff --git a/ufund-api/src/main/java/com/ufund/api/ufundapi/model/Need.java b/ufund-api/src/main/java/com/ufund/api/ufundapi/model/Need.java
index 9187796..2611357 100644
--- a/ufund-api/src/main/java/com/ufund/api/ufundapi/model/Need.java
+++ b/ufund-api/src/main/java/com/ufund/api/ufundapi/model/Need.java
@@ -1,5 +1,7 @@
package com.ufund.api.ufundapi.model;
+import com.fasterxml.jackson.annotation.JsonProperty;
+
public class Need {
public enum GoalType {
@@ -7,12 +9,12 @@ public class Need {
PHYSICAL
}
- private String name;
- private int id;
- private String[] filterAttributes;
- final private GoalType type;
- private double maxGoal;
- private double current;
+ @JsonProperty("name") private String name;
+ @JsonProperty("id") private int id;
+ @JsonProperty("filterAttributes") private String[] filterAttributes;
+ @JsonProperty("type") final private GoalType type;
+ @JsonProperty("maxGoal") private double maxGoal;
+ @JsonProperty("Current") private double current;
/**
* Create a new need
@@ -22,7 +24,7 @@ public class Need {
* @param maxGoal The maximum goal for this need
* @param type The type of need (monetary, physical)
*/
- public Need(String name, int id, double maxGoal, GoalType type) {
+ public Need(@JsonProperty("name") String name, @JsonProperty("id") int id, @JsonProperty("maxGoal") double maxGoal, GoalType type) {
this.id = id;
this.name = name;
this.maxGoal = maxGoal;
diff --git a/ufund-api/src/main/java/com/ufund/api/ufundapi/persistence/CupboardFileDao.java b/ufund-api/src/main/java/com/ufund/api/ufundapi/persistence/CupboardFileDao.java
index fd42e17..0f6e3af 100644
--- a/ufund-api/src/main/java/com/ufund/api/ufundapi/persistence/CupboardFileDao.java
+++ b/ufund-api/src/main/java/com/ufund/api/ufundapi/persistence/CupboardFileDao.java
@@ -11,7 +11,7 @@ import java.util.Map;
import java.util.TreeMap;
@Component
-public class CupboardFileDao implements CupboardDAO{
+public class CupboardFileDao implements CupboardDAO {
private final Map<Integer, Need> needs; // cache
private final ObjectMapper objectMapper;
diff --git a/ufund-api/src/main/resources/application.properties b/ufund-api/src/main/resources/application.properties
index 3e7fc8a..37b7058 100644
--- a/ufund-api/src/main/resources/application.properties
+++ b/ufund-api/src/main/resources/application.properties
@@ -1 +1,2 @@
server.error.include-message=always
+cupboard.file=data/cupboard.json \ No newline at end of file