File tree Expand file tree Collapse file tree 2 files changed +8
-3
lines changed
src/main/java/hexlet/code Expand file tree Collapse file tree 2 files changed +8
-3
lines changed Original file line number Diff line number Diff line change 44import hexlet .code .dto .task .TaskCreateDTO ;
55import hexlet .code .dto .taskStatus .TaskStatusCreateDTO ;
66import hexlet .code .dto .user .UserCreateDTO ;
7+ import hexlet .code .exception .ResourceNotFoundException ;
78import hexlet .code .repository .UserRepository ;
89import hexlet .code .service .LabelService ;
910import hexlet .code .service .TaskService ;
@@ -58,7 +59,8 @@ public void run(ApplicationArguments args) throws Exception {
5859 });
5960
6061 // Task
61- var user = userRepository .findByEmail (email ).get ();
62+ var user = userRepository .findByEmail (email )
63+ .orElseThrow (() -> new ResourceNotFoundException ("User with email " + email + " not found" ));
6264
6365 taskStatusData .values ().forEach (v ->
6466 IntStream .range (1 , 5 ).forEach (i -> {
Original file line number Diff line number Diff line change @@ -21,11 +21,14 @@ public User getCurrentUser() {
2121
2222 var email = authentication .getName ();
2323
24- return userRepository .findByEmail (email ).get ();
24+ return userRepository .findByEmail (email )
25+ .orElseThrow (() -> new ResourceNotFoundException ("User with email " + email + " not found" ));
2526 }
2627
2728 public boolean isCurrentUser (long id ) {
28- var userEmail = userRepository .findById (id ).get ().getEmail ();
29+ var userEmail = userRepository .findById (id )
30+ .orElseThrow (() -> new ResourceNotFoundException ("User with id " + id + " not found" ))
31+ .getEmail ();
2932 var authentication = SecurityContextHolder .getContext ().getAuthentication ();
3033
3134 return userEmail .equals (authentication .getName ());
You can’t perform that action at this time.
0 commit comments