-
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.
Merge pull request #75 from SWM-KAWAI-MANS/develop
프로덕션 환경에 반영
- Loading branch information
Showing
13 changed files
with
301 additions
and
4 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,7 +23,6 @@ jobs: | |
with: | ||
java-version: '17' | ||
distribution: 'temurin' | ||
|
||
- name: Login to Docker Hub | ||
uses: docker/[email protected] | ||
with: | ||
|
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
38 changes: 38 additions & 0 deletions
38
...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,38 @@ | ||
package online.partyrun.partyrunbattleservice.domain.mypage.controller; | ||
|
||
import lombok.AccessLevel; | ||
import lombok.RequiredArgsConstructor; | ||
import lombok.experimental.FieldDefaults; | ||
import online.partyrun.partyrunbattleservice.domain.mypage.dto.MyPageHistoryResponse; | ||
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()); | ||
} | ||
|
||
@GetMapping("battles") | ||
public MyPageHistoryResponse getMyPageBattleResponse(Authentication auth) { | ||
return myPageService.getMyPageBattle(auth.getName()); | ||
} | ||
|
||
@GetMapping("singles") | ||
public MyPageHistoryResponse getMyPageSingleResponse(Authentication auth) { | ||
return myPageService.getMyPageSingle(auth.getName()); | ||
} | ||
} |
34 changes: 34 additions & 0 deletions
34
...n/java/online/partyrun/partyrunbattleservice/domain/mypage/dto/MyPageHistoryResponse.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 online.partyrun.partyrunbattleservice.domain.mypage.dto; | ||
|
||
import online.partyrun.partyrunbattleservice.domain.battle.entity.Battle; | ||
import online.partyrun.partyrunbattleservice.domain.single.entity.Single; | ||
|
||
import java.util.Collections; | ||
import java.util.List; | ||
|
||
public record MyPageHistoryResponse(List<MyPageRunningResponse> history) { | ||
private static final MyPageHistoryResponse EMPTY_HISTORY = new MyPageHistoryResponse(Collections.emptyList()); | ||
|
||
public static MyPageHistoryResponse ofBattles(List<Battle> battles, String memberId) { | ||
if (battles.isEmpty()) { | ||
return EMPTY_HISTORY; | ||
} | ||
|
||
return new MyPageHistoryResponse( | ||
battles.stream() | ||
.map(battle -> MyPageRunningResponse.of(battle, memberId)) | ||
.toList() | ||
); | ||
} | ||
|
||
public static MyPageHistoryResponse ofSingle(List<Single> singles) { | ||
if (singles.isEmpty()) { | ||
return EMPTY_HISTORY; | ||
} | ||
return new MyPageHistoryResponse( | ||
singles.stream() | ||
.map(MyPageRunningResponse::from) | ||
.toList() | ||
); | ||
} | ||
} |
45 changes: 45 additions & 0 deletions
45
...n/java/online/partyrun/partyrunbattleservice/domain/mypage/dto/MyPageRunningResponse.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.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.RunningTime; | ||
import online.partyrun.partyrunbattleservice.domain.single.entity.Single; | ||
|
||
import java.time.Duration; | ||
import java.time.LocalDateTime; | ||
import java.util.List; | ||
|
||
public record MyPageRunningResponse(String id, | ||
LocalDateTime startTime, | ||
RunningTimeResponse runningTime, | ||
double distance) { | ||
|
||
public static MyPageRunningResponse of(Battle battle, String memberId) { | ||
final RunnerRecord runnerRecentRecord = battle.getRunnerRecentRecord(memberId); | ||
|
||
final LocalDateTime startTime = battle.getStartTime(); | ||
final LocalDateTime endTime = runnerRecentRecord.getTime(); | ||
final Duration duration = Duration.between(startTime, endTime); | ||
|
||
return new MyPageRunningResponse( | ||
battle.getId(), | ||
startTime, | ||
new RunningTimeResponse(duration.toHoursPart(), duration.toMinutesPart(), duration.toSecondsPart()), | ||
runnerRecentRecord.getDistance() | ||
); | ||
} | ||
|
||
public static MyPageRunningResponse from(Single single) { | ||
final RunningTime runningTime = single.getRunningTime(); | ||
|
||
final List<RunnerRecord> runnerRecords = single.getRunnerRecords(); | ||
|
||
return new MyPageRunningResponse( | ||
single.getId(), | ||
runnerRecords.get(0).getTime(), | ||
new RunningTimeResponse(runningTime.getHours(), runningTime.getMinutes(), runningTime.getSeconds()), | ||
runnerRecords.get(runnerRecords.size() - 1).getDistance() | ||
); | ||
} | ||
} |
64 changes: 64 additions & 0 deletions
64
...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,64 @@ | ||
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.runner.exception.InvalidRecentRunnerRecordException; | ||
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) { | ||
if (battles.isEmpty() && singles.isEmpty()) { | ||
return new MyPageTotalResponse(0, 0, new RunningTimeResponse(0, 0, 0)); | ||
} | ||
|
||
final double totalBattleDistance = battles.stream() | ||
.mapToDouble( | ||
battle -> { | ||
try { | ||
return battle.getRunnerRecentDistance(memberId); | ||
} catch (InvalidRecentRunnerRecordException exception) { | ||
return 0; | ||
} | ||
} | ||
) | ||
.sum(); | ||
|
||
final long totalBattleRunningTime = battles.stream() | ||
.mapToLong( | ||
battle -> { | ||
try { | ||
return Duration.between(battle.getCreatedAt(), battle.getRunnerRecentRecord(memberId).getTime()).toSeconds(); | ||
} catch (InvalidRecentRunnerRecordException exception) { | ||
return 0; | ||
} | ||
} | ||
) | ||
.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)); | ||
} | ||
} |
42 changes: 42 additions & 0 deletions
42
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,42 @@ | ||
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.MyPageHistoryResponse; | ||
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); | ||
} | ||
|
||
public MyPageHistoryResponse getMyPageBattle(String memberId) { | ||
final List<Battle> battles = battleRepository.findAllByRunnersIdExceptRunnerRecords(memberId); | ||
|
||
return MyPageHistoryResponse.ofBattles(battles, memberId); | ||
} | ||
|
||
public MyPageHistoryResponse getMyPageSingle(String memberId) { | ||
final List<Single> singles = singleRepository.findAllByRunnerId(memberId); | ||
|
||
return MyPageHistoryResponse.ofSingle(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
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
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); | ||
} | ||
} | ||
} |