1 | package edu.ucsb.cs156.happiercows.controllers; | |
2 | ||
3 | import edu.ucsb.cs156.happiercows.errors.EntityNotFoundException; | |
4 | import edu.ucsb.cs156.happiercows.models.CurrentUser; | |
5 | import edu.ucsb.cs156.happiercows.entities.Profit; | |
6 | import edu.ucsb.cs156.happiercows.entities.Commons; | |
7 | import edu.ucsb.cs156.happiercows.entities.User; | |
8 | import edu.ucsb.cs156.happiercows.entities.UserCommons; | |
9 | import edu.ucsb.cs156.happiercows.repositories.CommonsRepository; | |
10 | import edu.ucsb.cs156.happiercows.repositories.ProfitRepository; | |
11 | import edu.ucsb.cs156.happiercows.repositories.UserCommonsRepository; | |
12 | import io.swagger.annotations.Api; | |
13 | import io.swagger.annotations.ApiOperation; | |
14 | import io.swagger.annotations.ApiParam; | |
15 | import io.swagger.annotations.ApiResponse; | |
16 | import lombok.extern.slf4j.Slf4j; | |
17 | ||
18 | import javax.validation.Valid; | |
19 | ||
20 | import java.time.LocalDate; | |
21 | import java.time.LocalDateTime; | |
22 | import java.util.Optional; | |
23 | ||
24 | import com.fasterxml.jackson.core.JsonProcessingException; | |
25 | import com.fasterxml.jackson.databind.ObjectMapper; | |
26 | ||
27 | import org.springframework.beans.factory.annotation.Autowired; | |
28 | import org.springframework.http.ResponseEntity; | |
29 | import org.springframework.security.access.prepost.PreAuthorize; | |
30 | import org.springframework.web.bind.annotation.DeleteMapping; | |
31 | import org.springframework.web.bind.annotation.GetMapping; | |
32 | import org.springframework.web.bind.annotation.PostMapping; | |
33 | import org.springframework.web.bind.annotation.PutMapping; | |
34 | import org.springframework.web.bind.annotation.RequestBody; | |
35 | import org.springframework.web.bind.annotation.RequestMapping; | |
36 | import org.springframework.web.bind.annotation.RequestParam; | |
37 | import org.springframework.web.bind.annotation.RestController; | |
38 | ||
39 | @Api(description = "Profits") | |
40 | @RequestMapping("/api/profits") | |
41 | @RestController | |
42 | @Slf4j | |
43 | ||
44 | public class ProfitsController extends ApiController { | |
45 | ||
46 | @Autowired | |
47 | CommonsRepository commonsRepository; | |
48 | ||
49 | @Autowired | |
50 | UserCommonsRepository userCommonsRepository; | |
51 | ||
52 | @Autowired | |
53 | ProfitRepository profitRepository; | |
54 | ||
55 | @ApiOperation(value = "Get all profits belonging to a user commons as a user via CommonsID") | |
56 | @PreAuthorize("hasRole('ROLE_USER')") | |
57 | @GetMapping("/all/commonsid") | |
58 | public Iterable<Profit> allProfitsByCommonsId( | |
59 | @ApiParam("commonsId") @RequestParam Long commonsId) { | |
60 | Long userId = getCurrentUser().getUser().getId(); | |
61 | ||
62 | UserCommons userCommons = userCommonsRepository.findByCommonsIdAndUserId(commonsId, userId) | |
63 |
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)); |
64 | ||
65 |
1
1. allProfitsByCommonsId : negated conditional → KILLED |
if (userId != userCommons.getUserId()) |
66 | throw new EntityNotFoundException(UserCommons.class, userCommons.getId()); | |
67 | ||
68 | Iterable<Profit> profits = profitRepository.findAllByUserCommonsId(userCommons.getId()); | |
69 | ||
70 |
1
1. allProfitsByCommonsId : replaced return value with null for edu/ucsb/cs156/happiercows/controllers/ProfitsController::allProfitsByCommonsId → KILLED |
return profits; |
71 | } | |
72 | } | |
Mutations | ||
63 |
1.1 |
|
65 |
1.1 |
|
70 |
1.1 |