Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BE] refactor: 이미지 URL을 가진 엔티티에 모든 이미지 URL 반환하는 메서드 추가 (#999) #1000

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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());
}
}
}
Loading