aboutsummaryrefslogtreecommitdiff
path: root/ufund-api/src/main/java/com/ufund/api/ufundapi/model/Cupboard.java
diff options
context:
space:
mode:
authorsowgro <tpoke.ferrari@gmail.com>2025-02-16 12:29:41 -0500
committersowgro <tpoke.ferrari@gmail.com>2025-02-16 12:29:41 -0500
commitb7c662afadf531eae34c5044c50c7b5c5330345b (patch)
treebf70f88e27062ec2cbc8371c45e577b175ec4040 /ufund-api/src/main/java/com/ufund/api/ufundapi/model/Cupboard.java
parentbe155cb28c8c5662a6dd9ce9268b06869087b4a0 (diff)
downloadJellySolutions-b7c662afadf531eae34c5044c50c7b5c5330345b.tar.gz
JellySolutions-b7c662afadf531eae34c5044c50c7b5c5330345b.tar.bz2
JellySolutions-b7c662afadf531eae34c5044c50c7b5c5330345b.zip
Add spring stuff to CupboardController and make all DAO calls inside Cupboard class
Diffstat (limited to 'ufund-api/src/main/java/com/ufund/api/ufundapi/model/Cupboard.java')
-rw-r--r--ufund-api/src/main/java/com/ufund/api/ufundapi/model/Cupboard.java61
1 files changed, 27 insertions, 34 deletions
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
index fedf04e..de1695a 100644
--- 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
@@ -1,58 +1,51 @@
package com.ufund.api.ufundapi.model;
-import java.util.ArrayList;
+import com.ufund.api.ufundapi.persistence.CupboardDAO;
+import com.ufund.api.ufundapi.persistence.CupboardFileDao;
-public class Cupboard {
- ArrayList<Need> needs;
+import java.io.IOException;
- public Cupboard() {
- needs = new ArrayList<>();
- }
+public class Cupboard {
+ CupboardDAO dao = new CupboardFileDao();
- public void addNeed(Need need) {
- needs.add(need);
+ public void createNeed(Need need) throws IOException {
+ int id = dao.getNeeds().length;
+ dao.createNeed(need);
}
- public void createNeed(String name, double max, Need.GoalType type) {
- int id = needs.size();
- Need need = new Need(name, id, max, type);
- addNeed(need);
- }
+// public void updateID(int id) throws IOException {
+// for (int i = 0; i < getNeeds().length; i++) {
+// needs.get(i).setID(i);
+// }
+// }
- public void updateID(int id) {
- for (int i = 0; i < needs.size(); i++) {
- needs.get(i).setID(i);
- }
+ public Need[] findNeeds(String name) throws IOException {
+ return dao.findNeeds(name);
}
- public void removeNeed(Need need) {
- needs.remove(need);
+ public void updateNeed(Need need) throws IOException {
+ dao.updateNeed(need);
}
- public void updateNeed(Need need) {
- for (int i = 0; i < needs.size(); i++) {
- if (needs.get(i).getID() == need.getID()) {
- needs.set(i, need);
- return;
- }
- }
+ public void removeNeed(int id) throws IOException {
+ dao.deleteNeed(id);
}
- public void removeNeed(String name) {
- for (int i = 0; i < needs.size(); i++) {
- if (needs.get(i).getName().equals(name)) {
- needs.remove(i);
+ public void removeNeed(String name) throws IOException {
+ for (Need need : getNeeds()) {
+ if (need.getName().equals(name)) {
+ dao.deleteNeed(need.getID());
return;
}
}
}
- public Need[] getNeeds() {
- return needs.toArray(new Need[0]);
+ public Need[] getNeeds() throws IOException {
+ return dao.getNeeds();
}
- public Need getNeed(int index) {
- return needs.get(index);
+ public Need getNeed(int id) throws IOException {
+ return dao.getNeed(id);
}
}