-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #940 from woowacourse-teams/develop
Release 1.6.2
- Loading branch information
Showing
14 changed files
with
195 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
backend/src/main/java/team/teamby/teambyteam/notice/domain/event/NoticeCreationEvent.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package team.teamby.teambyteam.notice.domain.event; | ||
|
||
import team.teamby.teambyteam.common.domain.DomainEvent; | ||
import team.teamby.teambyteam.notice.domain.Notice; | ||
|
||
public class NoticeCreationEvent implements DomainEvent<Long> { | ||
|
||
public static final String NOTICE_NOT_CREATED_MESSAGE_FORMAT = "아직 생성되지 않은 공지입니다. teamplaceId: %d"; | ||
private final Long id; | ||
|
||
public NoticeCreationEvent(final Notice notice) { | ||
validate(notice); | ||
this.id = notice.getId(); | ||
} | ||
|
||
private static void validate(Notice notice) { | ||
if(notice.getId() == null) { | ||
throw new RuntimeException(String.format(NOTICE_NOT_CREATED_MESSAGE_FORMAT, notice.getTeamPlaceId())); | ||
} | ||
} | ||
|
||
@Override | ||
public Long getDomainId() { | ||
return id; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
58 changes: 58 additions & 0 deletions
58
...rc/main/java/team/teamby/teambyteam/sse/domain/converter/NoticeCreatedEventConverter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
package team.teamby.teambyteam.sse.domain.converter; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Component; | ||
import team.teamby.teambyteam.common.domain.DomainEvent; | ||
import team.teamby.teambyteam.notice.domain.NoticeRepository; | ||
import team.teamby.teambyteam.notice.domain.event.NoticeCreationEvent; | ||
import team.teamby.teambyteam.sse.domain.TeamPlaceSseEvent; | ||
import team.teamby.teambyteam.sse.domain.emitter.TeamPlaceEmitterId; | ||
|
||
@Component | ||
@RequiredArgsConstructor | ||
public class NoticeCreatedEventConverter implements TeamPlaceSseConverter<Long> { | ||
|
||
private final NoticeRepository noticeRepository; | ||
|
||
@Override | ||
public TeamPlaceSseEvent convert(DomainEvent<Long> event) { | ||
final Long noticeId = event.getDomainId(); | ||
final Long teamPlaceId = noticeRepository.findTeamPlaceIdByNoticeId(noticeId) | ||
.orElseThrow(() -> new RuntimeException(String.format("팀플레이스 공지를 찾을 수 없습니다. id : %d", noticeId))); | ||
return new NoticeCreatedSse(noticeId, teamPlaceId); | ||
} | ||
|
||
@Override | ||
public String supportEventName() { | ||
return NoticeCreationEvent.class.getName(); | ||
} | ||
|
||
private static class NoticeCreatedSse implements TeamPlaceSseEvent { | ||
|
||
private static final String EVENT_NAME = "new_notice"; | ||
|
||
private final NoticeSse event; | ||
|
||
public NoticeCreatedSse(final Long id, final Long teamPlaceId) { | ||
this.event = new NoticeSse(id, teamPlaceId); | ||
} | ||
|
||
@Override | ||
public Long getTeamPlaceId() { | ||
return event.teamPlaceId; | ||
} | ||
|
||
@Override | ||
public String getEventName() { | ||
return EVENT_NAME; | ||
} | ||
|
||
@Override | ||
public Object getEvent(TeamPlaceEmitterId emitterId) { | ||
return event; | ||
} | ||
|
||
private record NoticeSse(Long id, Long teamPlaceId) { | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
61 changes: 61 additions & 0 deletions
61
...est/java/team/teamby/teambyteam/sse/domain/converter/NoticeCreatedEventConverterTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
package team.teamby.teambyteam.sse.domain.converter; | ||
|
||
import org.junit.jupiter.api.DisplayName; | ||
import org.junit.jupiter.api.Test; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.boot.test.context.SpringBootTest; | ||
import org.springframework.test.context.jdbc.Sql; | ||
import team.teamby.teambyteam.common.builder.TestFixtureBuilder; | ||
import team.teamby.teambyteam.common.fixtures.MemberFixtures; | ||
import team.teamby.teambyteam.common.fixtures.NoticeFixtures; | ||
import team.teamby.teambyteam.common.fixtures.TeamPlaceFixtures; | ||
import team.teamby.teambyteam.member.domain.Member; | ||
import team.teamby.teambyteam.notice.domain.Notice; | ||
import team.teamby.teambyteam.notice.domain.event.NoticeCreationEvent; | ||
import team.teamby.teambyteam.sse.domain.TeamPlaceSseEvent; | ||
import team.teamby.teambyteam.teamplace.domain.TeamPlace; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.NONE) | ||
@Sql({"/h2-truncate.sql"}) | ||
class NoticeCreatedEventConverterTest { | ||
|
||
@Autowired | ||
private NoticeCreatedEventConverter noticeCreatedEventConverter; | ||
|
||
@Autowired | ||
private TestFixtureBuilder testFixtureBuilder; | ||
|
||
@Test | ||
@DisplayName("NoticeCreatedEvent 지원 확인") | ||
void isSupportNoticeCreatedEvent() { | ||
// given | ||
final String expected = NoticeCreationEvent.class.getName(); | ||
|
||
// when | ||
final String actual = noticeCreatedEventConverter.supportEventName(); | ||
|
||
// then | ||
assertThat(actual).isEqualTo(expected); | ||
} | ||
|
||
@Test | ||
@DisplayName("Notice 이벤트 변환 테스트") | ||
void convert() { | ||
// given | ||
final Member member = testFixtureBuilder.buildMember(MemberFixtures.ROY()); | ||
final TeamPlace teamPlace = testFixtureBuilder.buildTeamPlace(TeamPlaceFixtures.CONTROLS_TEAM_PLACE()); | ||
testFixtureBuilder.buildMemberTeamPlace(member, teamPlace); | ||
final Notice createdNotice = testFixtureBuilder.buildNotice(NoticeFixtures.NOTICE_1ST(teamPlace.getId(), member.getId())); | ||
|
||
final NoticeCreationEvent noticeCreationEvent = new NoticeCreationEvent(createdNotice); | ||
|
||
// when | ||
final TeamPlaceSseEvent convertedEvent = noticeCreatedEventConverter.convert(noticeCreationEvent); | ||
|
||
// then | ||
assertThat(convertedEvent.getTeamPlaceId()).isEqualTo(teamPlace.getId()); | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters