Changeset 43c9090 for src/main/java/finki/it/terapijamkbackend/spring/controllers/UserController.java
Legend:
- Unmodified
- Added
- Removed
-
src/main/java/finki/it/terapijamkbackend/spring/controllers/UserController.java
r743de55 r43c9090 45 45 response = new HashMap<>(); 46 46 response.put("message", "User created successfully!"); 47 System.out.println(response);48 47 return ResponseEntity.ok(response); 49 48 } catch (Exception e) { … … 54 53 @GetMapping("/editUser") 55 54 public ResponseEntity<User> getUser(@RequestParam String username) { 56 User user = userService.getUserByUsername(username); // Fetch user data from service55 User user = userService.getUserByUsername(username); 57 56 if (user != null) { 58 return ResponseEntity.ok(user); // Return user data as JSON57 return ResponseEntity.ok(user); 59 58 } else { 60 return ResponseEntity.notFound().build(); // Handle user not found59 return ResponseEntity.notFound().build(); 61 60 } 62 61 } … … 76 75 String oldUsername=getCookieValue(request, "username"); 77 76 User user = userService.updateUser(oldUsername, updatedUser); 78 return ResponseEntity.ok(user); // Return the updated user in the response77 return ResponseEntity.ok(user); 79 78 } catch (UserNotFoundException e) { 80 return ResponseEntity.status(HttpStatus.NOT_FOUND).build(); // Return a 404 if user is not found79 return ResponseEntity.status(HttpStatus.NOT_FOUND).build(); 81 80 } catch (Exception e) { 82 return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).build(); // Return a 500 for other errors81 return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).build(); 83 82 } 84 83 }
Note:
See TracChangeset
for help on using the changeset viewer.