use of com.ncedu.fooddelivery.api.v1.entities.File in project 2021-msk-food-delivery by netcracker-edu.
the class FileServiceTest method saveJpegLargeHeightClient.
@Test
public void saveJpegLargeHeightClient() throws IOException {
// prepare
Long userId = 1L;
User rajeshClient = UserUtils.clientRajeshKoothrappali(userId);
MultipartFile file = getImgWithType("testLargeHeight", "jpeg");
Long fileSize = file.getSize();
log.info("FILE SIZE before uploading: " + fileSize + " FILE NAME: " + file.getName());
when(fileRepoMock.save(any(File.class))).thenAnswer(invocation -> invocation.getArguments()[0]);
FileLinkDTO fileLinkDTO = fileService.save(file, rajeshClient);
verify(fileRepoMock, times(1)).save(any(File.class));
Path uploadedFile = getUploadedFilePath(fileLinkDTO.getFileUuid());
assertTrue(Files.exists(uploadedFile));
Long uploadedFileSize = Files.size(uploadedFile);
log.info("FILE SIZE after uploading: " + uploadedFileSize + " FILE UUID: " + fileLinkDTO.getFileUuid());
// uploaded size less than income because convert from jpeg to jpeg with small resolution
assertTrue(fileSize > uploadedFileSize);
BufferedImage bufferedImage = ImageIO.read(uploadedFile.toFile());
assertEquals(CLIENT_IMAGE_HEIGHT, bufferedImage.getHeight());
}
use of com.ncedu.fooddelivery.api.v1.entities.File in project 2021-msk-food-delivery by netcracker-edu.
the class UserServiceImpl method deleteAvatar.
@Override
public void deleteAvatar(User user) {
UUID avatarId = user.getAvatarId();
if (avatarId == null) {
return;
}
user.setAvatarId(null);
userRepo.save(user);
File avatar = fileService.getFile(avatarId);
if (avatar != null) {
fileService.delete(avatar, user);
}
}
use of com.ncedu.fooddelivery.api.v1.entities.File 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);
}
Aggregations