Skip to content

Commit

Permalink
!hotfix: 경매 이미지 url 처리에 방법 변경 (#385)
Browse files Browse the repository at this point in the history
* fix: 경매 이미지 url 처리에 방법 변경

* test: 테스트 실패 문제 해결
  • Loading branch information
JJ503 authored and swonny committed Oct 6, 2023
1 parent dde6956 commit 09253f7
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 22 deletions.
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
package com.ddang.ddang.image.application;

import com.ddang.ddang.image.domain.ProfileImage;
import com.ddang.ddang.image.application.exception.ImageNotFoundException;
import com.ddang.ddang.image.domain.AuctionImage;
import com.ddang.ddang.image.domain.ProfileImage;
import com.ddang.ddang.image.infrastructure.persistence.JpaAuctionImageRepository;
import com.ddang.ddang.image.infrastructure.persistence.JpaImageRepository;
import lombok.RequiredArgsConstructor;
Expand All @@ -28,19 +27,25 @@ public class ImageService {

public Resource readProfileImage(final Long id) throws MalformedURLException {
final ProfileImage profileImage = imageRepository.findById(id)
.orElseThrow(() -> new ImageNotFoundException(
"지정한 이미지를 찾을 수 없습니다."
));
.orElse(null);

if (profileImage == null) {
return null;
}

final String fullPath = findFullPath(profileImage.getImage().getStoreName());

return new UrlResource(FILE_PROTOCOL_PREFIX + fullPath);
}

public Resource readAuctionImage(final Long id) throws MalformedURLException {
final AuctionImage auctionImage = auctionImageRepository.findById(id)
.orElseThrow(() -> new ImageNotFoundException(
"지정한 이미지를 찾을 수 없습니다."
));
.orElse(null);

if (auctionImage == null) {
return null;
}

final String fullPath = findFullPath(auctionImage.getImage().getStoreName());

return new UrlResource(FILE_PROTOCOL_PREFIX + fullPath);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
package com.ddang.ddang.image.application;


import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;

import com.ddang.ddang.image.application.exception.ImageNotFoundException;
import com.ddang.ddang.image.domain.AuctionImage;
import com.ddang.ddang.image.domain.ProfileImage;
import com.ddang.ddang.image.infrastructure.persistence.JpaAuctionImageRepository;
Expand All @@ -17,6 +13,10 @@
import org.springframework.core.io.Resource;
import org.springframework.transaction.annotation.Transactional;

import java.net.MalformedURLException;

import static org.assertj.core.api.Assertions.assertThat;

@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
@Transactional
@DisplayNameGeneration(DisplayNameGenerator.ReplaceUnderscores.class)
Expand Down Expand Up @@ -47,14 +47,15 @@ class ProfileImageServiceTest {
}

@Test
void 지정한_아이디에_해당하는_이미지가_없는_경우_예외가_발생한다() {
void 지정한_아이디에_해당하는_이미지가_없는_경우_null을_반환한다() throws MalformedURLException {
// given
final Long invalidImageId = -999L;

// when & then
assertThatThrownBy(() -> imageService.readProfileImage(invalidImageId))
.isInstanceOf(ImageNotFoundException.class)
.hasMessage("지정한 이미지를 찾을 수 없습니다.");
// when
final Resource actual = imageService.readProfileImage(invalidImageId);

// then
assertThat(actual).isNull();
}

@Test
Expand All @@ -72,13 +73,14 @@ class ProfileImageServiceTest {
}

@Test
void 지정한_아이디에_해당하는_경매_이미지가_없는_경우_예외가_발생한다() {
void 지정한_아이디에_해당하는_경매_이미지가_없는_경우_null을_반환한다() throws MalformedURLException {
// given
final Long invalidAuctionImageId = -999L;

// when & then
assertThatThrownBy(() -> imageService.readAuctionImage(invalidAuctionImageId))
.isInstanceOf(ImageNotFoundException.class)
.hasMessage("지정한 이미지를 찾을 수 없습니다.");
// when
final Resource actual = imageService.readAuctionImage(invalidAuctionImageId);

// then
assertThat(actual).isNull();
}
}

0 comments on commit 09253f7

Please sign in to comment.