Skip to content

Commit

Permalink
fix: 아티스트 생성, 수정, 삭제 이벤트 발행 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
seokjin8678 committed May 7, 2024
1 parent 9688d4e commit 93b6ed0
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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")
Expand All @@ -25,7 +27,7 @@ class ArtistCommandServiceTest {
@BeforeEach
void setUp() {
artistRepository = new MemoryArtistRepository();
artistCommandService = new ArtistCommandService(artistRepository);
artistCommandService = new ArtistCommandService(artistRepository, mock());
}

@Test
Expand Down

0 comments on commit 93b6ed0

Please sign in to comment.