MenuItemReviewController.java

1
package edu.ucsb.cs156.example.controllers;
2
3
import edu.ucsb.cs156.example.entities.MenuItemReview;
4
import edu.ucsb.cs156.example.errors.EntityNotFoundException;
5
import edu.ucsb.cs156.example.repositories.MenuItemReviewRepository;
6
7
import io.swagger.v3.oas.annotations.Operation;
8
import io.swagger.v3.oas.annotations.Parameter;
9
import io.swagger.v3.oas.annotations.tags.Tag;
10
import lombok.extern.slf4j.Slf4j;
11
12
import com.fasterxml.jackson.core.JsonProcessingException;
13
14
import org.springframework.beans.factory.annotation.Autowired;
15
import org.springframework.format.annotation.DateTimeFormat;
16
import org.springframework.security.access.prepost.PreAuthorize;
17
import org.springframework.web.bind.annotation.DeleteMapping;
18
import org.springframework.web.bind.annotation.GetMapping;
19
import org.springframework.web.bind.annotation.PostMapping;
20
import org.springframework.web.bind.annotation.PutMapping;
21
import org.springframework.web.bind.annotation.RequestBody;
22
import org.springframework.web.bind.annotation.RequestMapping;
23
import org.springframework.web.bind.annotation.RequestParam;
24
import org.springframework.web.bind.annotation.RestController;
25
26
import jakarta.validation.Valid;
27
28
import java.time.LocalDateTime;
29
30
@Tag(name = "MenuItemReview")
31
@RequestMapping("/api/menuitemreview")
32
@RestController
33
@Slf4j
34
public class MenuItemReviewController extends ApiController{
35
    
36
    @Autowired
37
    MenuItemReviewRepository menuItemReviewRepository;
38
39
    @Operation(summary= "List all menu item reviews")
40
        @PreAuthorize("hasRole('ROLE_USER')")
41
        @GetMapping("/all")
42
        public Iterable<MenuItemReview> allMenuItemReviews() {
43
            Iterable<MenuItemReview> reviews = menuItemReviewRepository.findAll();
44 1 1. allMenuItemReviews : replaced return value with Collections.emptyList for edu/ucsb/cs156/example/controllers/MenuItemReviewController::allMenuItemReviews → KILLED
            return reviews;
45
        }
46
47
    @Operation(summary= "Create a new review")
48
    @PreAuthorize("hasRole('ROLE_ADMIN')")
49
    @PostMapping("/post")
50
    public MenuItemReview postMenuItemReview(
51
            @Parameter(name="itemId") @RequestParam long itemId,
52
            @Parameter(name="reviewerEmail") @RequestParam String reviewerEmail,
53
            @Parameter(name="stars") @RequestParam int stars,
54
            @Parameter(name="dateReviewed", description="date (in iso format, e.g. YYYY-mm-ddTHH:MM:SS; see https://en.wikipedia.org/wiki/ISO_8601)") @RequestParam("dateReviewed") @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME) LocalDateTime dateReviewed,
55
            @Parameter(name="comments") @RequestParam String comments)
56
            throws JsonProcessingException {
57
58
        // For an explanation of @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME)
59
        // See: https://www.baeldung.com/spring-date-parameters
60
61
        //log.info("localDateTime={}", dateReviewed);
62
63
        MenuItemReview menuItemReview = new MenuItemReview();
64 1 1. postMenuItemReview : removed call to edu/ucsb/cs156/example/entities/MenuItemReview::setItemId → KILLED
        menuItemReview.setItemId(itemId);
65 1 1. postMenuItemReview : removed call to edu/ucsb/cs156/example/entities/MenuItemReview::setReviewerEmail → KILLED
        menuItemReview.setReviewerEmail(reviewerEmail);
66 1 1. postMenuItemReview : removed call to edu/ucsb/cs156/example/entities/MenuItemReview::setStars → KILLED
        menuItemReview.setStars(stars);
67 1 1. postMenuItemReview : removed call to edu/ucsb/cs156/example/entities/MenuItemReview::setDateReviewed → KILLED
        menuItemReview.setDateReviewed(dateReviewed);
68 1 1. postMenuItemReview : removed call to edu/ucsb/cs156/example/entities/MenuItemReview::setComments → KILLED
        menuItemReview.setComments(comments);
69
70
        MenuItemReview savedMenuItemReview = menuItemReviewRepository.save(menuItemReview);
71
72 1 1. postMenuItemReview : replaced return value with null for edu/ucsb/cs156/example/controllers/MenuItemReviewController::postMenuItemReview → KILLED
        return savedMenuItemReview;
73
    }
74
75
    @Operation(summary= "Get a single review")
76
    @PreAuthorize("hasRole('ROLE_USER')")
77
    @GetMapping("")
78
    public MenuItemReview getById(
79
            @Parameter(name="id") @RequestParam Long id) {
80
        MenuItemReview menuItemReview = menuItemReviewRepository.findById(id)
81 1 1. lambda$getById$0 : replaced return value with null for edu/ucsb/cs156/example/controllers/MenuItemReviewController::lambda$getById$0 → KILLED
                .orElseThrow(() -> new EntityNotFoundException(MenuItemReview.class, id));
82
83 1 1. getById : replaced return value with null for edu/ucsb/cs156/example/controllers/MenuItemReviewController::getById → KILLED
        return menuItemReview;
84
    }
85
86
    @Operation(summary= "Delete a MenuItemReview")
87
    @PreAuthorize("hasRole('ROLE_ADMIN')")
88
    @DeleteMapping("")
89
    public Object delteMenuItemReview(
90
            @Parameter(name="id") @RequestParam Long id) {
91
        MenuItemReview menuItemReview = menuItemReviewRepository.findById(id)
92 1 1. lambda$delteMenuItemReview$1 : replaced return value with null for edu/ucsb/cs156/example/controllers/MenuItemReviewController::lambda$delteMenuItemReview$1 → KILLED
                .orElseThrow(() -> new EntityNotFoundException(MenuItemReview.class, id));
93
94 1 1. delteMenuItemReview : removed call to edu/ucsb/cs156/example/repositories/MenuItemReviewRepository::delete → KILLED
        menuItemReviewRepository.delete(menuItemReview);
95 1 1. delteMenuItemReview : replaced return value with null for edu/ucsb/cs156/example/controllers/MenuItemReviewController::delteMenuItemReview → KILLED
        return genericMessage("MenuItemReview with id %s deleted".formatted(id));
96
    }
97
98
    @Operation(summary= "Update a single review")
99
    @PreAuthorize("hasRole('ROLE_ADMIN')")
100
    @PutMapping("")
101
    public MenuItemReview updateMenuItemReview(
102
            @Parameter(name="id") @RequestParam Long id,
103
            @RequestBody @Valid MenuItemReview incoming) {
104
105
        MenuItemReview menuItemReview = menuItemReviewRepository.findById(id)
106 1 1. lambda$updateMenuItemReview$2 : replaced return value with null for edu/ucsb/cs156/example/controllers/MenuItemReviewController::lambda$updateMenuItemReview$2 → KILLED
                .orElseThrow(() -> new EntityNotFoundException(MenuItemReview.class, id));
107
108 1 1. updateMenuItemReview : removed call to edu/ucsb/cs156/example/entities/MenuItemReview::setItemId → KILLED
        menuItemReview.setItemId(incoming.getItemId());
109 1 1. updateMenuItemReview : removed call to edu/ucsb/cs156/example/entities/MenuItemReview::setReviewerEmail → KILLED
        menuItemReview.setReviewerEmail(incoming.getReviewerEmail());
110 1 1. updateMenuItemReview : removed call to edu/ucsb/cs156/example/entities/MenuItemReview::setStars → KILLED
        menuItemReview.setStars(incoming.getStars());
111 1 1. updateMenuItemReview : removed call to edu/ucsb/cs156/example/entities/MenuItemReview::setDateReviewed → KILLED
        menuItemReview.setDateReviewed(incoming.getDateReviewed());
112 1 1. updateMenuItemReview : removed call to edu/ucsb/cs156/example/entities/MenuItemReview::setComments → KILLED
        menuItemReview.setComments(incoming.getComments());
113
114
        menuItemReviewRepository.save(menuItemReview);
115
116 1 1. updateMenuItemReview : replaced return value with null for edu/ucsb/cs156/example/controllers/MenuItemReviewController::updateMenuItemReview → KILLED
        return menuItemReview;
117
    }
118
119
}

Mutations

44

1.1
Location : allMenuItemReviews
Killed by : edu.ucsb.cs156.example.controllers.MenuItemReviewControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.example.controllers.MenuItemReviewControllerTests]/[method:logged_in_user_can_get_all_menuItemReviews()]
replaced return value with Collections.emptyList for edu/ucsb/cs156/example/controllers/MenuItemReviewController::allMenuItemReviews → KILLED

64

1.1
Location : postMenuItemReview
Killed by : edu.ucsb.cs156.example.controllers.MenuItemReviewControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.example.controllers.MenuItemReviewControllerTests]/[method:an_admin_user_can_post_a_new_review()]
removed call to edu/ucsb/cs156/example/entities/MenuItemReview::setItemId → KILLED

65

1.1
Location : postMenuItemReview
Killed by : edu.ucsb.cs156.example.controllers.MenuItemReviewControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.example.controllers.MenuItemReviewControllerTests]/[method:an_admin_user_can_post_a_new_review()]
removed call to edu/ucsb/cs156/example/entities/MenuItemReview::setReviewerEmail → KILLED

66

1.1
Location : postMenuItemReview
Killed by : edu.ucsb.cs156.example.controllers.MenuItemReviewControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.example.controllers.MenuItemReviewControllerTests]/[method:an_admin_user_can_post_a_new_review()]
removed call to edu/ucsb/cs156/example/entities/MenuItemReview::setStars → KILLED

67

1.1
Location : postMenuItemReview
Killed by : edu.ucsb.cs156.example.controllers.MenuItemReviewControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.example.controllers.MenuItemReviewControllerTests]/[method:an_admin_user_can_post_a_new_review()]
removed call to edu/ucsb/cs156/example/entities/MenuItemReview::setDateReviewed → KILLED

68

1.1
Location : postMenuItemReview
Killed by : edu.ucsb.cs156.example.controllers.MenuItemReviewControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.example.controllers.MenuItemReviewControllerTests]/[method:an_admin_user_can_post_a_new_review()]
removed call to edu/ucsb/cs156/example/entities/MenuItemReview::setComments → KILLED

72

1.1
Location : postMenuItemReview
Killed by : edu.ucsb.cs156.example.controllers.MenuItemReviewControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.example.controllers.MenuItemReviewControllerTests]/[method:an_admin_user_can_post_a_new_review()]
replaced return value with null for edu/ucsb/cs156/example/controllers/MenuItemReviewController::postMenuItemReview → KILLED

81

1.1
Location : lambda$getById$0
Killed by : edu.ucsb.cs156.example.controllers.MenuItemReviewControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.example.controllers.MenuItemReviewControllerTests]/[method:test_that_logged_in_user_can_get_by_id_when_the_id_does_not_exist()]
replaced return value with null for edu/ucsb/cs156/example/controllers/MenuItemReviewController::lambda$getById$0 → KILLED

83

1.1
Location : getById
Killed by : edu.ucsb.cs156.example.controllers.MenuItemReviewControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.example.controllers.MenuItemReviewControllerTests]/[method:test_that_logged_in_user_can_get_by_id_when_the_id_exists()]
replaced return value with null for edu/ucsb/cs156/example/controllers/MenuItemReviewController::getById → KILLED

92

1.1
Location : lambda$delteMenuItemReview$1
Killed by : edu.ucsb.cs156.example.controllers.MenuItemReviewControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.example.controllers.MenuItemReviewControllerTests]/[method:admin_tries_to_delete_non_existant_menuitemreview_and_gets_right_error_message()]
replaced return value with null for edu/ucsb/cs156/example/controllers/MenuItemReviewController::lambda$delteMenuItemReview$1 → KILLED

94

1.1
Location : delteMenuItemReview
Killed by : edu.ucsb.cs156.example.controllers.MenuItemReviewControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.example.controllers.MenuItemReviewControllerTests]/[method:admin_can_delete_a_review()]
removed call to edu/ucsb/cs156/example/repositories/MenuItemReviewRepository::delete → KILLED

95

1.1
Location : delteMenuItemReview
Killed by : edu.ucsb.cs156.example.controllers.MenuItemReviewControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.example.controllers.MenuItemReviewControllerTests]/[method:admin_can_delete_a_review()]
replaced return value with null for edu/ucsb/cs156/example/controllers/MenuItemReviewController::delteMenuItemReview → KILLED

106

1.1
Location : lambda$updateMenuItemReview$2
Killed by : edu.ucsb.cs156.example.controllers.MenuItemReviewControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.example.controllers.MenuItemReviewControllerTests]/[method:admin_cannot_edit_menureview_that_does_not_exist()]
replaced return value with null for edu/ucsb/cs156/example/controllers/MenuItemReviewController::lambda$updateMenuItemReview$2 → KILLED

108

1.1
Location : updateMenuItemReview
Killed by : edu.ucsb.cs156.example.controllers.MenuItemReviewControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.example.controllers.MenuItemReviewControllerTests]/[method:admin_can_edit_an_existing_menuitemreview()]
removed call to edu/ucsb/cs156/example/entities/MenuItemReview::setItemId → KILLED

109

1.1
Location : updateMenuItemReview
Killed by : edu.ucsb.cs156.example.controllers.MenuItemReviewControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.example.controllers.MenuItemReviewControllerTests]/[method:admin_can_edit_an_existing_menuitemreview()]
removed call to edu/ucsb/cs156/example/entities/MenuItemReview::setReviewerEmail → KILLED

110

1.1
Location : updateMenuItemReview
Killed by : edu.ucsb.cs156.example.controllers.MenuItemReviewControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.example.controllers.MenuItemReviewControllerTests]/[method:admin_can_edit_an_existing_menuitemreview()]
removed call to edu/ucsb/cs156/example/entities/MenuItemReview::setStars → KILLED

111

1.1
Location : updateMenuItemReview
Killed by : edu.ucsb.cs156.example.controllers.MenuItemReviewControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.example.controllers.MenuItemReviewControllerTests]/[method:admin_can_edit_an_existing_menuitemreview()]
removed call to edu/ucsb/cs156/example/entities/MenuItemReview::setDateReviewed → KILLED

112

1.1
Location : updateMenuItemReview
Killed by : edu.ucsb.cs156.example.controllers.MenuItemReviewControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.example.controllers.MenuItemReviewControllerTests]/[method:admin_can_edit_an_existing_menuitemreview()]
removed call to edu/ucsb/cs156/example/entities/MenuItemReview::setComments → KILLED

116

1.1
Location : updateMenuItemReview
Killed by : edu.ucsb.cs156.example.controllers.MenuItemReviewControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.example.controllers.MenuItemReviewControllerTests]/[method:admin_can_edit_an_existing_menuitemreview()]
replaced return value with null for edu/ucsb/cs156/example/controllers/MenuItemReviewController::updateMenuItemReview → KILLED

Active mutators

Tests examined


Report generated by PIT 1.17.0