Skip to content

Commit 1c342e7

Browse files
changed TaskService.java
1 parent 8692820 commit 1c342e7

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

src/main/java/hexlet/code/service/TaskService.java

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import hexlet.code.exception.ResourceNotFoundException;
88
import hexlet.code.mapper.TaskMapper;
99
import hexlet.code.model.Task;
10+
import hexlet.code.model.User;
1011
import hexlet.code.repository.TaskRepository;
1112
import hexlet.code.repository.UserRepository;
1213
import 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

0 commit comments

Comments
 (0)