ProfitsController.java

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
13
import lombok.extern.slf4j.Slf4j;
14
15
import org.springframework.beans.factory.annotation.Autowired;
16
import org.springframework.data.domain.Page;
17
import org.springframework.data.domain.PageRequest;
18
import org.springframework.data.domain.Sort;
19
import org.springframework.security.access.prepost.PreAuthorize;
20
import org.springframework.web.bind.annotation.GetMapping;
21
import org.springframework.web.bind.annotation.RequestMapping;
22
import org.springframework.web.bind.annotation.RequestParam;
23
import org.springframework.web.bind.annotation.RestController;
24
25
@Tag(name = "Profits")
26
@RequestMapping("/api/profits")
27
@RestController
28
@Slf4j
29
30
public class ProfitsController extends ApiController {
31
32
    @Autowired
33
    CommonsRepository commonsRepository;
34
35
    @Autowired
36
    UserCommonsRepository userCommonsRepository;
37
38
    @Autowired
39
    ProfitRepository profitRepository;
40
41
    @Operation(summary = "Get all profits belonging to a user commons as a user via CommonsID")
42
    @PreAuthorize("hasRole('ROLE_USER')")
43
    @GetMapping("/all/commonsid")
44
    public Iterable<Profit> allProfitsByCommonsId(
45
            @Parameter(name="commonsId") @RequestParam Long commonsId
46
    ) {
47
        Long userId = getCurrentUser().getUser().getId();
48
49
        UserCommons userCommons = userCommonsRepository.findByCommonsIdAndUserId(commonsId, userId)
50 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));
51
52
        Iterable<Profit> profits = profitRepository.findAllByUserCommons(userCommons);
53
54 1 1. allProfitsByCommonsId : replaced return value with null for edu/ucsb/cs156/happiercows/controllers/ProfitsController::allProfitsByCommonsId → KILLED
        return profits;
55
    }
56
57
    @Operation(summary = "Get all profits belonging to a user commons as a user via CommonsID")
58
    @PreAuthorize("hasRole('ROLE_USER')")
59
    @GetMapping("/all/commonsid/pageable")
60
    public Page<Profit> allProfitsByCommonsIdPaged(
61
        @Parameter(name="page") @RequestParam int page,
62
        @Parameter(name="size") @RequestParam int size
63
    ) {
64
        Page<Profit> profits = profitRepository.findAll(PageRequest.of(page, size, Sort.by("timestamp").descending()));
65 1 1. allProfitsByCommonsIdPaged : replaced return value with null for edu/ucsb/cs156/happiercows/controllers/ProfitsController::allProfitsByCommonsIdPaged → KILLED
        return profits;
66
    }
67
}

Mutations

50

1.1
Location : lambda$allProfitsByCommonsId$0
Killed by : edu.ucsb.cs156.happiercows.controllers.ProfitsControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.happiercows.controllers.ProfitsControllerTests]/[method:get_profits_all_commons_nonexistent_using_commons_id()]
replaced return value with null for edu/ucsb/cs156/happiercows/controllers/ProfitsController::lambda$allProfitsByCommonsId$0 → KILLED

54

1.1
Location : allProfitsByCommonsId
Killed by : edu.ucsb.cs156.happiercows.controllers.ProfitsControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.happiercows.controllers.ProfitsControllerTests]/[method:get_profits_all_commons_using_commons_id()]
replaced return value with null for edu/ucsb/cs156/happiercows/controllers/ProfitsController::allProfitsByCommonsId → KILLED

65

1.1
Location : allProfitsByCommonsIdPaged
Killed by : edu.ucsb.cs156.happiercows.controllers.ProfitsControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.happiercows.controllers.ProfitsControllerTests]/[method:admin_can_get_all_profits_paged()]
replaced return value with null for edu/ucsb/cs156/happiercows/controllers/ProfitsController::allProfitsByCommonsIdPaged → KILLED

Active mutators

Tests examined


Report generated by PIT 1.7.3