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

Log new video after publishing a new video #21

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,6 @@ out/
# Ignore Gradle GUI config
gradle-app.setting

# IntelliJ .idea folder
.idea/

Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package tv.codely.mooc.notification.application.create;

import tv.codely.mooc.notification.domain.Notifier;
import tv.codely.mooc.video.domain.VideoPublished;
import tv.codely.shared.application.DomainEventSubscriber;

public class NotifyOnVideoPublished implements DomainEventSubscriber<VideoPublished> {
private final Notifier notifier;

public NotifyOnVideoPublished(Notifier notifier) {
this.notifier = notifier;
}

@Override
public Class<VideoPublished> subscribedTo() {
return VideoPublished.class;
}

@Override
public void consume(VideoPublished event) {
notifier.notify(String.format(
"Hey! There is a new video with title <%s> and description <%s>",
event.title(),
event.description()
));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package tv.codely.mooc.notification.domain;

public interface Notifier {
void notify(String message);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package tv.codely.mooc.notification.infrastructure;

public class FileHandlerCantBeCreated extends RuntimeException {
FileHandlerCantBeCreated(String reason) {
super("Can't create file handler:\n" + reason);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package tv.codely.mooc.notification.infrastructure;

import tv.codely.mooc.notification.domain.Notifier;

import java.io.IOException;
import java.util.logging.FileHandler;
import java.util.logging.Logger;

public class LogNotifier implements Notifier {
private final static Logger logger = Logger.getLogger(LogNotifier.class.getName());

public LogNotifier(String fileName) throws FileHandlerCantBeCreated {
try {
FileHandler fileHandler = new FileHandler(fileName, true);
logger.addHandler(fileHandler);
} catch (IOException e) {
throw new FileHandlerCantBeCreated(fileName);
}
}

@Override
public void notify(String text) {
logger.info(text);
}
}