| 1 | package edu.ucsb.cs156.happiercows.services; | |
| 2 | ||
| 3 | import org.springframework.beans.factory.annotation.Autowired; | |
| 4 | import org.springframework.stereotype.Service; | |
| 5 | ||
| 6 | import edu.ucsb.cs156.happiercows.entities.Game; | |
| 7 | import edu.ucsb.cs156.happiercows.entities.Report; | |
| 8 | import edu.ucsb.cs156.happiercows.entities.ReportLine; | |
| 9 | import edu.ucsb.cs156.happiercows.entities.Farmer; | |
| 10 | import edu.ucsb.cs156.happiercows.repositories.GameRepository; | |
| 11 | import edu.ucsb.cs156.happiercows.repositories.ReportLineRepository; | |
| 12 | import edu.ucsb.cs156.happiercows.repositories.ReportRepository; | |
| 13 | import edu.ucsb.cs156.happiercows.repositories.FarmerRepository; | |
| 14 | ||
| 15 | @Service("ReportService") | |
| 16 | public class ReportService { | |
| 17 | ||
| 18 | @Autowired | |
| 19 | ReportRepository reportRepository; | |
| 20 | ||
| 21 | @Autowired | |
| 22 | ReportLineRepository reportLineRepository; | |
| 23 | ||
| 24 | @Autowired | |
| 25 | GameRepository gameRepository; | |
| 26 | ||
| 27 | @Autowired | |
| 28 | FarmerRepository farmerRepository; | |
| 29 | ||
| 30 | public Report createReport(Long gameId) { | |
| 31 | Report report = createAndSaveReportHeader(gameId); | |
| 32 | | |
| 33 | Iterable<Farmer> allFarmer = farmerRepository.findByGameId(gameId); | |
| 34 | ||
| 35 | ||
| 36 | for (Farmer farmer : allFarmer) { | |
| 37 | createAndSaveReportLine(report, farmer); | |
| 38 | } | |
| 39 | ||
| 40 |
1
1. createReport : replaced return value with null for edu/ucsb/cs156/happiercows/services/ReportService::createReport → KILLED |
return report; |
| 41 | } | |
| 42 | ||
| 43 | public Report createAndSaveReportHeader(Long gameId) { | |
| 44 | Game game = gameRepository.findById(gameId) | |
| 45 |
1
1. lambda$createAndSaveReportHeader$0 : replaced return value with null for edu/ucsb/cs156/happiercows/services/ReportService::lambda$createAndSaveReportHeader$0 → KILLED |
.orElseThrow(() -> new RuntimeException(String.format("Game with id %d not found", gameId))); |
| 46 | ||
| 47 | Report report = Report.builder() | |
| 48 | .gameId(gameId) | |
| 49 | ||
| 50 | .name(game.getName()) | |
| 51 | .cowPrice(game.getCowPrice()) | |
| 52 | .milkPrice(game.getMilkPrice()) | |
| 53 | .startingBalance(game.getStartingBalance()) | |
| 54 | .startingDate(game.getStartingDate()) | |
| 55 | .showLeaderboard(game.isShowLeaderboard()) | |
| 56 | .capacityPerUser(game.getCapacityPerUser()) | |
| 57 | .carryingCapacity(game.getCarryingCapacity()) | |
| 58 | .degradationRate(game.getDegradationRate()) | |
| 59 | .belowCapacityHealthUpdateStrategy(game.getBelowCapacityHealthUpdateStrategy()) | |
| 60 | .aboveCapacityHealthUpdateStrategy(game.getAboveCapacityHealthUpdateStrategy()) | |
| 61 | .numUsers(gameRepository.getNumUsers(gameId).orElse(0)) | |
| 62 | .numCows(gameRepository.getNumCows(gameId).orElse(0)) | |
| 63 | ||
| 64 | .build(); | |
| 65 | ||
| 66 | reportRepository.save(report); | |
| 67 |
1
1. createAndSaveReportHeader : replaced return value with null for edu/ucsb/cs156/happiercows/services/ReportService::createAndSaveReportHeader → KILLED |
return report; |
| 68 | } | |
| 69 | ||
| 70 | public ReportLine createAndSaveReportLine(Report report, Farmer farmer) { | |
| 71 | ReportLine reportLine = ReportLine.builder() | |
| 72 | .reportId(report.getId()) | |
| 73 | .userId(farmer.getUser().getId()) | |
| 74 | .username(farmer.getUsername()) | |
| 75 | .totalWealth(farmer.getTotalWealth()) | |
| 76 | .numOfCows(farmer.getNumOfCows()) | |
| 77 | .avgCowHealth(farmer.getCowHealth()) | |
| 78 | .cowsBought(farmer.getCowsBought()) | |
| 79 | .cowsSold(farmer.getCowsSold()) | |
| 80 | .cowDeaths(farmer.getCowDeaths()) | |
| 81 | .build(); | |
| 82 | ||
| 83 | reportLineRepository.save(reportLine); | |
| 84 |
1
1. createAndSaveReportLine : replaced return value with null for edu/ucsb/cs156/happiercows/services/ReportService::createAndSaveReportLine → KILLED |
return reportLine; |
| 85 | } | |
| 86 | ||
| 87 | } | |
Mutations | ||
| 40 |
1.1 |
|
| 45 |
1.1 |
|
| 67 |
1.1 |
|
| 84 |
1.1 |