-
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 #201 from dnd-side-project/dev
Dev
- Loading branch information
Showing
40 changed files
with
351 additions
and
536 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
19 changes: 19 additions & 0 deletions
19
src/main/java/com/dnd/namuiwiki/common/util/ListUtils.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.common.util; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Arrays; | ||
import java.util.Collection; | ||
import java.util.List; | ||
|
||
public class ListUtils { | ||
public static <T> List<T> convertList(Object obj) { | ||
if (obj.getClass().isArray()) { | ||
return Arrays.asList((T[]) obj); | ||
} else if (obj instanceof Collection) { | ||
return new ArrayList<>((Collection<T>) obj); | ||
} else { | ||
throw new ClassCastException("Object is not a List."); | ||
} | ||
|
||
} | ||
} |
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
9 changes: 9 additions & 0 deletions
9
src/main/java/com/dnd/namuiwiki/config/RetryConfiguration.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 com.dnd.namuiwiki.config; | ||
|
||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.retry.annotation.EnableRetry; | ||
|
||
@Configuration | ||
@EnableRetry(proxyTargetClass=true) | ||
public class RetryConfiguration { | ||
} |
13 changes: 0 additions & 13 deletions
13
src/main/java/com/dnd/namuiwiki/domain/dashboard/DashboardCustomRepository.java
This file was deleted.
Oops, something went wrong.
45 changes: 0 additions & 45 deletions
45
src/main/java/com/dnd/namuiwiki/domain/dashboard/DashboardCustomRepositoryImpl.java
This file was deleted.
Oops, something went wrong.
70 changes: 70 additions & 0 deletions
70
src/main/java/com/dnd/namuiwiki/domain/dashboard/DashboardInternalProxyService.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,70 @@ | ||
package com.dnd.namuiwiki.domain.dashboard; | ||
|
||
|
||
import com.dnd.namuiwiki.domain.dashboard.model.entity.Dashboard; | ||
import com.dnd.namuiwiki.domain.statistic.model.Statistics; | ||
import com.dnd.namuiwiki.domain.survey.model.entity.Answer; | ||
import com.dnd.namuiwiki.domain.survey.type.Period; | ||
import com.dnd.namuiwiki.domain.survey.type.Relation; | ||
import com.dnd.namuiwiki.domain.user.entity.User; | ||
import com.dnd.namuiwiki.domain.wiki.WikiType; | ||
import com.dnd.namuiwiki.external.DiscordClient; | ||
import lombok.RequiredArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.dao.OptimisticLockingFailureException; | ||
import org.springframework.retry.annotation.Backoff; | ||
import org.springframework.retry.annotation.Recover; | ||
import org.springframework.retry.annotation.Retryable; | ||
import org.springframework.stereotype.Service; | ||
|
||
import java.util.List; | ||
|
||
@Slf4j | ||
@RequiredArgsConstructor | ||
@Service | ||
public class DashboardInternalProxyService { | ||
private final DashboardRepository dashboardRepository; | ||
private final DiscordClient discordClient; | ||
|
||
@Retryable( | ||
retryFor = {OptimisticLockingFailureException.class}, | ||
maxAttempts = 3, | ||
backoff = @Backoff(delay = 30 * 1000L) | ||
) | ||
public void updateDashboard(User owner, WikiType wikiType, Period period, Relation relation, List<Answer> answers) { | ||
insertDashboardIfNotExist(owner, wikiType, period, relation, answers); | ||
Dashboard dashboard = dashboardRepository.findByUserAndWikiTypeAndPeriodAndRelation(owner, wikiType, period, relation) | ||
.orElseGet(() -> { | ||
Dashboard d = Dashboard.builder() | ||
.user(owner) | ||
.wikiType(wikiType) | ||
.period(period) | ||
.relation(relation) | ||
.statistics(Statistics.from(answers.stream().map(Answer::getQuestion).toList())) | ||
.build(); | ||
return dashboardRepository.save(d); | ||
}); | ||
|
||
dashboard.updateStatistics(answers); | ||
dashboardRepository.save(dashboard); | ||
} | ||
|
||
@Recover | ||
private void recoverForUpdateDashboard(Exception e) { | ||
log.error("Failed to update dashboard", e); | ||
discordClient.sendMessage(e.toString()); | ||
} | ||
|
||
private void insertDashboardIfNotExist(User owner, WikiType wikiType, Period period, Relation relation, List<Answer> answers) { | ||
if (!dashboardRepository.existsByUserAndWikiTypeAndPeriodAndRelation(owner, wikiType, period, relation)) { | ||
dashboardRepository.save(Dashboard.builder() | ||
.user(owner) | ||
.wikiType(wikiType) | ||
.period(period) | ||
.relation(relation) | ||
.statistics(Statistics.from(answers.stream().map(Answer::getQuestion).toList())) | ||
.build()); | ||
} | ||
} | ||
|
||
} |
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
57 changes: 0 additions & 57 deletions
57
src/main/java/com/dnd/namuiwiki/domain/dashboard/model/BestWorthDashboardComponent.java
This file was deleted.
Oops, something went wrong.
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.