-
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 #35 from SSUMatch/feat/1-match
[feat]:Main 구장 상세 api 구현
- Loading branch information
Showing
9 changed files
with
164 additions
and
3 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
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
7 changes: 7 additions & 0 deletions
7
Main/src/main/java/com/Main/domain/match/domain/service/MatchesManager.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,5 +1,12 @@ | ||
package com.Main.domain.match.domain.service; | ||
|
||
import com.Main.domain.record.domain.entity.Record; | ||
import com.Main.domain.user.domain.entity.User; | ||
import com.Main.domain.userMatch.domain.entity.UserMatch; | ||
|
||
import java.util.List; | ||
|
||
public interface MatchesManager { | ||
String isFull(Long matchesId); | ||
String getExpectRate(List<Record> user); | ||
} |
15 changes: 15 additions & 0 deletions
15
Main/src/main/java/com/Main/domain/record/domain/entity/Level.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,15 @@ | ||
package com.Main.domain.record.domain.entity; | ||
|
||
import lombok.Getter; | ||
import lombok.RequiredArgsConstructor; | ||
|
||
@RequiredArgsConstructor | ||
@Getter | ||
public enum Level { | ||
ROOKIE("루키"), | ||
BEGINNER("비기너"), | ||
AMATUAR("아마추어"), | ||
SEMIPRO("세미프로"), | ||
PRO("프로"); | ||
private final String levelString; | ||
} |
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
8 changes: 8 additions & 0 deletions
8
Main/src/main/java/com/Main/domain/record/domain/repository/RecordRepository.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,8 @@ | ||
package com.Main.domain.record.domain.repository; | ||
|
||
import com.Main.domain.record.domain.entity.Record; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
|
||
public interface RecordRepository extends JpaRepository<Record, Long> { | ||
Record findByUserId(Long userId); | ||
} |
65 changes: 65 additions & 0 deletions
65
Main/src/main/java/com/Main/domain/record/domain/service/RecordManager.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,65 @@ | ||
package com.Main.domain.record.domain.service; | ||
|
||
import com.Main.domain.match.application.dto.LevelDto; | ||
import com.Main.domain.record.domain.entity.Level; | ||
import com.Main.domain.record.domain.entity.Record; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Service; | ||
|
||
import java.util.ArrayList; | ||
import java.util.HashMap; | ||
import java.util.List; | ||
import java.util.Map; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
public class RecordManager { | ||
public List<LevelDto> getLevelDtos(List<Record> records) { | ||
if (records.isEmpty()) { | ||
return List.of(); | ||
} | ||
|
||
Map<Level, Integer> levelCount = new HashMap<>(); | ||
int totalRecords = records.size(); | ||
|
||
for (Record record : records) { | ||
Level level = record.getLevel(); | ||
levelCount.put(level, levelCount.getOrDefault(level, 0) + 1); | ||
} | ||
|
||
List<LevelDto> levelDtos = new ArrayList<>(); | ||
for (Map.Entry<Level, Integer> entry : levelCount.entrySet()) { | ||
Level level = entry.getKey(); | ||
int count = entry.getValue(); | ||
double percent = (double) count / totalRecords * 100; | ||
String percentString = String.format("%.2f%%", percent); | ||
levelDtos.add(LevelDto.of(level.getLevelString(), percentString)); | ||
} | ||
|
||
return levelDtos; | ||
} | ||
public String getExpectRate(List<Record> records) { | ||
if (records.isEmpty()) { | ||
return "No records found."; | ||
} | ||
|
||
Map<Level, Integer> levelCount = new HashMap<>(); | ||
|
||
for (Record record : records) { | ||
Level level = record.getLevel(); | ||
levelCount.put(level, levelCount.getOrDefault(level, 0) + 1); | ||
} | ||
|
||
Level mostCommonLevel = null; | ||
int maxCount = 0; | ||
|
||
for (Map.Entry<Level, Integer> entry : levelCount.entrySet()) { | ||
if (entry.getValue() > maxCount) { | ||
mostCommonLevel = entry.getKey(); | ||
maxCount = entry.getValue(); | ||
} | ||
} | ||
|
||
return mostCommonLevel != null ? mostCommonLevel.getLevelString() : "No common level found."; | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
Main/src/main/java/com/Main/domain/record/domain/service/RecordReader.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,15 @@ | ||
package com.Main.domain.record.domain.service; | ||
|
||
import com.Main.domain.record.domain.entity.Record; | ||
import com.Main.domain.record.domain.repository.RecordRepository; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Service; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
public class RecordReader { | ||
private final RecordRepository recordRepository; | ||
public Record getRecordByUserId(Long userId){ | ||
return recordRepository.findByUserId(userId); | ||
} | ||
} |