aboutsummaryrefslogtreecommitdiff
path: root/ufund-api/src/main/java/com/ufund/api/ufundapi/controller
diff options
context:
space:
mode:
Diffstat (limited to 'ufund-api/src/main/java/com/ufund/api/ufundapi/controller')
-rw-r--r--ufund-api/src/main/java/com/ufund/api/ufundapi/controller/AuthController.java25
-rw-r--r--ufund-api/src/main/java/com/ufund/api/ufundapi/controller/CupboardController.java15
2 files changed, 23 insertions, 17 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 1a545f6..b0390ae 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
@@ -20,8 +20,10 @@ public class AuthController {
/**
* Attempts to log in as a user
- * @param params A map/json object in the format {username: string, password: string}
- * @return An api key if the auth was successful, null otherwise
+ *
+ * @param params A json object in the format {username: string, password: string}
+ * @return An api key and status OK if the authentication was successful,
+ * Status UNAUTHORIZED if the authentication failed and INTERNAL SERVER ERROR otherwise.
*/
@PostMapping("")
public ResponseEntity<String> login(@RequestBody Map<String, String> params) {
@@ -30,19 +32,26 @@ public class AuthController {
try {
String key = authService.login(username, password);
return new ResponseEntity<>(key, HttpStatus.OK);
- } catch (IOException ex) {
- return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR);
} catch (IllegalAccessException e) {
return new ResponseEntity<>(HttpStatus.UNAUTHORIZED);
+ } catch (IOException ex) {
+ return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR);
}
}
/**
- * TODO
- * @return
+ * Logs out the current user
+ *
+ * @param key The API sent by the client in the header
+ * @return OK if the user was successfully logged out, INTERNAL_SERVER_ERROR otherwise.
*/
@DeleteMapping("")
- public ResponseEntity<Object> logout() {
- return new ResponseEntity<>(HttpStatus.NOT_IMPLEMENTED);
+ public ResponseEntity<Object> logout(@RequestHeader("jelly-api-key") String key) {
+ try {
+ authService.logout(key);
+ return new ResponseEntity<>(HttpStatus.OK);
+ } catch (IOException e) {
+ return new ResponseEntity<>(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 6b0bb71..dfcb8a3 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
@@ -40,8 +40,11 @@ public class CupboardController {
/**
* Creates a Need with the provided object
*
- * @param need The need to create
- * @return OK response and the need if it was successful, INTERNAL_SERVER_ERROR otherwise
+ * @param params The need to create
+ * @return OK response and the need if it was successful,
+ * CONFLICT if another need with the same name exists
+ * UNPROCESSABLE_ENTITY if the need contains bad data
+ * INTERNAL_SERVER_ERROR otherwise
*/
@PostMapping("")
public ResponseEntity<Need> createNeed(@RequestBody Map<String, String> params) {
@@ -50,10 +53,8 @@ public class CupboardController {
Need.GoalType goalType = GoalType.valueOf(params.get("maxGoal"));
try {
-
Need need = cupboardService.createNeed(name, maxGoal, goalType);
return new ResponseEntity<>(need, HttpStatus.OK);
-
} catch (DuplicateKeyException ex) {
return new ResponseEntity<>(HttpStatus.CONFLICT);
} catch (IllegalArgumentException ex) {
@@ -113,10 +114,8 @@ public class CupboardController {
*
* @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>
+ * @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 ResponseEntity<Need> getNeed(@PathVariable int id) {
@@ -129,7 +128,6 @@ 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);
@@ -143,7 +141,6 @@ public class CupboardController {
* @param need The need to update
* @return OK response and the need if it was successful, or INTERNAL_SERVER_ERROR if there was an issue
*/
-
@PutMapping("")
public ResponseEntity<Need> updateNeed(@RequestBody Need need) {
try {