File tree Expand file tree Collapse file tree 1 file changed +8
-5
lines changed
src/main/java/hexlet/code/service Expand file tree Collapse file tree 1 file changed +8
-5
lines changed Original file line number Diff line number Diff line change 77import hexlet .code .exception .ResourceNotFoundException ;
88import hexlet .code .mapper .TaskMapper ;
99import hexlet .code .model .Task ;
10+ import hexlet .code .model .User ;
1011import hexlet .code .repository .TaskRepository ;
1112import hexlet .code .repository .UserRepository ;
1213import hexlet .code .specification .TaskSpecification ;
@@ -43,16 +44,18 @@ public TaskDTO findByIdTask(Long id) {
4344 }
4445
4546 public TaskDTO createTask (TaskCreateDTO taskData ) {
46- var user = userRepository .findById (taskData .getAssigneeId ())
47- .orElseThrow (() -> new ResourceNotFoundException ("User with id "
48- + taskData .getAssigneeId ()
49- + " not found" ));
47+ Long assigneeId = taskData .getAssigneeId ();
48+ User user = null ;
49+ if (assigneeId != null ) {
50+ user = userRepository .findById (assigneeId )
51+ .orElseThrow (() -> new IllegalArgumentException ("User with id " + assigneeId + " not found" ));
52+ }
53+
5054 var task = taskMapper .map (taskData );
5155 task .setAssignee (user );
5256
5357 taskRepository .save (task );
5458
55-
5659 return taskMapper .map (task );
5760 }
5861
You can’t perform that action at this time.
0 commit comments