Skip to content

Commit

Permalink
refactor: 이미지 URL 가진 엔티티에 모든 이미지 URL 반환하는 메서드 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
seokjin8678 committed May 30, 2024
1 parent 4c9a07f commit 4477d58
Show file tree
Hide file tree
Showing 9 changed files with 104 additions and 6 deletions.
5 changes: 5 additions & 0 deletions backend/src/main/java/com/festago/artist/domain/Artist.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
import java.util.List;
import lombok.AccessLevel;
import lombok.NoArgsConstructor;

Expand Down Expand Up @@ -49,6 +50,10 @@ public void update(String name, String profileImage, String backgroundImageUrl)
this.backgroundImageUrl = ImageUrlHelper.getBlankStringIfBlank(backgroundImageUrl);
}

public List<String> getImageUrls() {
return List.of(profileImage, backgroundImageUrl);
}

public Long getId() {
return id;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import jakarta.validation.constraints.Size;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.List;
import lombok.AccessLevel;
import lombok.NoArgsConstructor;

Expand Down Expand Up @@ -101,6 +102,10 @@ public void changeFestivalDuration(FestivalDuration festivalDuration) {
this.festivalDuration = festivalDuration;
}

public List<String> getImageUrls() {
return List.of(posterImageUrl);
}

public Long getId() {
return id;
}
Expand Down
5 changes: 5 additions & 0 deletions backend/src/main/java/com/festago/school/domain/School.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import jakarta.persistence.Id;
import jakarta.validation.constraints.NotNull;
import jakarta.validation.constraints.Size;
import java.util.List;
import lombok.AccessLevel;
import lombok.NoArgsConstructor;

Expand Down Expand Up @@ -112,6 +113,10 @@ public void changeBackgroundImageUrl(String backgroundImageUrl) {
this.backgroundUrl = ImageUrlHelper.getBlankStringIfBlank(backgroundImageUrl);
}

public List<String> getImageUrls() {
return List.of(backgroundUrl, logoUrl);
}

public Long getId() {
return id;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,15 @@ public class AsyncArtistUploadImagesStatusChangeEventListener {
public void changeAttachedStatusArtistImagesEventHandler(ArtistCreatedEvent event) {
Artist artist = event.artist();
Long artistId = artist.getId();
List<String> imageUris = List.of(artist.getProfileImage(), artist.getBackgroundImageUrl());
List<String> imageUris = artist.getImageUrls();
uploadFileStatusChangeService.changeAttached(artistId, ARTIST, imageUris);
}

@TransactionalEventListener(value = ArtistUpdatedEvent.class, phase = TransactionPhase.AFTER_COMMIT)
public void changeRenewalStatusArtistImagesEventHandler(ArtistUpdatedEvent event) {
Artist artist = event.artist();
Long artistId = artist.getId();
List<String> imageUris = List.of(artist.getProfileImage(), artist.getBackgroundImageUrl());
List<String> imageUris = artist.getImageUrls();
uploadFileStatusChangeService.changeRenewal(artistId, ARTIST, imageUris);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,15 @@ public class AsyncFestivalUploadImagesStatusChangeEventListener {
public void changeAttachedStatusFestivalImagesEventHandler(FestivalCreatedEvent event) {
Festival festival = event.festival();
Long festivalId = festival.getId();
List<String> imageUris = List.of(festival.getPosterImageUrl());
List<String> imageUris = festival.getImageUrls();
uploadFileStatusChangeService.changeAttached(festivalId, FESTIVAL, imageUris);
}

@TransactionalEventListener(value = FestivalUpdatedEvent.class, phase = TransactionPhase.AFTER_COMMIT)
public void changeRenewalStatusFestivalImagesEventHandler(FestivalUpdatedEvent event) {
Festival festival = event.festival();
Long festivalId = festival.getId();
List<String> imageUris = List.of(festival.getPosterImageUrl());
List<String> imageUris = festival.getImageUrls();
uploadFileStatusChangeService.changeRenewal(festivalId, FESTIVAL, imageUris);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,15 @@ public class AsyncSchoolUploadImagesStatusChangeEventListener {
public void changeAttachedStatusSchoolImagesEventHandler(SchoolCreatedEvent event) {
School school = event.school();
Long schoolId = school.getId();
List<String> imageUris = List.of(school.getBackgroundUrl(), school.getLogoUrl());
List<String> imageUris = school.getImageUrls();
uploadFileStatusChangeService.changeAttached(schoolId, SCHOOL, imageUris);
}

@TransactionalEventListener(value = SchoolUpdatedEvent.class, phase = TransactionPhase.AFTER_COMMIT)
public void changeRenewalStatusSchoolImagesEventHandler(SchoolUpdatedEvent event) {
School school = event.school();
Long schoolId = school.getId();
List<String> imageUris = List.of(school.getBackgroundUrl(), school.getLogoUrl());
List<String> imageUris = school.getImageUrls();
uploadFileStatusChangeService.changeRenewal(schoolId, SCHOOL, imageUris);
}

Expand Down
32 changes: 32 additions & 0 deletions backend/src/test/java/com/festago/artist/domain/ArtistTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package com.festago.artist.domain;

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

import com.festago.support.fixture.ArtistFixture;
import java.util.List;
import org.junit.jupiter.api.DisplayNameGeneration;
import org.junit.jupiter.api.DisplayNameGenerator;
import org.junit.jupiter.api.Nested;
import org.junit.jupiter.api.Test;

@DisplayNameGeneration(DisplayNameGenerator.ReplaceUnderscores.class)
@SuppressWarnings("NonAsciiCharacters")
class ArtistTest {

@Nested
class getImageUrls {

@Test
void 지고_있는_모든_이미지_URL_반환한다() {
// given
Artist artist = ArtistFixture.builder().build();

// when
List<String> imageUrls = artist.getImageUrls();

// then
assertThat(imageUrls)
.containsExactlyInAnyOrder(artist.getProfileImage(), artist.getBackgroundImageUrl());
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package com.festago.festival.domain;

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

import com.festago.support.fixture.FestivalFixture;
import java.util.List;
import org.junit.jupiter.api.DisplayNameGeneration;
import org.junit.jupiter.api.DisplayNameGenerator;
import org.junit.jupiter.api.Nested;
import org.junit.jupiter.api.Test;

@DisplayNameGeneration(DisplayNameGenerator.ReplaceUnderscores.class)
@SuppressWarnings("NonAsciiCharacters")
class FestivalTest {

@Nested
class getImageUrls {

@Test
void 지고_있는_모든_이미지_URL_반환한다() {
// given
Festival festival = FestivalFixture.builder().build();

// when
List<String> imageUrls = festival.getImageUrls();

// then
assertThat(imageUrls)
.containsExactlyInAnyOrder(festival.getPosterImageUrl());
}
}
}
19 changes: 19 additions & 0 deletions backend/src/test/java/com/festago/school/domain/SchoolTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
import static org.assertj.core.api.SoftAssertions.assertSoftly;

import com.festago.common.exception.ValidException;
import com.festago.support.fixture.SchoolFixture;
import java.util.List;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.DisplayNameGeneration;
import org.junit.jupiter.api.DisplayNameGenerator.ReplaceUnderscores;
Expand Down Expand Up @@ -357,4 +359,21 @@ void setUp() {
.isInstanceOf(ValidException.class);
}
}

@Nested
class getImageUrls {

@Test
void 지고_있는_모든_이미지_URL_반환한다() {
// given
School school = SchoolFixture.builder().build();

// when
List<String> imageUrls = school.getImageUrls();

// then
assertThat(imageUrls)
.containsExactlyInAnyOrder(school.getLogoUrl(), school.getBackgroundUrl());
}
}
}

0 comments on commit 4477d58

Please sign in to comment.