From 93b6ed0ed9e11ac0de509487d73c52cf5c0bc690 Mon Sep 17 00:00:00 2001 From: seokjin8678 Date: Tue, 7 May 2024 15:57:21 +0900 Subject: [PATCH] =?UTF-8?q?fix:=20=EC=95=84=ED=8B=B0=EC=8A=A4=ED=8A=B8=20?= =?UTF-8?q?=EC=83=9D=EC=84=B1,=20=EC=88=98=EC=A0=95,=20=EC=82=AD=EC=A0=9C?= =?UTF-8?q?=20=EC=9D=B4=EB=B2=A4=ED=8A=B8=20=EB=B0=9C=ED=96=89=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../festago/artist/application/ArtistCommandService.java | 8 ++++++++ .../artist/application/ArtistCommandServiceTest.java | 4 +++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/backend/src/main/java/com/festago/artist/application/ArtistCommandService.java b/backend/src/main/java/com/festago/artist/application/ArtistCommandService.java index 8e38368b7..ec4b82c22 100644 --- a/backend/src/main/java/com/festago/artist/application/ArtistCommandService.java +++ b/backend/src/main/java/com/festago/artist/application/ArtistCommandService.java @@ -3,8 +3,12 @@ import com.festago.artist.domain.Artist; import com.festago.artist.dto.command.ArtistCreateCommand; import com.festago.artist.dto.command.ArtistUpdateCommand; +import com.festago.artist.dto.event.ArtistCreatedEvent; +import com.festago.artist.dto.event.ArtistDeletedEvent; +import com.festago.artist.dto.event.ArtistUpdatedEvent; import com.festago.artist.repository.ArtistRepository; import lombok.RequiredArgsConstructor; +import org.springframework.context.ApplicationEventPublisher; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -14,20 +18,24 @@ public class ArtistCommandService { private final ArtistRepository artistRepository; + private final ApplicationEventPublisher eventPublisher; public Long save(ArtistCreateCommand command) { Artist artist = artistRepository.save( new Artist(command.name(), command.profileImageUrl(), command.backgroundImageUrl()) ); + eventPublisher.publishEvent(new ArtistCreatedEvent(artist)); return artist.getId(); } public void update(ArtistUpdateCommand command, Long artistId) { Artist artist = artistRepository.getOrThrow(artistId); artist.update(command.name(), command.profileImageUrl(), command.backgroundImageUrl()); + eventPublisher.publishEvent(new ArtistUpdatedEvent(artist)); } public void delete(Long artistId) { artistRepository.deleteById(artistId); + eventPublisher.publishEvent(new ArtistDeletedEvent(artistId)); } } diff --git a/backend/src/test/java/com/festago/artist/application/ArtistCommandServiceTest.java b/backend/src/test/java/com/festago/artist/application/ArtistCommandServiceTest.java index 5d1ba42cd..f8ce4ef82 100644 --- a/backend/src/test/java/com/festago/artist/application/ArtistCommandServiceTest.java +++ b/backend/src/test/java/com/festago/artist/application/ArtistCommandServiceTest.java @@ -2,6 +2,7 @@ import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.SoftAssertions.assertSoftly; +import static org.mockito.BDDMockito.*; import com.festago.artist.domain.Artist; import com.festago.artist.dto.command.ArtistCreateCommand; @@ -13,6 +14,7 @@ import org.junit.jupiter.api.DisplayNameGeneration; import org.junit.jupiter.api.DisplayNameGenerator; import org.junit.jupiter.api.Test; +import org.mockito.BDDMockito; @DisplayNameGeneration(DisplayNameGenerator.ReplaceUnderscores.class) @SuppressWarnings("NonAsciiCharacters") @@ -25,7 +27,7 @@ class ArtistCommandServiceTest { @BeforeEach void setUp() { artistRepository = new MemoryArtistRepository(); - artistCommandService = new ArtistCommandService(artistRepository); + artistCommandService = new ArtistCommandService(artistRepository, mock()); } @Test