diff options
author | Zhongheng Liu <z.liu@outlook.com.gr> | 2024-01-19 21:02:17 +0200 |
---|---|---|
committer | Zhongheng Liu <z.liu@outlook.com.gr> | 2024-01-19 21:02:17 +0200 |
commit | 7992705e9ceda23164be74378659b26008b20882 (patch) | |
tree | b9c27899bf65e955336159245721da3a21bed9c0 /src/main/java/me/imsonmia/epqapi/controller/UserController.java | |
parent | 2e73088d2a1604bc0ec77926c2c312cb86a6800a (diff) | |
download | epq-api-7992705e9ceda23164be74378659b26008b20882.tar.gz epq-api-7992705e9ceda23164be74378659b26008b20882.tar.bz2 epq-api-7992705e9ceda23164be74378659b26008b20882.zip |
Added server-side CORS support for API endpoints
Diffstat (limited to 'src/main/java/me/imsonmia/epqapi/controller/UserController.java')
-rw-r--r-- | src/main/java/me/imsonmia/epqapi/controller/UserController.java | 17 |
1 files changed, 7 insertions, 10 deletions
diff --git a/src/main/java/me/imsonmia/epqapi/controller/UserController.java b/src/main/java/me/imsonmia/epqapi/controller/UserController.java index 8a29082..842e353 100644 --- a/src/main/java/me/imsonmia/epqapi/controller/UserController.java +++ b/src/main/java/me/imsonmia/epqapi/controller/UserController.java @@ -5,6 +5,7 @@ import java.util.ArrayList; import java.util.Optional; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.HttpHeaders; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.DeleteMapping; import org.springframework.web.bind.annotation.GetMapping; @@ -38,8 +39,13 @@ public class UserController { // malformed request return ResponseEntity.badRequest().build(); } else { + boolean exists = userRepository.existsByUserName(name.get()); // Filter by name branch - return ResponseEntity.ok().body(userRepository.findByUserName(name.get())); + if (!exists) { + return ResponseEntity.notFound().build(); + } else { + return ResponseEntity.ok().body(userRepository.findByUserName(name.get()).get()); + } } } else { // get by id branch @@ -85,13 +91,4 @@ public class UserController { } return messages; } - // @PatchMapping("/user/{id}") - // boolean changeUserProperties(@PathVariable(value = "id") Long userId, - // @RequestBody User newUser) { - // if (!userRepository.existsById(userId)) { - // return false; - // } - // userRepository.save(newUser); - // return true; - // } } |