-
Notifications
You must be signed in to change notification settings - Fork 1
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 #70 from jkuznik/Task-55-create-toast-builder
Task-55-create-toast-builder
- Loading branch information
Showing
10 changed files
with
136 additions
and
17 deletions.
There are no files selected for viewing
18 changes: 18 additions & 0 deletions
18
src/main/java/pl/ateam/disasteralerts/message/ToastMessage.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,18 @@ | ||
package pl.ateam.disasteralerts.message; | ||
|
||
import jakarta.validation.constraints.NotNull; | ||
import lombok.Builder; | ||
import lombok.Getter; | ||
|
||
@Builder | ||
@Getter | ||
class ToastMessage { | ||
|
||
@NotNull | ||
private ToastMessageType type; | ||
private String icon; | ||
@NotNull | ||
private String header; | ||
@NotNull | ||
private String message; | ||
} |
11 changes: 11 additions & 0 deletions
11
src/main/java/pl/ateam/disasteralerts/message/ToastMessageFacade.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,11 @@ | ||
package pl.ateam.disasteralerts.message; | ||
|
||
import org.springframework.stereotype.Component; | ||
import pl.ateam.disasteralerts.message.dto.ToastMessageDTO; | ||
|
||
@Component | ||
public interface ToastMessageFacade { | ||
|
||
ToastMessageDTO buildMessage(ToastMessageType type, String header, String message); | ||
ToastMessageDTO buildMessage(ToastMessageType type, String icon, String header, String message); | ||
} |
40 changes: 40 additions & 0 deletions
40
src/main/java/pl/ateam/disasteralerts/message/ToastMessageImpl.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,40 @@ | ||
package pl.ateam.disasteralerts.message; | ||
|
||
import org.springframework.stereotype.Service; | ||
import pl.ateam.disasteralerts.message.dto.ToastMessageDTO; | ||
|
||
@Service | ||
class ToastMessageImpl implements ToastMessageFacade { | ||
|
||
private final ToastMessageMapper toastMessageMapper; | ||
|
||
public ToastMessageImpl(ToastMessageMapper toastMessageMapper) { | ||
this.toastMessageMapper = toastMessageMapper; | ||
} | ||
|
||
@Override | ||
public ToastMessageDTO buildMessage(ToastMessageType type, String header, String message) { | ||
String icon = getDefaultIcon(type); | ||
return buildMessage(type, icon, header, message); | ||
} | ||
|
||
@Override | ||
public ToastMessageDTO buildMessage(ToastMessageType type, String icon, String header, String message) { | ||
ToastMessage built = ToastMessage.builder() | ||
.type(type) | ||
.icon(icon) | ||
.header(header) | ||
.message(message) | ||
.build(); | ||
return toastMessageMapper.mapToastMessageToToastMessageDTO(built); | ||
} | ||
|
||
private String getDefaultIcon(ToastMessageType type) { | ||
String icon = "bi bi-balloon-heart-fill"; | ||
switch (type) { | ||
case DANGER -> icon = "bi bi-exclamation-circle-fill"; | ||
case SUCCESS -> icon = "bi bi-check2-square"; | ||
} | ||
return icon; | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
src/main/java/pl/ateam/disasteralerts/message/ToastMessageMapper.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,9 @@ | ||
package pl.ateam.disasteralerts.message; | ||
|
||
import org.mapstruct.Mapper; | ||
import pl.ateam.disasteralerts.message.dto.ToastMessageDTO; | ||
|
||
@Mapper(componentModel = "spring") | ||
interface ToastMessageMapper { | ||
ToastMessageDTO mapToastMessageToToastMessageDTO(ToastMessage toastMessage); | ||
} |
5 changes: 5 additions & 0 deletions
5
src/main/java/pl/ateam/disasteralerts/message/ToastMessageType.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,5 @@ | ||
package pl.ateam.disasteralerts.message; | ||
|
||
public enum ToastMessageType { | ||
DANGER, INFO, SUCCESS | ||
} |
7 changes: 7 additions & 0 deletions
7
src/main/java/pl/ateam/disasteralerts/message/dto/ToastMessageDTO.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,7 @@ | ||
package pl.ateam.disasteralerts.message.dto; | ||
|
||
public record ToastMessageDTO(String type, | ||
String icon, | ||
String header, | ||
String message) { | ||
} |
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
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