Search in sources :

Example 11 with UserInfoDTO

use of com.ncedu.fooddelivery.api.v1.dto.user.UserInfoDTO in project 2021-msk-food-delivery by netcracker-edu.

the class UserServiceImpl method getAllAdmins.

public List<UserInfoDTO> getAllAdmins() {
    Role adminRole = Role.ADMIN;
    List<User> admins = userRepo.findByRole(adminRole);
    List<UserInfoDTO> adminsDTO = new ArrayList<>();
    for (User admin : admins) {
        adminsDTO.add(createUserDTO(admin));
    }
    return adminsDTO;
}
Also used : Role(com.ncedu.fooddelivery.api.v1.entities.Role) User(com.ncedu.fooddelivery.api.v1.entities.User) UserInfoDTO(com.ncedu.fooddelivery.api.v1.dto.user.UserInfoDTO)

Example 12 with UserInfoDTO

use of com.ncedu.fooddelivery.api.v1.dto.user.UserInfoDTO in project 2021-msk-food-delivery by netcracker-edu.

the class UserServiceImpl method addAvatar.

@Override
public UserInfoDTO addAvatar(User authedUser, String fileUuid) {
    UUID avatarId = UUID.fromString(fileUuid);
    File avatar = fileService.getFile(avatarId);
    authedUser.setAvatarId(avatar.getId());
    userRepo.save(authedUser);
    return createUserDTO(authedUser);
}
Also used : File(com.ncedu.fooddelivery.api.v1.entities.File)

Example 13 with UserInfoDTO

use of com.ncedu.fooddelivery.api.v1.dto.user.UserInfoDTO in project 2021-msk-food-delivery by netcracker-edu.

the class UserServiceTest method getAllAdminsSuccess.

@Test
public void getAllAdminsSuccess() {
    Long userId = 1L;
    User sheldonAdmin = UserUtils.adminSheldonCooper(userId);
    List<User> admins = new ArrayList<>();
    admins.add(sheldonAdmin);
    when(userRepoMock.findByRole(Role.ADMIN)).thenReturn(admins);
    List<UserInfoDTO> resultDTO = userService.getAllAdmins();
    List<UserInfoDTO> perfectDTO = new ArrayList<>();
    perfectDTO.add(UserUtils.createUserDTO(sheldonAdmin));
    assertEquals(perfectDTO, resultDTO);
    verify(userRepoMock, times(1)).findByRole(Role.ADMIN);
}
Also used : User(com.ncedu.fooddelivery.api.v1.entities.User) ArrayList(java.util.ArrayList) UserInfoDTO(com.ncedu.fooddelivery.api.v1.dto.user.UserInfoDTO) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Aggregations

User (com.ncedu.fooddelivery.api.v1.entities.User)12 Test (org.junit.jupiter.api.Test)11 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)11 UserInfoDTO (com.ncedu.fooddelivery.api.v1.dto.user.UserInfoDTO)9 Timestamp (java.sql.Timestamp)3 ArrayList (java.util.ArrayList)3 Role (com.ncedu.fooddelivery.api.v1.entities.Role)2 PageImpl (org.springframework.data.domain.PageImpl)2 Pageable (org.springframework.data.domain.Pageable)2 EmailChangeDTO (com.ncedu.fooddelivery.api.v1.dto.user.EmailChangeDTO)1 PasswordChangeDTO (com.ncedu.fooddelivery.api.v1.dto.user.PasswordChangeDTO)1 File (com.ncedu.fooddelivery.api.v1.entities.File)1 AlreadyExistsException (com.ncedu.fooddelivery.api.v1.errors.badrequest.AlreadyExistsException)1 PasswordsMismatchException (com.ncedu.fooddelivery.api.v1.errors.badrequest.PasswordsMismatchException)1 NotFoundEx (com.ncedu.fooddelivery.api.v1.errors.notfound.NotFoundEx)1 UserRepo (com.ncedu.fooddelivery.api.v1.repos.UserRepo)1 List (java.util.List)1 Optional (java.util.Optional)1 Collectors (java.util.stream.Collectors)1 Slf4j (lombok.extern.slf4j.Slf4j)1