11package demo .codeexample .user .application ;
22
33import demo .codeexample .exceptions .EmailAlreadyExistsException ;
4+ import demo .codeexample .exceptions .TeamValidationException ;
45import demo .codeexample .exceptions .UserNotFoundException ;
56import demo .codeexample .shared .Role ;
67import demo .codeexample .user .*;
@@ -70,16 +71,30 @@ public Optional<UserDto> findByFullName(String firstname, String lastName) {
7071 * @return true if each user has unique role
7172 */
7273
74+ // @Override
75+ // public void validateUniqueRoles(Set<Long> employeesId) {
76+ // List<Role> foundRoles = employeesId.stream()
77+ // .map(id -> findById(id).orElseThrow(() -> new UserNotFoundException(id)))
78+ // .map(UserDto::getRole)
79+ // .toList();
80+ //
81+ // List<Role> requiredRoles = List.of(Role.PRODUCER, Role.DIRECTOR, Role.EDITOR, Role.RECRUITER);
82+ // if(!foundRoles.containsAll(requiredRoles))
83+ // throw new TeamValidationException();
84+ // }
85+
7386 @ Override
74- public void validateUniqueRoles (Set <Long > employeesId ) {
87+ public boolean validateUniqueRoles (Set <Long > employeesId ) {
7588 List <Role > foundRoles = employeesId .stream ()
76- .map (id -> findById (id ).orElseThrow (() -> new UserNotFoundException (id )))
89+ .map (id -> findById (id )
90+ .orElseThrow (() -> new UserNotFoundException (id )))
7791 .map (UserDto ::getRole )
7892 .toList ();
7993
80- List <Role > requiredRoles = List .of (Role .PRODUCER , Role .DIRECTOR , Role .EDITOR , Role .RECRUITER );
81- if (!foundRoles .containsAll (requiredRoles ))
82- throw new TeamValidationException ();
94+ List <Role > requiredRoles = List .of (
95+ Role .PRODUCER , Role .DIRECTOR , Role .EDITOR , Role .RECRUITER
96+ );
97+ return foundRoles .containsAll (requiredRoles ); // ← return boolean instead of throw
8398 }
8499
85100 @ Override
@@ -94,7 +109,7 @@ public boolean validateUserRole(Long id, Role role) {
94109 // ─────────────────────────────────────────
95110
96111 @ Override
97- public UserDto createUser (CreateUserRequestDTO request ) {
112+ public UserDto createUser (CreateUserDto request ) {
98113
99114 // Check email is not already taken
100115 if (repository .existsByEmail (request .getEmail ())) {
0 commit comments