aboutsummaryrefslogtreecommitdiff
path: root/ufund-api/src/main/java/com/ufund/api/ufundapi
diff options
context:
space:
mode:
authorTyler Ferrari <69283684+Sowgro@users.noreply.github.com>2025-04-01 02:17:25 -0400
committerGitHub <noreply@github.com>2025-04-01 02:17:25 -0400
commit233fe120d2a9b30e0150401ebdfeb946dc9c2c07 (patch)
tree98583e1b1d21d1a0cc57e8ff3489fbbf758eccff /ufund-api/src/main/java/com/ufund/api/ufundapi
parentc6bbb29f42eaea7d0c8aebdb7b95be0287cbf4f9 (diff)
parent0e9c0803e35a23ef2e873dc7ebf224a49a92f207 (diff)
downloadJellySolutions-233fe120d2a9b30e0150401ebdfeb946dc9c2c07.tar.gz
JellySolutions-233fe120d2a9b30e0150401ebdfeb946dc9c2c07.tar.bz2
JellySolutions-233fe120d2a9b30e0150401ebdfeb946dc9c2c07.zip
Merge pull request #22 from RIT-SWEN-261-02/css
Merge css into main
Diffstat (limited to 'ufund-api/src/main/java/com/ufund/api/ufundapi')
-rw-r--r--ufund-api/src/main/java/com/ufund/api/ufundapi/controller/AuthController.java6
-rw-r--r--ufund-api/src/main/java/com/ufund/api/ufundapi/controller/CupboardController.java66
-rw-r--r--ufund-api/src/main/java/com/ufund/api/ufundapi/controller/UserController.java26
-rw-r--r--ufund-api/src/main/java/com/ufund/api/ufundapi/model/Need.java28
-rw-r--r--ufund-api/src/main/java/com/ufund/api/ufundapi/service/CupboardService.java12
5 files changed, 86 insertions, 52 deletions
diff --git a/ufund-api/src/main/java/com/ufund/api/ufundapi/controller/AuthController.java b/ufund-api/src/main/java/com/ufund/api/ufundapi/controller/AuthController.java
index aa99a90..82b2c67 100644
--- a/ufund-api/src/main/java/com/ufund/api/ufundapi/controller/AuthController.java
+++ b/ufund-api/src/main/java/com/ufund/api/ufundapi/controller/AuthController.java
@@ -43,10 +43,10 @@ public class AuthController {
return new ResponseEntity<>(key, HttpStatus.OK);
} catch (IllegalAccessException ex) {
LOG.log(Level.WARNING, ex.getLocalizedMessage());
- return new ResponseEntity<>(HttpStatus.UNAUTHORIZED);
+ return new ResponseEntity<>(ex.getMessage(), HttpStatus.UNAUTHORIZED);
} catch (IOException ex) {
LOG.log(Level.SEVERE, ex.getLocalizedMessage());
- return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR);
+ return new ResponseEntity<>(ex.getMessage(), HttpStatus.INTERNAL_SERVER_ERROR);
}
}
@@ -64,7 +64,7 @@ public class AuthController {
return new ResponseEntity<>(HttpStatus.OK);
} catch (IOException ex) {
LOG.log(Level.WARNING, ex.getLocalizedMessage());
- return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR);
+ return new ResponseEntity<>(ex.getMessage(), HttpStatus.INTERNAL_SERVER_ERROR);
}
}
}
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 bbfd3f6..12fb0a9 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
@@ -5,7 +5,6 @@ import java.util.Map;
import java.util.logging.Level;
import java.util.logging.Logger;
-import com.ufund.api.ufundapi.service.AuthService;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.DeleteMapping;
@@ -22,6 +21,7 @@ import org.springframework.web.bind.annotation.RestController;
import com.ufund.api.ufundapi.DuplicateKeyException;
import com.ufund.api.ufundapi.model.Need;
import com.ufund.api.ufundapi.model.Need.GoalType;
+import com.ufund.api.ufundapi.service.AuthService;
import com.ufund.api.ufundapi.service.CupboardService;
@RestController
@@ -51,29 +51,33 @@ public class CupboardController {
* INTERNAL_SERVER_ERROR otherwise
*/
@PostMapping("")
- public ResponseEntity<Need> createNeed(@RequestBody Map<String, Object> params, @RequestHeader("jelly-api-key") String key) {
+ public ResponseEntity<Object> createNeed(@RequestBody Map<String, Object> params, @RequestHeader("jelly-api-key") String key) {
LOG.log(Level.INFO, "POST /cupboard body={0}", params);
String name = (String) params.get("name");
+ String image = (String) params.get("image");
+ String location = (String) params.get("location");
double maxGoal = ((Number) params.get("maxGoal")).doubleValue();
+ boolean urgent = (Boolean) params.get("urgent");
+ String description = (String) params.get("description");
Need.GoalType goalType = GoalType.valueOf((String) params.get("type"));
try {
authService.keyHasAccessToCupboard(key);
- Need need = cupboardService.createNeed(name, maxGoal, goalType);
+ Need need = cupboardService.createNeed(name, image, location, maxGoal, goalType, urgent, description);
return new ResponseEntity<>(need, HttpStatus.OK);
} catch (DuplicateKeyException ex) {
LOG.log(Level.WARNING, ex.getLocalizedMessage());
- return new ResponseEntity<>(HttpStatus.CONFLICT);
+ return new ResponseEntity<>(ex.getMessage(), HttpStatus.CONFLICT);
} catch (IllegalArgumentException ex) {
LOG.log(Level.WARNING, ex.getLocalizedMessage());
- return new ResponseEntity<>(HttpStatus.BAD_REQUEST);
+ return new ResponseEntity<>(ex.getMessage(), HttpStatus.BAD_REQUEST);
} catch (IllegalAccessException ex) {
LOG.log(Level.WARNING, ex.getLocalizedMessage());
- return new ResponseEntity<>(HttpStatus.UNAUTHORIZED);
+ return new ResponseEntity<>(ex.getMessage(), HttpStatus.UNAUTHORIZED);
} catch (IOException ex) {
LOG.log(Level.SEVERE, ex.getLocalizedMessage());
- return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR);
+ return new ResponseEntity<>(ex.getMessage(), HttpStatus.INTERNAL_SERVER_ERROR);
}
}
@@ -86,15 +90,15 @@ public class CupboardController {
* ResponseEntity with HTTP status of INTERNAL_SERVER_ERROR otherwise
*/
@GetMapping("")
- public ResponseEntity<Need[]> getNeeds() {
+ public ResponseEntity<Object> getNeeds() {
LOG.info("GET /cupboard");
try {
Need[] needs = cupboardService.getNeeds();
return new ResponseEntity<>(needs, HttpStatus.OK);
- } catch (IOException e) {
- LOG.log(Level.SEVERE, e.getLocalizedMessage());
- return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR);
+ } catch (IOException ex) {
+ LOG.log(Level.SEVERE, ex.getLocalizedMessage());
+ return new ResponseEntity<>(ex.getMessage(), HttpStatus.INTERNAL_SERVER_ERROR);
}
}
@@ -104,23 +108,21 @@ public class CupboardController {
*
* @param name The name parameter which contains the text used to find the {@link Need need}
*
- * @deprecated Searching should now be done client side in the future
- *
* @return ResponseEntity with array of {@link Need need} objects (may be empty) and
* HTTP status of OK<br>
* ResponseEntity with HTTP status of INTERNAL_SERVER_ERROR otherwise
* <p>
*/
@GetMapping("/")
- public ResponseEntity<Need[]> searchNeeds(@RequestParam String name) {
+ public ResponseEntity<Object> searchNeeds(@RequestParam String name) {
LOG.info("GET /cupboard/?name="+name);
try {
Need[] needs = cupboardService.searchNeeds(name);
return new ResponseEntity<>(needs, HttpStatus.OK);
- } catch (IOException e) {
- LOG.log(Level.SEVERE,e.getLocalizedMessage());
- return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR);
+ } catch (IOException ex) {
+ LOG.log(Level.SEVERE,ex.getLocalizedMessage());
+ return new ResponseEntity<>(ex.getMessage(), HttpStatus.INTERNAL_SERVER_ERROR);
}
}
@@ -133,7 +135,7 @@ public class CupboardController {
* ResponseEntity with HTTP status of NOT_FOUND if not found<br>
*/
@GetMapping("/{id}")
- public ResponseEntity<Need> getNeed(@PathVariable int id) {
+ public ResponseEntity<Object> getNeed(@PathVariable int id) {
LOG.log(Level.INFO, "GET /cupboard/{0}", id);
try {
@@ -143,9 +145,9 @@ public class CupboardController {
} else {
return new ResponseEntity<>(HttpStatus.NOT_FOUND);
}
- } catch (IOException e) {
- LOG.log(Level.SEVERE, e.getLocalizedMessage());
- return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR);
+ } catch (IOException ex) {
+ LOG.log(Level.SEVERE, ex.getLocalizedMessage());
+ return new ResponseEntity<>(ex.getMessage(), HttpStatus.INTERNAL_SERVER_ERROR);
}
}
@@ -157,7 +159,7 @@ public class CupboardController {
* @return OK response and the need if it was successful, or INTERNAL_SERVER_ERROR if there was an issue
*/
@PutMapping("/{id}")
- public ResponseEntity<Need> updateNeed(@RequestBody Need need, @PathVariable int id, @RequestHeader("jelly-api-key") String key) {
+ public ResponseEntity<Object> updateNeed(@RequestBody Need need, @PathVariable int id, @RequestHeader("jelly-api-key") String key) {
LOG.log(Level.INFO, "PUT /cupboard/{0} body={1}", of(id, need));
try {
authService.keyHasAccessToCupboard(key);
@@ -169,19 +171,19 @@ public class CupboardController {
}
} catch (IllegalArgumentException ex) {
LOG.log(Level.WARNING, ex.getLocalizedMessage());
- return new ResponseEntity<>(HttpStatus.BAD_REQUEST);
+ return new ResponseEntity<>(ex.getMessage(), HttpStatus.BAD_REQUEST);
} catch (IllegalAccessException ex) {
LOG.log(Level.WARNING, ex.getLocalizedMessage());
- return new ResponseEntity<>(HttpStatus.UNAUTHORIZED);
+ return new ResponseEntity<>(ex.getMessage(), HttpStatus.UNAUTHORIZED);
} catch (IOException ex) {
LOG.log(Level.SEVERE, ex.getLocalizedMessage());
- return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR);
+ return new ResponseEntity<>(ex.getMessage(), HttpStatus.INTERNAL_SERVER_ERROR);
}
}
/**
* Checks out a need by checkoutAmount
- *
+ *
* @param data JSON object with parameters needID and amount
* @param key Key used to authenticate user
* @return OK if successful, other statuses if failure
@@ -196,13 +198,13 @@ public class CupboardController {
return new ResponseEntity<>(HttpStatus.OK);
} catch (IllegalArgumentException ex) {
LOG.log(Level.WARNING, ex.getLocalizedMessage());
- return new ResponseEntity<>(HttpStatus.BAD_REQUEST);
+ return new ResponseEntity<>(ex.getMessage(), HttpStatus.BAD_REQUEST);
} catch (IllegalAccessException ex) {
LOG.log(Level.WARNING, ex.getLocalizedMessage());
- return new ResponseEntity<>(HttpStatus.UNAUTHORIZED);
+ return new ResponseEntity<>(ex.getMessage(), HttpStatus.UNAUTHORIZED);
} catch (IOException ex) {
LOG.log(Level.SEVERE, ex.getLocalizedMessage());
- return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR);
+ return new ResponseEntity<>(ex.getMessage(), HttpStatus.INTERNAL_SERVER_ERROR);
}
}
@@ -213,7 +215,7 @@ public class CupboardController {
* @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, @RequestHeader("jelly-api-key") String key) {
+ public ResponseEntity<Object> deleteNeed(@PathVariable int id, @RequestHeader("jelly-api-key") String key) {
LOG.log(Level.INFO, "DELETE /cupboard/{0}", id);
try {
authService.keyHasAccessToCupboard(key);
@@ -225,10 +227,10 @@ public class CupboardController {
}
} catch (IllegalAccessException ex) {
LOG.log(Level.WARNING, ex.getLocalizedMessage());
- return new ResponseEntity<>(HttpStatus.UNAUTHORIZED);
+ return new ResponseEntity<>(ex.getMessage(), HttpStatus.UNAUTHORIZED);
} catch (IOException ex) {
LOG.log(Level.SEVERE, ex.getLocalizedMessage());
- return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR);
+ return new ResponseEntity<>(ex.getMessage(), HttpStatus.INTERNAL_SERVER_ERROR);
}
}
diff --git a/ufund-api/src/main/java/com/ufund/api/ufundapi/controller/UserController.java b/ufund-api/src/main/java/com/ufund/api/ufundapi/controller/UserController.java
index 33d2e4f..a34e891 100644
--- a/ufund-api/src/main/java/com/ufund/api/ufundapi/controller/UserController.java
+++ b/ufund-api/src/main/java/com/ufund/api/ufundapi/controller/UserController.java
@@ -41,7 +41,7 @@ public class UserController {
* otherwise
*/
@PostMapping("")
- public ResponseEntity<User> createUser(@RequestBody Map<String, String> params) {
+ public ResponseEntity<Object> createUser(@RequestBody Map<String, String> params) {
LOG.log(Level.INFO, "POST /users body={0}", params);
String username = params.get("username");
String password = params.get("password");
@@ -55,10 +55,10 @@ public class UserController {
}
} catch (DuplicateKeyException ex) {
LOG.log(Level.WARNING, ex.getLocalizedMessage());
- return new ResponseEntity<>(HttpStatus.CONFLICT);
+ return new ResponseEntity<>(ex.getMessage(), HttpStatus.CONFLICT);
} catch (IOException ex) {
LOG.log(Level.SEVERE, ex.getLocalizedMessage());
- return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR);
+ return new ResponseEntity<>(ex.getMessage(), HttpStatus.INTERNAL_SERVER_ERROR);
}
}
@@ -73,7 +73,7 @@ public class UserController {
* ResponseEntity with HTTP status of INTERNAL_SERVER_ERROR otherwise
*/
@GetMapping("/{username}")
- public ResponseEntity<User> getUser(@PathVariable String username, @RequestHeader("jelly-api-key") String key) {
+ public ResponseEntity<Object> getUser(@PathVariable String username, @RequestHeader("jelly-api-key") String key) {
LOG.log(Level.INFO, "GET /user/{0} key={1}", of(username, key));
try {
@@ -86,10 +86,10 @@ public class UserController {
}
} catch (IllegalAccessException ex) {
LOG.log(Level.WARNING, ex.getLocalizedMessage());
- return new ResponseEntity<>(HttpStatus.UNAUTHORIZED);
+ return new ResponseEntity<>(ex.getMessage(), HttpStatus.UNAUTHORIZED);
} catch (IOException ex) {
LOG.log(Level.SEVERE, ex.getLocalizedMessage());
- return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR);
+ return new ResponseEntity<>(ex.getMessage(), HttpStatus.INTERNAL_SERVER_ERROR);
}
}
@@ -104,7 +104,7 @@ public class UserController {
* INTERNAL_SERVER_ERROR if there was an issue
*/
@PutMapping("/{username}")
- public ResponseEntity<User> updateUser(@RequestBody User user, @PathVariable String username, @RequestHeader("jelly-api-key") String key) {
+ public ResponseEntity<Object> updateUser(@RequestBody User user, @PathVariable String username, @RequestHeader("jelly-api-key") String key) {
LOG.log(Level.INFO,"PUT /users/{0} body={1} key={2}", of(username, user, key));
try {
authService.keyHasAccessToUser(username, key);
@@ -116,13 +116,13 @@ public class UserController {
}
} catch (IllegalArgumentException ex) {
LOG.log(Level.WARNING, ex.getLocalizedMessage());
- return new ResponseEntity<>(HttpStatus.BAD_REQUEST);
+ return new ResponseEntity<>(ex.getMessage(), HttpStatus.BAD_REQUEST);
} catch (IllegalAccessException ex) {
LOG.log(Level.WARNING, ex.getLocalizedMessage());
- return new ResponseEntity<>(HttpStatus.UNAUTHORIZED);
+ return new ResponseEntity<>(ex.getMessage(), HttpStatus.UNAUTHORIZED);
} catch (IOException ex) {
LOG.log(Level.SEVERE, ex.getLocalizedMessage());
- return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR);
+ return new ResponseEntity<>(ex.getMessage(), HttpStatus.INTERNAL_SERVER_ERROR);
}
}
@@ -135,7 +135,7 @@ public class UserController {
* INTERNAL_SERVER_ERROR if an error occurred
*/
@DeleteMapping("/{username}")
- public ResponseEntity<Boolean> deleteUser(@PathVariable String username, @RequestHeader("jelly-api-key") String key) {
+ public ResponseEntity<Object> deleteUser(@PathVariable String username, @RequestHeader("jelly-api-key") String key) {
LOG.log(Level.INFO, "DELETE /users/{0} id={1}", of(username, key));
try {
@@ -147,10 +147,10 @@ public class UserController {
}
} catch (IllegalAccessException ex) {
LOG.log(Level.WARNING, ex.getLocalizedMessage());
- return new ResponseEntity<>(HttpStatus.UNAUTHORIZED);
+ return new ResponseEntity<>(ex.getMessage(), HttpStatus.UNAUTHORIZED);
} catch (IOException ex) {
LOG.log(Level.SEVERE, ex.getLocalizedMessage());
- return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR);
+ return new ResponseEntity<>(ex.getMessage(), HttpStatus.INTERNAL_SERVER_ERROR);
}
}
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 22e86e3..9b6170b 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
@@ -10,38 +10,57 @@ public class Need {
}
@JsonProperty("name") private String name;
+ @JsonProperty("image") private String image;
+ @JsonProperty("location") private String location;
@JsonProperty("id") private int id;
@JsonProperty("filterAttributes") private String[] filterAttributes;
@JsonProperty("type") final private GoalType type;
@JsonProperty("maxGoal") private double maxGoal;
+ @JsonProperty("urgent") private boolean urgent;
@JsonProperty("current") private double current;
+ @JsonProperty("description") private String description;
/**
* Create a new need, used by the controller
*
* @param name The name of the need
+ * @param location The physical location of the need
* @param id The unique ID of the need
* @param maxGoal The maximum goal for this need
* @param type The type of need (monetary, physical)
+ * @param urgent The urgency of the need
+ * @param description The description of the need
*/
- public Need(@JsonProperty("name") String name, @JsonProperty("id") int id, @JsonProperty("maxGoal") double maxGoal, @JsonProperty("type") GoalType type) {
+ public Need(@JsonProperty("name") String name, @JsonProperty("image") String image, @JsonProperty("location") String location, @JsonProperty("id") int id, @JsonProperty("maxGoal") double maxGoal, @JsonProperty("type") GoalType type, @JsonProperty("urgent") boolean urgent, @JsonProperty("Description") String description) {
this.id = id;
+ this.image = image;
+ this.location = location;
this.name = name;
this.maxGoal = maxGoal;
this.type = type;
+ this.urgent = urgent;
+ this.description = description;
}
/**
* Create a new need
*
* @param name The name of the need
+ * @param image The image representation of the need
+ * @param location The location of the need
* @param maxGoal The maximum goal for this need
* @param type The type of need (monetary, physical)
+ * @param urgent The urgency of the need
+ * @param description The description of the need
*/
- public Need(String name, GoalType type, double maxGoal) {
+ public Need(String name, String image, String location, double maxGoal, GoalType type, boolean urgent, String description) {
this.name = name;
+ this.image = image;
+ this.location = location;
this.type = type;
this.maxGoal = maxGoal;
+ this.urgent = urgent;
+ this.description = description;
}
/**
@@ -51,11 +70,15 @@ public class Need {
*/
public Need(Need other) {
this.name = other.name;
+ this.image = other.image;
+ this.location = other.location;
this.id = other.id;
this.filterAttributes = other.filterAttributes;
this.type = other.type;
this.maxGoal = other.maxGoal;
this.current = other.current;
+ this.urgent = other.urgent;
+ this.description = other.description;
}
public String getName() {
@@ -82,6 +105,7 @@ public class Need {
return current;
}
+
public void setCurrent(double current) {
this.current = current;
}
diff --git a/ufund-api/src/main/java/com/ufund/api/ufundapi/service/CupboardService.java b/ufund-api/src/main/java/com/ufund/api/ufundapi/service/CupboardService.java
index aaa8cb8..993e7c1 100644
--- a/ufund-api/src/main/java/com/ufund/api/ufundapi/service/CupboardService.java
+++ b/ufund-api/src/main/java/com/ufund/api/ufundapi/service/CupboardService.java
@@ -25,16 +25,22 @@ public class CupboardService {
* Creates a new Need
*
* @param name The name of the need to create
+ * @param image The image representation of the need to create
+ * @param location The location of the new need
* @param maxGoal The max goal of the new need
* @param goalType The goal type of the new need
+ * @param urgent The urgency of the new need
+ * @param description The description of the new need
* @return The need that was created
* @throws IOException Thrown if there was any issue saving the data
* @throws DuplicateKeyException If there already exists a need with the same name
*/
- public Need createNeed(String name, double maxGoal, Need.GoalType goalType) throws IOException, DuplicateKeyException {
+ public Need createNeed(String name, String image, String location, double maxGoal, Need.GoalType goalType, boolean urgent, String description) throws IOException, DuplicateKeyException {
if (maxGoal <= 0) {
throw new IllegalArgumentException("Max Goal must be greater than zero");
+ } else if (goalType.equals(Need.GoalType.PHYSICAL) && maxGoal % 1 != 0) {
+ throw new IllegalArgumentException("Cannot have non whole number value for physical goal");
}
for (Need searchNeed : cupboardDAO.getNeeds()) {
@@ -43,7 +49,7 @@ public class CupboardService {
}
}
- Need need = new Need(name, goalType, maxGoal);
+ Need need = new Need(name, image, location, maxGoal, goalType, urgent, description);
return cupboardDAO.addNeed(need);
}
@@ -95,6 +101,8 @@ public class CupboardService {
}
if (need.getMaxGoal() <= 0) {
throw new IllegalArgumentException("Goal must be greater than 0");
+ } else if (need.getType().equals(Need.GoalType.PHYSICAL) && need.getMaxGoal() % 1 != 0) {
+ throw new IllegalArgumentException("Cannot have non whole number value for physical goal");
}
return cupboardDAO.updateNeed(need);
}