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 commons_id) { | |
31 | Report report = createAndSaveReportHeader(commons_id); | |
32 | | |
33 | Iterable<UserCommons> allUserCommons = userCommonsRepository.findByCommonsId(commons_id); | |
34 | ||
35 | for (UserCommons userCommons : allUserCommons) { | |
36 | createAndSaveReportLine(report, userCommons); | |
37 | } | |
38 | ||
39 |
1
1. createReport : replaced return value with null for edu/ucsb/cs156/happiercows/services/ReportService::createReport → KILLED |
return report; |
40 | } | |
41 | ||
42 | public Report createAndSaveReportHeader(Long commons_id) { | |
43 | Commons commons = commonsRepository.findById(commons_id) | |
44 |
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", commons_id))); |
45 | ||
46 | Report report = Report.builder() | |
47 | .commons_id(commons_id) | |
48 | .name(commons.getName()) | |
49 | .cowPrice(commons.getCowPrice()) | |
50 | .milkPrice(commons.getMilkPrice()) | |
51 | .startingBalance(commons.getStartingBalance()) | |
52 | .startingDate(commons.getStartingDate()) | |
53 | .showLeaderboard(commons.isShowLeaderboard()) | |
54 | .carryingCapacity(commons.getCarryingCapacity()) | |
55 | .degradationRate(commons.getDegradationRate()) | |
56 | .belowCapacityHealthUpdateStrategy(commons.getBelowCapacityHealthUpdateStrategy()) | |
57 | .aboveCapacityHealthUpdateStrategy(commons.getAboveCapacityHealthUpdateStrategy()) | |
58 | .numUsers(commonsRepository.getNumUsers(commons_id).orElse(0)) | |
59 | .numCows(commonsRepository.getNumCows(commons_id).orElse(0)) | |
60 | .build(); | |
61 | ||
62 | reportRepository.save(report); | |
63 |
1
1. createAndSaveReportHeader : replaced return value with null for edu/ucsb/cs156/happiercows/services/ReportService::createAndSaveReportHeader → KILLED |
return report; |
64 | } | |
65 | ||
66 | public ReportLine createAndSaveReportLine(Report report, UserCommons userCommons) { | |
67 | ReportLine reportLine = ReportLine.builder() | |
68 | .report_id(report.getId()) | |
69 | .user_id(userCommons.getUser().getId()) | |
70 | .username(userCommons.getUsername()) | |
71 | .totalWealth(userCommons.getTotalWealth()) | |
72 | .numOfCows(userCommons.getNumOfCows()) | |
73 | .avgCowHealth(userCommons.getCowHealth()) | |
74 | .cowsBought(userCommons.getCowsBought()) | |
75 | .cowsSold(userCommons.getCowsSold()) | |
76 | .cowDeaths(userCommons.getCowDeaths()) | |
77 | .build(); | |
78 | ||
79 | reportLineRepository.save(reportLine); | |
80 |
1
1. createAndSaveReportLine : replaced return value with null for edu/ucsb/cs156/happiercows/services/ReportService::createAndSaveReportLine → KILLED |
return reportLine; |
81 | } | |
82 | ||
83 | } | |
Mutations | ||
39 |
1.1 |
|
44 |
1.1 |
|
63 |
1.1 |
|
80 |
1.1 |