-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: mypage total 조회 * refactor: jacoco 기준 변경 * feat : embedded redis를 test-container 대체 (#68) --------- Co-authored-by: Hyeonjun Park <[email protected]>
- Loading branch information
1 parent
416b167
commit 8e0df12
Showing
14 changed files
with
190 additions
and
23 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,6 +23,10 @@ jobs: | |
with: | ||
java-version: '17' | ||
distribution: 'temurin' | ||
- name: Setup Testcontainers Cloud Client | ||
uses: atomicjar/testcontainers-cloud-setup-action@v1 | ||
with: | ||
token: ${{ secrets.TC_CLOUD_TOKEN }} | ||
|
||
- name: Login to Docker Hub | ||
uses: docker/[email protected] | ||
|
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 |
---|---|---|
|
@@ -23,6 +23,10 @@ jobs: | |
with: | ||
java-version: '17' | ||
distribution: 'temurin' | ||
- name: Setup Testcontainers Cloud Client | ||
uses: atomicjar/testcontainers-cloud-setup-action@v1 | ||
with: | ||
token: ${{ secrets.TC_CLOUD_TOKEN }} | ||
|
||
- name: Login to Docker Hub | ||
uses: docker/[email protected] | ||
|
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
27 changes: 27 additions & 0 deletions
27
...java/online/partyrun/partyrunbattleservice/domain/mypage/controller/MyPageController.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,27 @@ | ||
package online.partyrun.partyrunbattleservice.domain.mypage.controller; | ||
|
||
import lombok.AccessLevel; | ||
import lombok.RequiredArgsConstructor; | ||
import lombok.experimental.FieldDefaults; | ||
import online.partyrun.partyrunbattleservice.domain.mypage.dto.MyPageTotalResponse; | ||
import online.partyrun.partyrunbattleservice.domain.mypage.service.MyPageService; | ||
import online.partyrun.partyrunbattleservice.global.logging.Logging; | ||
import org.springframework.security.core.Authentication; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
@Logging | ||
@RestController | ||
@RequiredArgsConstructor | ||
@FieldDefaults(level = AccessLevel.PRIVATE, makeFinal = true) | ||
@RequestMapping("mypage") | ||
public class MyPageController { | ||
|
||
MyPageService myPageService; | ||
|
||
@GetMapping("/total") | ||
public MyPageTotalResponse getMyPageTotalResponse(Authentication auth) { | ||
return myPageService.getMyPageTotal(auth.getName()); | ||
} | ||
} |
43 changes: 43 additions & 0 deletions
43
...ain/java/online/partyrun/partyrunbattleservice/domain/mypage/dto/MyPageTotalResponse.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 online.partyrun.partyrunbattleservice.domain.mypage.dto; | ||
|
||
import online.partyrun.partyrunbattleservice.domain.battle.entity.Battle; | ||
import online.partyrun.partyrunbattleservice.domain.runner.entity.record.RunnerRecord; | ||
import online.partyrun.partyrunbattleservice.domain.single.dto.RunningTimeResponse; | ||
import online.partyrun.partyrunbattleservice.domain.single.entity.Single; | ||
|
||
import java.time.Duration; | ||
import java.util.List; | ||
|
||
public record MyPageTotalResponse(double totalDistance, double averagePace, RunningTimeResponse totalRunningTime) { | ||
|
||
public static MyPageTotalResponse of(String memberId, List<Battle> battles, List<Single> singles) { | ||
final double totalBattleDistance = battles.stream() | ||
.mapToDouble(battle -> battle.getRunnerRecentDistance(memberId)) | ||
.sum(); | ||
|
||
final long totalBattleRunningTime = battles.stream() | ||
.mapToLong(battle -> Duration.between(battle.getCreatedAt(), battle.getRunnerRecentRecord(memberId).getTime()).toSeconds()) | ||
.sum(); | ||
|
||
final double totalSingleDistance = singles.stream() | ||
.mapToDouble(single -> { | ||
final List<RunnerRecord> runnerRecords = single.getRunnerRecords(); | ||
return runnerRecords.get(runnerRecords.size() - 1).getDistance(); | ||
}) | ||
.sum(); | ||
|
||
final int totalSingleRunningTime = singles.stream() | ||
.mapToInt(single -> single.getRunningTime().getTotalSeconds()) | ||
.sum(); | ||
|
||
|
||
final double totalDistance = totalBattleDistance + totalSingleDistance; | ||
final long totalRunningTime = totalBattleRunningTime + totalSingleRunningTime; | ||
|
||
int totalHour = (int) totalRunningTime / 3600; | ||
int totalMinute = (int) (totalRunningTime % 3600) / 60; | ||
int totalSecond = (int) totalRunningTime % 60; | ||
|
||
return new MyPageTotalResponse(totalDistance, totalDistance / totalRunningTime, new RunningTimeResponse(totalHour, totalMinute, totalSecond)); | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
src/main/java/online/partyrun/partyrunbattleservice/domain/mypage/service/MyPageService.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,29 @@ | ||
package online.partyrun.partyrunbattleservice.domain.mypage.service; | ||
|
||
import lombok.AccessLevel; | ||
import lombok.RequiredArgsConstructor; | ||
import lombok.experimental.FieldDefaults; | ||
import online.partyrun.partyrunbattleservice.domain.battle.entity.Battle; | ||
import online.partyrun.partyrunbattleservice.domain.battle.repository.BattleRepository; | ||
import online.partyrun.partyrunbattleservice.domain.mypage.dto.MyPageTotalResponse; | ||
import online.partyrun.partyrunbattleservice.domain.single.entity.Single; | ||
import online.partyrun.partyrunbattleservice.domain.single.repository.SingleRepository; | ||
import org.springframework.stereotype.Service; | ||
|
||
import java.util.List; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
@FieldDefaults(level = AccessLevel.PRIVATE, makeFinal = true) | ||
public class MyPageService { | ||
|
||
BattleRepository battleRepository; | ||
SingleRepository singleRepository; | ||
|
||
public MyPageTotalResponse getMyPageTotal(String memberId) { | ||
final List<Battle> battles = battleRepository.findAllByRunnersIdExceptRunnerRecords(memberId); | ||
final List<Single> singles = singleRepository.findAllByRunnerId(memberId); | ||
|
||
return MyPageTotalResponse.of(memberId, battles, singles); | ||
} | ||
} |
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
19 changes: 0 additions & 19 deletions
19
src/main/java/online/partyrun/partyrunbattleservice/global/config/RedissonConfig.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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,7 +14,7 @@ spring: | |
|
||
data: | ||
redis: | ||
url: redis://localhost:16379 | ||
url: redis://localhost:6379/0 | ||
|
||
cloud: | ||
aws: | ||
|
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
45 changes: 45 additions & 0 deletions
45
.../online/partyrun/partyrunbattleservice/domain/single/repository/SingleRepositoryTest.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,45 @@ | ||
package online.partyrun.partyrunbattleservice.domain.single.repository; | ||
|
||
import online.partyrun.partyrunbattleservice.domain.runner.entity.record.GpsData; | ||
import online.partyrun.partyrunbattleservice.domain.runner.entity.record.RunnerRecord; | ||
import online.partyrun.partyrunbattleservice.domain.single.entity.RunningTime; | ||
import online.partyrun.partyrunbattleservice.domain.single.entity.Single; | ||
import org.junit.jupiter.api.*; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.boot.test.autoconfigure.data.mongo.DataMongoTest; | ||
|
||
import java.time.LocalDateTime; | ||
import java.util.List; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
@DataMongoTest | ||
@DisplayName("SingleRepository") | ||
class SingleRepositoryTest { | ||
|
||
@Autowired | ||
SingleRepository singleRepository; | ||
|
||
String runnerId = "박성우"; | ||
LocalDateTime now = LocalDateTime.now(); | ||
|
||
@Nested | ||
@DisplayNameGeneration(DisplayNameGenerator.ReplaceUnderscores.class) | ||
class findAllByRunnerId는 { | ||
|
||
@Test | ||
@DisplayName("모든 싱글 데이터를 조회한다.") | ||
void returnSingles() { | ||
final List<Single> singleData = List.of( | ||
new Single(runnerId, new RunningTime(0, 0, 1), List.of(new RunnerRecord(GpsData.of(1, 1, 1, now), 0))), | ||
new Single(runnerId, new RunningTime(0, 0, 1), List.of(new RunnerRecord(GpsData.of(1, 1, 1, now), 0))) | ||
); | ||
|
||
singleRepository.saveAll(singleData); | ||
|
||
final List<Single> singleResult = singleRepository.findAllByRunnerId(runnerId); | ||
|
||
assertThat(singleResult).hasSize(2); | ||
} | ||
} | ||
} |