Skip to content

Commit 008b360

Browse files
committed
변경, 추가 이벤트의 워딩을 Command 로 변경
1 parent 369b2f3 commit 008b360

File tree

11 files changed

+40
-39
lines changed

11 files changed

+40
-39
lines changed

profile/src/main/java/com/example/research/profile/entity/cache/Profile.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package com.example.research.profile.entity.cache;
22

3-
import com.example.research.profile.entity.event.ProfileChangedEvent;
4-
import com.example.research.profile.entity.event.ProfileSavedEvent;
3+
import com.example.research.profile.entity.command.ProfileChangedCommand;
4+
import com.example.research.profile.entity.command.ProfileSavedCommand;
55
import com.example.research.profile.entity.storage.ProfileEvent;
66

77
import org.springframework.data.annotation.Id;
@@ -36,13 +36,13 @@ public static Profile from(com.example.research.profile.entity.storage.Profile p
3636
}
3737

3838
// 생성 이벤트에서 왔으므로, 항상 active
39-
public static Profile from(ProfileSavedEvent event) {
39+
public static Profile from(ProfileSavedCommand event) {
4040
return from(event.getId(), event.getName(), event.getAge(),
4141
event.getSex(), true, Collections.emptySet());
4242
}
4343

4444
// TODO active 상태
45-
public static Profile from(ProfileChangedEvent event) {
45+
public static Profile from(ProfileChangedCommand event) {
4646
return from(event.getId(), event.getName(), event.getAge(),
4747
event.getSex(), true, Collections.emptySet());
4848
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package com.example.research.profile.entity.command;
2+
3+
import java.io.Serializable;
4+
5+
public interface Command<ID> extends Serializable {
6+
String getTag();
7+
8+
ID getId();
9+
}

profile/src/main/java/com/example/research/profile/entity/event/ProfileChangedEvent.java renamed to profile/src/main/java/com/example/research/profile/entity/command/ProfileChangedCommand.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package com.example.research.profile.entity.event;
1+
package com.example.research.profile.entity.command;
22

33
import com.example.research.profile.entity.storage.Profile;
44

@@ -11,17 +11,17 @@
1111
@Data
1212
@NoArgsConstructor
1313
@AllArgsConstructor
14-
public class ProfileChangedEvent extends ProfileEvent {
15-
public static final String TAG = ProfileChangedEvent.class.getSimpleName();
14+
public class ProfileChangedCommand extends ProfileCommand {
15+
public static final String TAG = ProfileChangedCommand.class.getSimpleName();
1616

1717
String id;
1818
String name;
1919
Integer age;
2020
String sex; // man, woman
2121
LocalDateTime createdAt;
2222

23-
public static ProfileChangedEvent from(Profile storeProfile) {
24-
return new ProfileChangedEvent(
23+
public static ProfileChangedCommand from(Profile storeProfile) {
24+
return new ProfileChangedCommand(
2525
storeProfile.getId(),
2626
storeProfile.getName(), storeProfile.getAge(),
2727
storeProfile.getSex(), storeProfile.getCreatedAt()
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
package com.example.research.profile.entity.command;
2+
3+
public abstract class ProfileCommand implements Command<String> {
4+
}

profile/src/main/java/com/example/research/profile/entity/event/ProfileSavedEvent.java renamed to profile/src/main/java/com/example/research/profile/entity/command/ProfileSavedCommand.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package com.example.research.profile.entity.event;
1+
package com.example.research.profile.entity.command;
22

33
import com.example.research.profile.entity.storage.Profile;
44

@@ -12,17 +12,17 @@
1212
@ToString
1313
@Getter
1414
@RequiredArgsConstructor
15-
public class ProfileSavedEvent extends ProfileEvent {
16-
public static final String TAG = ProfileSavedEvent.class.getSimpleName();
15+
public class ProfileSavedCommand extends ProfileCommand {
16+
public static final String TAG = ProfileSavedCommand.class.getSimpleName();
1717

1818
@NonNull String id;
1919
@NonNull String name;
2020
@NonNull Integer age;
2121
@NonNull String sex; // man, woman
2222
@NonNull LocalDateTime createdAt;
2323

24-
public static ProfileSavedEvent from(Profile storeProfile) {
25-
return new ProfileSavedEvent(
24+
public static ProfileSavedCommand from(Profile storeProfile) {
25+
return new ProfileSavedCommand(
2626
storeProfile.getId(),
2727
storeProfile.getName(), storeProfile.getAge(),
2828
storeProfile.getSex(), storeProfile.getCreatedAt()

profile/src/main/java/com/example/research/profile/entity/event/Event.java

Lines changed: 0 additions & 9 deletions
This file was deleted.

profile/src/main/java/com/example/research/profile/entity/event/ProfileEvent.java

Lines changed: 0 additions & 4 deletions
This file was deleted.

profile/src/main/java/com/example/research/profile/entity/storage/ProfileEvent.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package com.example.research.profile.entity.storage;
22

33
import com.example.research.profile.core.StoredEvent;
4+
import com.example.research.profile.entity.command.ProfileCommand;
45

56
import java.time.LocalDateTime;
67

@@ -43,7 +44,7 @@ public ProfileEvent() {
4344
this.createdAt = LocalDateTime.now();
4445
}
4546

46-
public static ProfileEvent from(com.example.research.profile.entity.event.ProfileEvent event,
47+
public static ProfileEvent from(ProfileCommand event,
4748
Long latestVersion, String payload) {
4849
ProfileEvent profileEvent = new ProfileEvent();
4950
profileEvent.identifier = event.getId();

profile/src/main/java/com/example/research/profile/v1/profile/ProfileEventHandler.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package com.example.research.profile.v1.profile;
22

3-
import com.example.research.profile.entity.event.ProfileEvent;
3+
import com.example.research.profile.entity.command.ProfileCommand;
44
import com.example.research.profile.entity.storage.ProfileEventStoreRepository;
55
import com.example.research.profile.entity.storage.ProfileStorageRepository;
66
import com.fasterxml.jackson.core.JsonProcessingException;
@@ -26,7 +26,7 @@ public class ProfileEventHandler {
2626

2727
@Async
2828
@Transactional
29-
public CompletableFuture<com.example.research.profile.entity.storage.ProfileEvent> save(ProfileEvent event) {
29+
public CompletableFuture<com.example.research.profile.entity.storage.ProfileEvent> save(ProfileCommand event) {
3030
return CompletableFuture.supplyAsync(() -> {
3131
Long latestVersion = profileEventStoreRepository
3232
.findTopByIdentifierOrderByNoDesc(event.getId())
@@ -40,7 +40,7 @@ public CompletableFuture<com.example.research.profile.entity.storage.ProfileEven
4040
});
4141
}
4242

43-
private String generatePayload(ProfileEvent event) {
43+
private String generatePayload(ProfileCommand event) {
4444
String payload;
4545
try {
4646
payload = objectMapper.writeValueAsString(event);

profile/src/main/java/com/example/research/profile/v1/profile/ProfileEventListener.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22

33
import com.example.research.profile.entity.cache.Profile;
44
import com.example.research.profile.entity.cache.ProfileRepository;
5-
import com.example.research.profile.entity.event.ProfileChangedEvent;
6-
import com.example.research.profile.entity.event.ProfileSavedEvent;
5+
import com.example.research.profile.entity.command.ProfileChangedCommand;
6+
import com.example.research.profile.entity.command.ProfileSavedCommand;
77
import com.example.research.profile.entity.storage.ProfileStorageRepository;
88

99
import org.springframework.beans.factory.annotation.Autowired;
@@ -23,7 +23,7 @@ public class ProfileEventListener {
2323
@Autowired ProfileRepository profileRepository;
2424
@Autowired ProfileStorageRepository profileStorageRepository;
2525

26-
@EventListener public void onProfileSavedEventReceived(ProfileSavedEvent event) {
26+
@EventListener public void onProfileSavedEventReceived(ProfileSavedCommand event) {
2727
log.info("onProfileSavedEventReceived received : {}" + event);
2828
profileRepository.save(Profile.from(event))
2929
.flatMap(profile -> Mono.fromCompletionStage(profileEventHandler.save(event)))
@@ -32,7 +32,7 @@ public class ProfileEventListener {
3232
.subscribe();
3333
}
3434

35-
@EventListener public void onProfileChangedEventReceived(ProfileChangedEvent event) {
35+
@EventListener public void onProfileChangedEventReceived(ProfileChangedCommand event) {
3636
log.info("onProfileChangedEventReceived received : {}" + event);
3737

3838
Mono.fromCompletionStage(profileEventHandler.save(event))

0 commit comments

Comments
 (0)