-
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.
[SAMBAD-271] 알림 목록 조회 및 알림 메시지 템플릿 기능 추가
- Loading branch information
Showing
20 changed files
with
407 additions
and
42 deletions.
There are no files selected for viewing
23 changes: 23 additions & 0 deletions
23
src/main/java/org/depromeet/sambad/moring/common/config/CacheConfig.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,23 @@ | ||
package org.depromeet.sambad.moring.common.config; | ||
|
||
import java.util.List; | ||
|
||
import org.springframework.cache.CacheManager; | ||
import org.springframework.cache.annotation.EnableCaching; | ||
import org.springframework.cache.concurrent.ConcurrentMapCacheManager; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
|
||
@EnableCaching | ||
@Configuration | ||
public class CacheConfig { | ||
|
||
@Bean | ||
public CacheManager cacheManager() { | ||
ConcurrentMapCacheManager cacheManager = new ConcurrentMapCacheManager(); | ||
cacheManager.setAllowNullValues(false); | ||
cacheManager.setCacheNames(List.of("eventTemplates")); | ||
return cacheManager; | ||
} | ||
|
||
} |
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
14 changes: 14 additions & 0 deletions
14
src/main/java/org/depromeet/sambad/moring/common/logging/NoLogging.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,14 @@ | ||
package org.depromeet.sambad.moring.common.logging; | ||
|
||
import java.lang.annotation.ElementType; | ||
import java.lang.annotation.Retention; | ||
import java.lang.annotation.RetentionPolicy; | ||
import java.lang.annotation.Target; | ||
|
||
/** | ||
* 메서드에 부착 시, ExecutionLoggingAdvice 내 로깅 대상에서 제외합니다. | ||
*/ | ||
@Target(ElementType.METHOD) | ||
@Retention(RetentionPolicy.RUNTIME) | ||
public @interface NoLogging { | ||
} |
11 changes: 11 additions & 0 deletions
11
...in/java/org/depromeet/sambad/moring/event/application/EventMessageTemplateRepository.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 org.depromeet.sambad.moring.event.application; | ||
|
||
import java.util.Optional; | ||
|
||
import org.depromeet.sambad.moring.event.domain.EventMessageTemplate; | ||
import org.depromeet.sambad.moring.event.domain.EventType; | ||
|
||
public interface EventMessageTemplateRepository { | ||
|
||
Optional<EventMessageTemplate> findByType(EventType type); | ||
} |
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
43 changes: 43 additions & 0 deletions
43
src/main/java/org/depromeet/sambad/moring/event/domain/EventMessageTemplate.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,43 @@ | ||
package org.depromeet.sambad.moring.event.domain; | ||
|
||
import static jakarta.persistence.EnumType.*; | ||
import static jakarta.persistence.GenerationType.*; | ||
import static lombok.AccessLevel.*; | ||
|
||
import java.util.Map; | ||
import java.util.regex.Matcher; | ||
import java.util.regex.Pattern; | ||
|
||
import jakarta.persistence.Column; | ||
import jakarta.persistence.Entity; | ||
import jakarta.persistence.Enumerated; | ||
import jakarta.persistence.GeneratedValue; | ||
import jakarta.persistence.Id; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
|
||
@Getter | ||
@Entity | ||
@NoArgsConstructor(access = PROTECTED) | ||
public class EventMessageTemplate { | ||
|
||
@Id | ||
@GeneratedValue(strategy = IDENTITY) | ||
@Column(name = "event_template_id") | ||
private Long id; | ||
|
||
@Enumerated(STRING) | ||
@Column(columnDefinition = "varchar(50)") | ||
private EventType type; | ||
|
||
private String template; | ||
|
||
public String replaceTemplateVariables(Map<String, String> contentsMap) { | ||
String message = template; | ||
for (String key : contentsMap.keySet()) { | ||
String regex = Pattern.quote("#{" + key + "}"); | ||
message = message.replaceAll(regex, Matcher.quoteReplacement(contentsMap.get(key))); | ||
} | ||
return message; | ||
} | ||
} |
17 changes: 0 additions & 17 deletions
17
src/main/java/org/depromeet/sambad/moring/event/domain/EventType.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 |
---|---|---|
@@ -1,25 +1,8 @@ | ||
package org.depromeet.sambad.moring.event.domain; | ||
|
||
import java.util.HashSet; | ||
import java.util.Set; | ||
|
||
import org.depromeet.sambad.moring.meeting.member.domain.MeetingMember; | ||
import org.depromeet.sambad.moring.meeting.question.domain.MeetingQuestion; | ||
|
||
public enum EventType { | ||
QUESTION_REGISTERED, | ||
TARGET_MEMBER, | ||
HAND_WAVING_REQUESTED, | ||
; | ||
|
||
public static Set<EventType> of(MeetingQuestion meetingQuestion, MeetingMember loginMember) { | ||
Set<EventType> eventTypes = new HashSet<>(); | ||
if (meetingQuestion.getQuestion() != null) { | ||
eventTypes.add(EventType.QUESTION_REGISTERED); | ||
} | ||
if (meetingQuestion.getTargetMember().equals(loginMember)) { | ||
eventTypes.add(EventType.TARGET_MEMBER); | ||
} | ||
return eventTypes; | ||
} | ||
} |
41 changes: 41 additions & 0 deletions
41
src/main/java/org/depromeet/sambad/moring/event/domain/MapToJsonConverter.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,41 @@ | ||
package org.depromeet.sambad.moring.event.domain; | ||
|
||
import java.io.IOException; | ||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
import com.fasterxml.jackson.core.JsonProcessingException; | ||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
|
||
import jakarta.persistence.AttributeConverter; | ||
import jakarta.persistence.Converter; | ||
|
||
@Converter | ||
public class MapToJsonConverter implements AttributeConverter<Map<String, Object>, String> { | ||
|
||
private final ObjectMapper objectMapper = new ObjectMapper(); | ||
|
||
@Override | ||
public String convertToDatabaseColumn(Map<String, Object> attribute) { | ||
if (attribute == null) { | ||
return null; | ||
} | ||
try { | ||
return objectMapper.writeValueAsString(attribute); | ||
} catch (JsonProcessingException e) { | ||
throw new IllegalArgumentException("Could not convert map to JSON", e); | ||
} | ||
} | ||
|
||
@Override | ||
public Map<String, Object> convertToEntityAttribute(String dbData) { | ||
if (dbData == null) { | ||
return null; | ||
} | ||
try { | ||
return objectMapper.readValue(dbData, HashMap.class); | ||
} catch (IOException e) { | ||
throw new IllegalArgumentException("Could not convert JSON to map", e); | ||
} | ||
} | ||
} |
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
12 changes: 12 additions & 0 deletions
12
...a/org/depromeet/sambad/moring/event/infrastructure/EventMessageTemplateJpaRepository.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,12 @@ | ||
package org.depromeet.sambad.moring.event.infrastructure; | ||
|
||
import java.util.Optional; | ||
|
||
import org.depromeet.sambad.moring.event.domain.EventMessageTemplate; | ||
import org.depromeet.sambad.moring.event.domain.EventType; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
|
||
public interface EventMessageTemplateJpaRepository extends JpaRepository<EventMessageTemplate, Long> { | ||
|
||
Optional<EventMessageTemplate> findByType(EventType type); | ||
} |
35 changes: 35 additions & 0 deletions
35
.../org/depromeet/sambad/moring/event/infrastructure/EventMessageTemplateRepositoryImpl.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,35 @@ | ||
package org.depromeet.sambad.moring.event.infrastructure; | ||
|
||
import java.util.Optional; | ||
|
||
import org.depromeet.sambad.moring.common.logging.NoLogging; | ||
import org.depromeet.sambad.moring.event.application.EventMessageTemplateRepository; | ||
import org.depromeet.sambad.moring.event.domain.EventMessageTemplate; | ||
import org.depromeet.sambad.moring.event.domain.EventType; | ||
import org.springframework.cache.annotation.CacheEvict; | ||
import org.springframework.cache.annotation.Cacheable; | ||
import org.springframework.scheduling.annotation.Scheduled; | ||
import org.springframework.stereotype.Repository; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
|
||
@Slf4j | ||
@RequiredArgsConstructor | ||
@Repository | ||
public class EventMessageTemplateRepositoryImpl implements EventMessageTemplateRepository { | ||
|
||
private final EventMessageTemplateJpaRepository eventMessageTemplateJpaRepository; | ||
|
||
@Override | ||
@Cacheable(value = "eventTemplates", key = "#type", unless = "#result == null") | ||
public Optional<EventMessageTemplate> findByType(EventType type) { | ||
return eventMessageTemplateJpaRepository.findByType(type); | ||
} | ||
|
||
@NoLogging | ||
@CacheEvict(value = "eventTemplates", allEntries = true) | ||
@Scheduled(fixedRateString = "${caching.spring.event-templates-ttl}") | ||
public void evictAllCaches() { | ||
} | ||
} |
Oops, something went wrong.