| 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.Commons; | |
| 7 | import edu.ucsb.cs156.happiercows.entities.Report; | |
| 8 | import edu.ucsb.cs156.happiercows.entities.ReportLine; | |
| 9 | import edu.ucsb.cs156.happiercows.entities.UserCommons; | |
| 10 | import edu.ucsb.cs156.happiercows.repositories.CommonsRepository; | |
| 11 | import edu.ucsb.cs156.happiercows.repositories.ReportLineRepository; | |
| 12 | import edu.ucsb.cs156.happiercows.repositories.ReportRepository; | |
| 13 | import edu.ucsb.cs156.happiercows.repositories.UserCommonsRepository; | |
| 14 | ||
| 15 | @Service("ReportService") | |
| 16 | public class ReportService { | |
| 17 | ||
| 18 |     @Autowired | |
| 19 |     ReportRepository reportRepository; | |
| 20 | ||
| 21 |     @Autowired | |
| 22 |     ReportLineRepository reportLineRepository; | |
| 23 | ||
| 24 |     @Autowired | |
| 25 |     CommonsRepository commonsRepository; | |
| 26 | ||
| 27 |     @Autowired | |
| 28 |     UserCommonsRepository userCommonsRepository; | |
| 29 | ||
| 30 |     public Report createReport(Long commonsId) { | |
| 31 |         Report report = createAndSaveReportHeader(commonsId); | |
| 32 |          | |
| 33 |         Iterable<UserCommons> allUserCommons = userCommonsRepository.findByCommonsId(commonsId); | |
| 34 | ||
| 35 | ||
| 36 |         for (UserCommons userCommons : allUserCommons) { | |
| 37 |                createAndSaveReportLine(report, userCommons); | |
| 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 commonsId) { | |
| 44 |         Commons commons = commonsRepository.findById(commonsId) | |
| 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("Commons with id %d not found", commonsId))); | 
| 46 | ||
| 47 |         Report report = Report.builder() | |
| 48 |                 .commonsId(commonsId) | |
| 49 | ||
| 50 |                 .name(commons.getName()) | |
| 51 |                 .cowPrice(commons.getCowPrice()) | |
| 52 |                 .milkPrice(commons.getMilkPrice()) | |
| 53 |                 .startingBalance(commons.getStartingBalance()) | |
| 54 |                 .startingDate(commons.getStartingDate()) | |
| 55 |                 .showLeaderboard(commons.isShowLeaderboard()) | |
| 56 |                 .showChat(commons.isShowChat()) | |
| 57 |                 .carryingCapacity(commons.getCarryingCapacity()) | |
| 58 |                 .degradationRate(commons.getDegradationRate()) | |
| 59 |                 .belowCapacityHealthUpdateStrategy(commons.getBelowCapacityHealthUpdateStrategy()) | |
| 60 |                 .aboveCapacityHealthUpdateStrategy(commons.getAboveCapacityHealthUpdateStrategy()) | |
| 61 |                 .numUsers(commonsRepository.getNumUsers(commonsId).orElse(0)) | |
| 62 |                 .numCows(commonsRepository.getNumCows(commonsId).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, UserCommons userCommons) { | |
| 71 |         ReportLine reportLine = ReportLine.builder() | |
| 72 |                 .reportId(report.getId()) | |
| 73 |                 .userId(userCommons.getUser().getId()) | |
| 74 |                 .username(userCommons.getUsername()) | |
| 75 |                 .totalWealth(userCommons.getTotalWealth()) | |
| 76 |                 .numOfCows(userCommons.getNumOfCows()) | |
| 77 |                 .avgCowHealth(userCommons.getCowHealth()) | |
| 78 |                 .cowsBought(userCommons.getCowsBought()) | |
| 79 |                 .cowsSold(userCommons.getCowsSold()) | |
| 80 |                 .cowDeaths(userCommons.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  |