aboutsummaryrefslogtreecommitdiff
path: root/ufund-api/src/main
diff options
context:
space:
mode:
Diffstat (limited to 'ufund-api/src/main')
-rw-r--r--ufund-api/src/main/java/com/ufund/api/ufundapi/controller/UserController.java27
-rw-r--r--ufund-api/src/main/java/com/ufund/api/ufundapi/model/User.java3
-rw-r--r--ufund-api/src/main/java/com/ufund/api/ufundapi/persistence/UserFileDAO.java4
-rw-r--r--ufund-api/src/main/resources/application.properties3
4 files changed, 20 insertions, 17 deletions
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 ae75179..1af865d 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
@@ -19,13 +19,13 @@ import com.ufund.api.ufundapi.model.User;
import com.ufund.api.ufundapi.persistence.UserDAO;
@RestController
-@RequestMapping("cupboard")
+@RequestMapping("users")
public class UserController {
private static final Logger LOG = Logger.getLogger(CupboardController.class.getName());
private final UserDAO UserDAO;
/**
- * Create a cupboard controller to receive REST signals
+ * Create a user controller to receive REST signals
*
* @param UserDAO The Data Access Object
*/
@@ -37,7 +37,8 @@ public class UserController {
* Creates a User with the provided object
*
* @param user The user to create
- * @return OK response and the user if it was successful, INTERNAL_SERVER_ERROR otherwise
+ * @return OK response and the user if it was successful, INTERNAL_SERVER_ERROR
+ * otherwise
*/
@PostMapping("")
public ResponseEntity<User> createUser(@RequestBody User user) {
@@ -47,7 +48,7 @@ public class UserController {
} else {
return new ResponseEntity<>(HttpStatus.CONFLICT);
}
-
+
} catch (IOException ex) {
return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR);
}
@@ -107,18 +108,19 @@ public class UserController {
* Updates a User with the provided one
*
* @param user The user to update
- * @return OK response and the user if it was successful, or INTERNAL_SERVER_ERROR if there was an issue
+ * @return OK response and the user if it was successful, or
+ * INTERNAL_SERVER_ERROR if there was an issue
*/
- @PutMapping("")
- public ResponseEntity<User> updateUser(@RequestBody User user, String string) {
+ @PutMapping("/{name}")
+ public ResponseEntity<User> updateUser(@RequestBody User user, @PathVariable String name) {
try {
- user = UserDAO.updateUser(user, string);
+ user = UserDAO.updateUser(user, name);
if (user != null) {
return new ResponseEntity<>(user, HttpStatus.OK);
} else {
return new ResponseEntity<>(HttpStatus.NOT_FOUND);
}
-
+
} catch (IOException e) {
return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR);
}
@@ -128,8 +130,9 @@ public class UserController {
* Deletes a user with the desired name
*
* @param name The name of the user
- * @return OK if the user was deleted, NOT_FOUND if the user was not found, or INTERNAL_SERVER_ERROR if an error occurred
- */
+ * @return OK if the user was deleted, NOT_FOUND if the user was not found, or
+ * INTERNAL_SERVER_ERROR if an error occurred
+ */
@DeleteMapping("/{name}")
public ResponseEntity<User> deleteUser(@PathVariable String name) {
try {
@@ -137,7 +140,7 @@ public class UserController {
return new ResponseEntity<>(HttpStatus.OK);
} else {
return new ResponseEntity<>(HttpStatus.NOT_FOUND);
- }
+ }
} catch (IOException e) {
return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR);
}
diff --git a/ufund-api/src/main/java/com/ufund/api/ufundapi/model/User.java b/ufund-api/src/main/java/com/ufund/api/ufundapi/model/User.java
index ed34817..2086d45 100644
--- a/ufund-api/src/main/java/com/ufund/api/ufundapi/model/User.java
+++ b/ufund-api/src/main/java/com/ufund/api/ufundapi/model/User.java
@@ -12,9 +12,8 @@ public class User {
*
* @param name The name of the user
* @param password The password of the user
- * @param id The unique ID of the user
*/
- public User(String name) {
+ public User(@JsonProperty("name") String name) {
this.name = name;
}
diff --git a/ufund-api/src/main/java/com/ufund/api/ufundapi/persistence/UserFileDAO.java b/ufund-api/src/main/java/com/ufund/api/ufundapi/persistence/UserFileDAO.java
index 0f30824..18eec18 100644
--- a/ufund-api/src/main/java/com/ufund/api/ufundapi/persistence/UserFileDAO.java
+++ b/ufund-api/src/main/java/com/ufund/api/ufundapi/persistence/UserFileDAO.java
@@ -95,7 +95,7 @@ public class UserFileDAO implements UserDAO {
@Override
public User createUser(User user) throws IOException {
synchronized (users) {
- if (getUser(user.getName()) != null) {
+ if (getUser(user.getName()) == null) {
User newUser = new User(user);
users.put(newUser.getName(), newUser);
save();
@@ -131,7 +131,7 @@ public class UserFileDAO implements UserDAO {
/**
* Delete a user matching the name
*
- * @param name The name of the user
+ * @param name The name of the user
*
* @return True if deleted, false otherwise
* @throws IOException If there was an IO issue saving the file
diff --git a/ufund-api/src/main/resources/application.properties b/ufund-api/src/main/resources/application.properties
index 22e8184..254ac64 100644
--- a/ufund-api/src/main/resources/application.properties
+++ b/ufund-api/src/main/resources/application.properties
@@ -1,4 +1,5 @@
# rename to application.properties
server.error.include-message=always
-cupboard.file=ufund-api/data/cupboard.json \ No newline at end of file
+cupboard.file=ufund-api/data/cupboard.json
+users.file=ufund-api/data/users.json \ No newline at end of file