Skip to content

Commit a8e9a3b

Browse files
committed
Add presenter
1 parent 8fe3d7b commit a8e9a3b

File tree

3 files changed

+14
-17
lines changed

3 files changed

+14
-17
lines changed
Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,21 @@
11
package org.hydev.mcpm.client.commands.controllers;
22

3+
import org.hydev.mcpm.client.display.presenters.LogExportPresenter;
34
import org.hydev.mcpm.client.export.ExportPluginsBoundary;
45
import org.hydev.mcpm.client.export.ExportPluginsInput;
56

67
import java.util.function.Consumer;
78

89
/**
910
* Controller for the export plugins use case.
11+
*
12+
* @param boundary The export implementation
13+
* @param presenter The presenter to show the result
1014
*/
11-
public class ExportPluginsController {
12-
private final ExportPluginsBoundary boundary;
13-
14-
/**
15-
* Create a controller using the given boundary to process
16-
*
17-
* @param boundary the boundary to process the use case
18-
*/
19-
public ExportPluginsController(ExportPluginsBoundary boundary) {
20-
this.boundary = boundary;
21-
}
15+
public record ExportPluginsController(
16+
ExportPluginsBoundary boundary,
17+
LogExportPresenter presenter
18+
) {
2219

2320
/**
2421
* Call the boundary to perform an export.
@@ -28,6 +25,6 @@ public ExportPluginsController(ExportPluginsBoundary boundary) {
2825
*/
2926
public void export(ExportPluginsInput input, Consumer<String> log) {
3027
var result = boundary.export(input);
31-
log.accept(String.format("Export status: %s\n", result.state().toString()));
28+
presenter.present(result, log);
3229
}
3330
}

src/main/java/org/hydev/mcpm/client/commands/presenters/ExportPresenter.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,11 @@
22

33
import org.hydev.mcpm.client.export.ExportPluginsResult;
44

5+
import java.util.function.Consumer;
6+
57
/**
68
* Interface for presenting the export use case
79
*/
810
public interface ExportPresenter {
9-
void present(ExportPluginsResult exportPluginsResult);
11+
void present(ExportPluginsResult exportPluginsResult, Consumer<String> log);
1012
}

src/main/java/org/hydev/mcpm/client/display/presenters/LogExportPresenter.java

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

88
/**
99
* ExportPresenter that presents to a log.
10-
*
11-
* @param log The log to present to
1210
*/
13-
public record LogExportPresenter(Consumer<String> log) implements ExportPresenter {
11+
public class LogExportPresenter implements ExportPresenter {
1412

1513
private String getColor(ExportPluginsResult exportPluginsResult) {
1614
return switch (exportPluginsResult.state()) {
@@ -28,7 +26,7 @@ private String getMessage(ExportPluginsResult exportPluginsResult) {
2826

2927

3028
@Override
31-
public void present(ExportPluginsResult exportPluginsResult) {
29+
public void present(ExportPluginsResult exportPluginsResult, Consumer<String> log) {
3230
log.accept(getColor(exportPluginsResult) + getMessage(exportPluginsResult));
3331
}
3432
}

0 commit comments

Comments
 (0)