-
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 #149 from dnd-side-project/dev
release v0.2.9
- Loading branch information
Showing
10 changed files
with
152 additions
and
6 deletions.
There are no files selected for viewing
20 changes: 20 additions & 0 deletions
20
src/main/java/com/dnd/namuiwiki/common/exception/AsyncExceptionHandler.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,20 @@ | ||
package com.dnd.namuiwiki.common.exception; | ||
|
||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.aop.interceptor.AsyncUncaughtExceptionHandler; | ||
|
||
import java.lang.reflect.Method; | ||
|
||
@Slf4j | ||
public class AsyncExceptionHandler implements AsyncUncaughtExceptionHandler { | ||
|
||
@Override | ||
public void handleUncaughtException(Throwable ex, Method method, Object... params) { | ||
log.error("AsyncException message={}, declaringClass={}, methodName={}", ex.getMessage(), method.getDeclaringClass(), method.getName(), ex); | ||
|
||
for (Object param : params) { | ||
log.error("Parameter value - {}, declaringClass={}, methodName={}", param, method.getDeclaringClass(), method.getName()); | ||
} | ||
} | ||
|
||
} |
24 changes: 24 additions & 0 deletions
24
src/main/java/com/dnd/namuiwiki/config/AsyncConfiguration.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,24 @@ | ||
package com.dnd.namuiwiki.config; | ||
|
||
import com.dnd.namuiwiki.common.exception.AsyncExceptionHandler; | ||
import org.springframework.aop.interceptor.AsyncUncaughtExceptionHandler; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.scheduling.annotation.AsyncConfigurer; | ||
import org.springframework.scheduling.annotation.EnableAsync; | ||
|
||
@EnableAsync | ||
@Configuration | ||
public class AsyncConfiguration implements AsyncConfigurer { | ||
|
||
@Override | ||
public AsyncUncaughtExceptionHandler getAsyncUncaughtExceptionHandler() { | ||
return asyncExceptionHandler(); | ||
} | ||
|
||
@Bean | ||
public AsyncExceptionHandler asyncExceptionHandler() { | ||
return new AsyncExceptionHandler(); | ||
} | ||
|
||
} |
28 changes: 28 additions & 0 deletions
28
src/main/java/com/dnd/namuiwiki/config/CacheConfiguration.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,28 @@ | ||
package com.dnd.namuiwiki.config; | ||
|
||
import org.springframework.cache.Cache; | ||
import org.springframework.cache.CacheManager; | ||
import org.springframework.cache.annotation.EnableCaching; | ||
import org.springframework.cache.concurrent.ConcurrentMapCache; | ||
import org.springframework.cache.support.SimpleCacheManager; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
@EnableCaching | ||
@Configuration | ||
public class CacheConfiguration { | ||
|
||
@Bean | ||
CacheManager cacheManager() { | ||
SimpleCacheManager cacheManager = new SimpleCacheManager(); | ||
List<Cache> caches = new ArrayList<>(); | ||
caches.add(new ConcurrentMapCache("questions")); | ||
caches.add(new ConcurrentMapCache("question")); | ||
cacheManager.setCaches(caches); | ||
return cacheManager; | ||
} | ||
|
||
} |
19 changes: 19 additions & 0 deletions
19
src/main/java/com/dnd/namuiwiki/config/EventConfiguration.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,19 @@ | ||
package com.dnd.namuiwiki.config; | ||
|
||
import com.dnd.namuiwiki.domain.statistic.StatisticsService; | ||
import com.dnd.namuiwiki.domain.survey.SurveyEventHandler; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
|
||
@Configuration | ||
@RequiredArgsConstructor | ||
public class EventConfiguration { | ||
private final StatisticsService statisticsService; | ||
|
||
@Bean | ||
public SurveyEventHandler surveyEventHandler() { | ||
return new SurveyEventHandler(statisticsService); | ||
} | ||
|
||
} |
14 changes: 14 additions & 0 deletions
14
src/main/java/com/dnd/namuiwiki/domain/question/QuestionRepository.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,7 +1,21 @@ | ||
package com.dnd.namuiwiki.domain.question; | ||
|
||
import com.dnd.namuiwiki.domain.question.entity.Question; | ||
import org.springframework.cache.annotation.Cacheable; | ||
import org.springframework.data.mongodb.repository.MongoRepository; | ||
import org.springframework.lang.NonNull; | ||
|
||
import java.util.List; | ||
import java.util.Optional; | ||
|
||
public interface QuestionRepository extends MongoRepository<Question, String> { | ||
|
||
@NonNull | ||
@Cacheable("questions") | ||
List<Question> findAll(); | ||
|
||
@NonNull | ||
@Cacheable("question") | ||
Optional<Question> findById(@NonNull String id); | ||
|
||
} |
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
25 changes: 25 additions & 0 deletions
25
src/main/java/com/dnd/namuiwiki/domain/survey/SurveyEventHandler.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,25 @@ | ||
package com.dnd.namuiwiki.domain.survey; | ||
|
||
import com.dnd.namuiwiki.domain.statistic.StatisticsService; | ||
import com.dnd.namuiwiki.domain.survey.model.dto.SurveyCreatedEvent; | ||
import com.dnd.namuiwiki.domain.survey.model.entity.Survey; | ||
import lombok.RequiredArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.context.event.EventListener; | ||
import org.springframework.scheduling.annotation.Async; | ||
|
||
@Slf4j | ||
@RequiredArgsConstructor | ||
public class SurveyEventHandler { | ||
private final StatisticsService statisticsService; | ||
|
||
@Async | ||
@EventListener | ||
public void handleSurveySuccessEvent(SurveyCreatedEvent event) { | ||
Survey survey = event.getSurvey(); | ||
log.info("SurveyEventHandler.handleSurveySuccessEvent: surveyId={}", survey.getId()); | ||
|
||
statisticsService.updateStatistics(survey); | ||
} | ||
|
||
} |
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
11 changes: 11 additions & 0 deletions
11
src/main/java/com/dnd/namuiwiki/domain/survey/model/dto/SurveyCreatedEvent.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 com.dnd.namuiwiki.domain.survey.model.dto; | ||
|
||
import com.dnd.namuiwiki.domain.survey.model.entity.Survey; | ||
import lombok.Getter; | ||
import lombok.RequiredArgsConstructor; | ||
|
||
@Getter | ||
@RequiredArgsConstructor | ||
public class SurveyCreatedEvent { | ||
private final Survey survey; | ||
} |
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