-
Notifications
You must be signed in to change notification settings - Fork 0
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 #94 from playkuround/feat/userNotification
refactor: user notification
- Loading branch information
Showing
12 changed files
with
165 additions
and
70 deletions.
There are no files selected for viewing
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
21 changes: 21 additions & 0 deletions
21
src/main/java/com/playkuround/playkuroundserver/domain/user/domain/Notification.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,21 @@ | ||
package com.playkuround.playkuroundserver.domain.user.domain; | ||
|
||
import lombok.EqualsAndHashCode; | ||
import lombok.Getter; | ||
|
||
import java.util.Objects; | ||
|
||
@Getter | ||
@EqualsAndHashCode | ||
public class Notification { | ||
|
||
private final String name; | ||
private final String description; | ||
|
||
public Notification(NotificationEnum notificationEnum, String description) { | ||
Objects.requireNonNull(notificationEnum, "notificationEnum must be provided"); | ||
|
||
this.name = notificationEnum.getName(); | ||
this.description = (description == null ? "" : description); | ||
} | ||
} |
47 changes: 47 additions & 0 deletions
47
...main/java/com/playkuround/playkuroundserver/domain/user/domain/NotificationConverter.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,47 @@ | ||
package com.playkuround.playkuroundserver.domain.user.domain; | ||
|
||
import jakarta.persistence.AttributeConverter; | ||
import jakarta.persistence.Converter; | ||
|
||
import java.util.*; | ||
import java.util.stream.Collectors; | ||
|
||
@Converter | ||
public class NotificationConverter implements AttributeConverter<Set<Notification>, String> { | ||
|
||
@Override | ||
public String convertToDatabaseColumn(Set<Notification> notifications) { | ||
if (notifications == null) { | ||
return null; | ||
} | ||
|
||
StringBuilder sb = new StringBuilder(); | ||
for (Notification notification : notifications) { | ||
if (!sb.isEmpty()) { | ||
sb.append("@"); | ||
} | ||
sb.append(notification.getName()) | ||
.append("#") | ||
.append(notification.getDescription()); | ||
} | ||
return sb.toString(); | ||
} | ||
|
||
@Override | ||
public Set<Notification> convertToEntityAttribute(String notifications) { | ||
if (notifications == null || notifications.isEmpty()) { | ||
return new HashSet<>(); | ||
} | ||
return Arrays.stream(notifications.split("@")) | ||
.map(notification -> notification.split("#")) | ||
.filter(nameAndDescription -> nameAndDescription.length == 2) | ||
.map(nameAndDescription -> { | ||
Optional<NotificationEnum> notificationEnum = NotificationEnum.fromString(nameAndDescription[0]); | ||
return notificationEnum | ||
.map(anEnum -> new Notification(anEnum, nameAndDescription[1])) | ||
.orElse(null); | ||
}) | ||
.filter(Objects::nonNull) | ||
.collect(Collectors.toSet()); | ||
} | ||
} |
34 changes: 34 additions & 0 deletions
34
src/main/java/com/playkuround/playkuroundserver/domain/user/domain/NotificationEnum.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,34 @@ | ||
package com.playkuround.playkuroundserver.domain.user.domain; | ||
|
||
import lombok.Getter; | ||
|
||
import java.util.Map; | ||
import java.util.Optional; | ||
import java.util.stream.Stream; | ||
|
||
import static java.util.stream.Collectors.toMap; | ||
|
||
@Getter | ||
public enum NotificationEnum { | ||
|
||
UPDATE("update", "application is must update"), | ||
SYSTEM_CHECK("system_check", "system is not available"), | ||
ALARM("alarm", "user message"), | ||
NEW_BADGE("new_badge", "user get new badge"); | ||
|
||
private static final Map<String, NotificationEnum> stringToEnum = | ||
Stream.of(values()) | ||
.collect(toMap(NotificationEnum::getName, e -> e)); | ||
private final String name; | ||
private final String defaultMessage; | ||
|
||
NotificationEnum(String name, String defaultMessage) { | ||
this.name = name; | ||
this.defaultMessage = defaultMessage; | ||
} | ||
|
||
public static Optional<NotificationEnum> fromString(String source) { | ||
return Optional.ofNullable(stringToEnum.get(source)); | ||
} | ||
|
||
} |
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
Oops, something went wrong.