1 | package edu.ucsb.cs156.happiercows.controllers; | |
2 | ||
3 | import edu.ucsb.cs156.happiercows.entities.Profit; | |
4 | import edu.ucsb.cs156.happiercows.entities.UserCommons; | |
5 | import edu.ucsb.cs156.happiercows.errors.EntityNotFoundException; | |
6 | import edu.ucsb.cs156.happiercows.repositories.CommonsRepository; | |
7 | import edu.ucsb.cs156.happiercows.repositories.ProfitRepository; | |
8 | import edu.ucsb.cs156.happiercows.repositories.UserCommonsRepository; | |
9 | import io.swagger.v3.oas.annotations.tags.Tag; | |
10 | import io.swagger.v3.oas.annotations.Operation; | |
11 | import io.swagger.v3.oas.annotations.Parameter; | |
12 | import lombok.extern.slf4j.Slf4j; | |
13 | import org.springframework.beans.factory.annotation.Autowired; | |
14 | import org.springframework.security.access.prepost.PreAuthorize; | |
15 | import org.springframework.web.bind.annotation.GetMapping; | |
16 | import org.springframework.web.bind.annotation.RequestMapping; | |
17 | import org.springframework.web.bind.annotation.RequestParam; | |
18 | import org.springframework.web.bind.annotation.RestController; | |
19 | ||
20 | @Tag(name = "Profits") | |
21 | @RequestMapping("/api/profits") | |
22 | @RestController | |
23 | @Slf4j | |
24 | ||
25 | public class ProfitsController extends ApiController { | |
26 | ||
27 | @Autowired | |
28 | CommonsRepository commonsRepository; | |
29 | ||
30 | @Autowired | |
31 | UserCommonsRepository userCommonsRepository; | |
32 | ||
33 | @Autowired | |
34 | ProfitRepository profitRepository; | |
35 | ||
36 | @Operation(summary = "Get all profits belonging to a user commons as a user via CommonsID") | |
37 | @PreAuthorize("hasRole('ROLE_USER')") | |
38 | @GetMapping("/all/commonsid") | |
39 | public Iterable<Profit> allProfitsByCommonsId( | |
40 | @Parameter(name="commonsId") @RequestParam Long commonsId | |
41 | ) { | |
42 | Long userId = getCurrentUser().getUser().getId(); | |
43 | ||
44 | UserCommons userCommons = userCommonsRepository.findByCommonsIdAndUserId(commonsId, userId) | |
45 |
1
1. lambda$allProfitsByCommonsId$0 : replaced return value with null for edu/ucsb/cs156/happiercows/controllers/ProfitsController::lambda$allProfitsByCommonsId$0 → KILLED |
.orElseThrow(() -> new EntityNotFoundException(UserCommons.class, "commonsId", commonsId, "userId", userId)); |
46 | ||
47 | Iterable<Profit> profits = profitRepository.findAllByUserCommons(userCommons); | |
48 | ||
49 |
1
1. allProfitsByCommonsId : replaced return value with null for edu/ucsb/cs156/happiercows/controllers/ProfitsController::allProfitsByCommonsId → KILLED |
return profits; |
50 | } | |
51 | } | |
Mutations | ||
45 |
1.1 |
|
49 |
1.1 |