Skip to content
This repository was archived by the owner on Nov 6, 2023. It is now read-only.

Commit 41530f8

Browse files
committed
Add VideoTitle and VideoDescription Value Objects examples:
* I've go for doing the conversion between primitive types to value objects inside the Application Service. We're used to to do so in the Command/Query handler, and when we don't have a command/query bus we tend to do so in the entrypoint controller. However, I think this way we avoid some boilerplate on the different entrypoints a use case might have, and we avoid coupling our infrastructure to all the internal structure of our domain. What do you think? * Move `tv.codely.Starter` to `tv.codely.context.video.module.video.infrastructure.VideoPublisherCliController` in order to serve as entrypoint controller through CLI
1 parent 763b86a commit 41530f8

File tree

8 files changed

+67
-23
lines changed

8 files changed

+67
-23
lines changed

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,5 +30,5 @@ test {
3030
}
3131

3232
application {
33-
mainClassName = "tv.codely.Starter"
33+
mainClassName = "tv.codely.context.video.module.video.infrastructure.VideoPublisherCliController"
3434
}
Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package tv.codely.context.video.module.video.application.publish;
22

33
import tv.codely.context.video.module.video.domain.Video;
4+
import tv.codely.context.video.module.video.domain.VideoDescription;
5+
import tv.codely.context.video.module.video.domain.VideoTitle;
46
import tv.codely.shared.domain.EventBus;
57

68
public final class VideoPublisher {
@@ -10,10 +12,12 @@ public VideoPublisher(EventBus eventBus) {
1012
this.eventBus = eventBus;
1113
}
1214

13-
public void publish(String title, String description) {
15+
public void publish(String rawTitle, String rawDescription) {
16+
final var title = new VideoTitle(rawTitle);
17+
final var description = new VideoDescription(rawDescription);
18+
1419
final var video = Video.publish(title, description);
1520

1621
eventBus.publish(video.pullDomainEvents());
1722
}
18-
1923
}

src/main/java/tv/codely/context/video/module/video/domain/Video.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,18 @@
33
import tv.codely.shared.domain.AggregateRoot;
44

55
public final class Video extends AggregateRoot {
6-
private final String title;
7-
private final String description;
6+
private final VideoTitle title;
7+
private final VideoDescription description;
88

9-
private Video(String title, String description) {
9+
private Video(VideoTitle title, VideoDescription description) {
1010
this.title = title;
1111
this.description = description;
1212
}
1313

14-
public static Video publish(String title, String description) {
14+
public static Video publish(VideoTitle title, VideoDescription description) {
1515
var video = new Video(title, description);
1616

17-
var videoCreated = new VideoPublished(title, description);
17+
var videoCreated = new VideoPublished(title.value(), description.value());
1818

1919
video.record(videoCreated);
2020

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package tv.codely.context.video.module.video.domain;
2+
3+
public final class VideoDescription {
4+
private final String value;
5+
6+
public VideoDescription(final String value) {
7+
this.value = value;
8+
}
9+
10+
public String value() {
11+
return value;
12+
}
13+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package tv.codely.context.video.module.video.domain;
2+
3+
public final class VideoTitle {
4+
private final String value;
5+
6+
public VideoTitle(String value) {
7+
this.value = value;
8+
}
9+
10+
public String value() {
11+
return value;
12+
}
13+
}

src/main/java/tv/codely/Starter.java renamed to src/main/java/tv/codely/context/video/module/video/infrastructure/VideoPublisherCliController.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package tv.codely;
1+
package tv.codely.context.video.module.video.infrastructure;
22

33
import tv.codely.context.notification.module.push.application.create.SendPushToSubscribersOnVideoPublished;
44
import tv.codely.context.video.module.video.application.publish.VideoPublisher;
@@ -8,7 +8,7 @@
88

99
import java.util.Set;
1010

11-
public class Starter {
11+
public class VideoPublisherCliController {
1212
public static void main(String[] args) {
1313
final Set<DomainEventSubscriber> subscribers = Set.of(
1414
new SendPushToSubscribersOnVideoPublished()

src/test/java/tv/codely/StarterShould.java

Lines changed: 0 additions & 13 deletions
This file was deleted.
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package tv.codely.context.video.module.video.application.publish;
2+
3+
import org.junit.jupiter.api.Test;
4+
import tv.codely.context.notification.module.push.application.create.SendPushToSubscribersOnVideoPublished;
5+
import tv.codely.shared.application.DomainEventSubscriber;
6+
import tv.codely.shared.domain.EventBus;
7+
import tv.codely.shared.infrastructure.bus.ReactorEventBus;
8+
9+
import java.util.Set;
10+
11+
final class VideoPublisherShould {
12+
@Test
13+
void publish_the_video_published_domain_event() {
14+
final Set<DomainEventSubscriber> subscribers = Set.of(
15+
new SendPushToSubscribersOnVideoPublished()
16+
);
17+
final EventBus eventBus = new ReactorEventBus(subscribers);
18+
final var videoPublisher = new VideoPublisher(eventBus);
19+
20+
final var videoTitle = "\uD83C\uDF89 New YouTube.com/CodelyTV video title";
21+
final var videoDescription = "This should be the video description \uD83D\uDE42";
22+
23+
videoPublisher.publish(videoTitle, videoDescription);
24+
25+
}
26+
27+
}

0 commit comments

Comments
 (0)