-
Notifications
You must be signed in to change notification settings - Fork 47
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
37 additions
and
0 deletions.
There are no files selected for viewing
37 changes: 37 additions & 0 deletions
37
BE/baseball/src/main/java/team9/baseball/DTO/response/BattingHistoryDTO.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,37 @@ | ||
package team9.baseball.DTO.response; | ||
|
||
import lombok.AccessLevel; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Builder; | ||
import lombok.Getter; | ||
import team9.baseball.domain.aggregate.game.BattingHistory; | ||
import team9.baseball.domain.aggregate.team.Team; | ||
|
||
@Getter | ||
@Builder(access = AccessLevel.PRIVATE) | ||
@AllArgsConstructor(access = AccessLevel.PRIVATE) | ||
public class BattingHistoryDTO { | ||
private int uniform_number; | ||
private String name; | ||
private int appear_count; | ||
private int hit_count; | ||
private double hit_ratio; | ||
private boolean playing; | ||
|
||
|
||
public static BattingHistoryDTO of(Team team, BattingHistory battingHistory, int playingUniformNumber) { | ||
double hitRatio = 0; | ||
if (battingHistory.getAppear() != 0) { | ||
hitRatio = (double) battingHistory.getHits() / (double) battingHistory.getAppear(); | ||
} | ||
|
||
return builder() | ||
.uniform_number(battingHistory.getBatterUniformNumber()) | ||
.name(team.getPlayerName(battingHistory.getBatterUniformNumber())) | ||
.appear_count(battingHistory.getAppear()) | ||
.hit_count(battingHistory.getHits()) | ||
.hit_ratio(hitRatio) | ||
.playing(battingHistory.getBatterUniformNumber() == playingUniformNumber) | ||
.build(); | ||
} | ||
} |