Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
…-springboot into seyong#141-fix-reply-alarm
  • Loading branch information
parseyong committed Sep 8, 2024
2 parents 9a74353 + c65cf50 commit 0f4c17d
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ public List<FindAllAlbumsResDto> findAllAlbumsByLoginId(String uid) {
User foundUser = userRepository.findByLoginId(uid).orElseThrow(() -> new CustomException(ExceptionCode.USER_NOT_EXIST));
List<Album> foundAlbums = albumRepository.findAlbumsByUser(foundUser);
return foundAlbums.stream().map(album -> {
Optional<Snap> firstSnapOptional = album.getSnap().isEmpty() ? Optional.empty() : Optional.of(album.getSnap().get(0));
int lastNumber = album.getSnap().size();
Optional<Snap> firstSnapOptional = album.getSnap().isEmpty() ? Optional.empty() : Optional.of(album.getSnap().get(lastNumber-1));
String photoUrl = firstSnapOptional.map(snap -> urlComponent.makePhotoURL(snap.getFileName(), snap.isPrivate())).orElse(null);
return FindAllAlbumsResDto.builder()
.id(album.getId())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import me.snaptime.profilePhoto.service.ProfilePhotoService;
import me.snaptime.user.domain.User;
import me.snaptime.user.repository.UserRepository;
import me.snaptime.util.ProfilePhotoNameGenerator;
import me.snaptime.util.FileNameGenerator;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
Expand Down Expand Up @@ -76,7 +76,7 @@ public ProfilePhotoResDto updatePhotoFromFileSystem(String loginId, MultipartFil
User updateUser = userRepository.findByLoginId(loginId).orElseThrow(()-> new CustomException(ExceptionCode.USER_NOT_EXIST));
ProfilePhoto profilePhoto = profilePhotoRepository.findById(updateUser.getProfilePhoto().getProfilePhotoId()).orElseThrow(()-> new CustomException(ExceptionCode.PROFILE_PHOTO_NOT_FOUND));

String updateFileName = ProfilePhotoNameGenerator.generatorProfilePhotoName(updateFile.getOriginalFilename());
String updateFileName = FileNameGenerator.generatorName(updateFile.getOriginalFilename());
String updateFilePath = FOLDER_PATH + updateFileName;

try{
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/me/snaptime/util/FileNameGenerator.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@

public class FileNameGenerator {

static String currentTime = LocalDateTime.now().format(DateTimeFormatter.ofPattern("MMddHHmmssSSS"));

public static String generatorName(String fileName) {
String currentTime = LocalDateTime.now().format(DateTimeFormatter.ofPattern("MMddHHmmssSSS"));
Random rd = new Random();
int nonNegativeInt = Math.abs(rd.nextInt()); // 음수를 방지하기 위해 절대값을 취합니다.
return currentTime + "_" + nonNegativeInt + "_" + fileName;
Expand Down
12 changes: 0 additions & 12 deletions src/main/java/me/snaptime/util/ProfilePhotoNameGenerator.java

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import me.snaptime.profilePhoto.service.impl.ProfilePhotoServiceImpl;
import me.snaptime.user.domain.User;
import me.snaptime.user.repository.UserRepository;
import me.snaptime.util.ProfilePhotoNameGenerator;
import me.snaptime.util.FileNameGenerator;
import org.junit.jupiter.api.*;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.InjectMocks;
Expand Down Expand Up @@ -70,7 +70,7 @@ void updatePhotoToFileSystemTest() throws Exception {
"profile/jpeg",
new byte[]{});

String fileName = ProfilePhotoNameGenerator.generatorProfilePhotoName(updateFile.getOriginalFilename());
String fileName = FileNameGenerator.generatorName(updateFile.getOriginalFilename());
String filePath = FOLDER_PATH + fileName;

/*업데이트 할 프로필 사진*/
Expand Down

0 comments on commit 0f4c17d

Please sign in to comment.