Skip to content

Commit

Permalink
[#6] feat: Create BattingHistoryDTO
Browse files Browse the repository at this point in the history
  • Loading branch information
isaac56 committed May 7, 2021
1 parent 65cd76b commit ab93dfd
Showing 1 changed file with 37 additions and 0 deletions.
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();
}
}

0 comments on commit ab93dfd

Please sign in to comment.