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
import io.swagger.v3.oas.annotations.Operation;
7
import io.swagger.v3.oas.annotations.Parameter;
8
import io.swagger.v3.oas.annotations.tags.Tag;
9
import lombok.extern.slf4j.Slf4j;
10
11
import com.fasterxml.jackson.core.JsonProcessingException;
12
13
import org.springframework.beans.factory.annotation.Autowired;
14
import org.springframework.format.annotation.DateTimeFormat;
15
import org.springframework.security.access.prepost.PreAuthorize;
16
import org.springframework.web.bind.annotation.DeleteMapping;
17
import org.springframework.web.bind.annotation.GetMapping;
18
import org.springframework.web.bind.annotation.PostMapping;
19
import org.springframework.web.bind.annotation.PutMapping;
20
import org.springframework.web.bind.annotation.RequestBody;
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
import jakarta.validation.Valid;
26
27
import java.time.LocalDateTime;
28
29
30
@Tag(name = "MenuItemReview")
31
@RequestMapping("/api/menuitemreview")
32
@RestController
33
@Slf4j
34
public class MenuItemReviewController extends ApiController {
35
    //please take into account id is the primary key of the entity and then the other fields
36
37
    @Autowired
38
    MenuItemReviewRepository menuItemsReviewRepository;
39
40
    /**
41
     * List all MenuItemReview
42
     * 
43
     * @return an iterable of MenuItemReview
44
     */
45
    @Operation(summary= "List all menu item reviews")
46
    @PreAuthorize("hasRole('ROLE_USER')")
47
    @GetMapping("/all")
48
    public Iterable<MenuItemReview> allMenuItemReview() {
49
        Iterable<MenuItemReview> reviews = menuItemsReviewRepository.findAll();
50 1 1. allMenuItemReview : replaced return value with Collections.emptyList for edu/ucsb/cs156/example/controllers/MenuItemReviewController::allMenuItemReview → KILLED
        return reviews;
51
    }
52
53
    @Operation(summary= "Create a new menu item review")
54
    @PreAuthorize("hasRole('ROLE_USER')")
55
    @PostMapping("/post")
56
57
    //Create a new menu item review
58
    public MenuItemReview postMenuItemReview(
59
            @Parameter(name="itemId") @RequestParam long itemId,
60
            @Parameter(name="reviewerEmail") @RequestParam String reviewerEmail,
61
            @Parameter(name="stars") @RequestParam int stars,
62
            @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,
63
            @Parameter(name="comments") @RequestParam String comments)
64
            throws JsonProcessingException {
65
66
        // For an explanation of @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME)
67
        // See: https://www.baeldung.com/spring-date-parameters
68
69
        log.info("dateReviewed={}", dateReviewed);
70
71
        MenuItemReview menuItemReview = new MenuItemReview();
72 1 1. postMenuItemReview : removed call to edu/ucsb/cs156/example/entities/MenuItemReview::setItemId → KILLED
        menuItemReview.setItemId(itemId);
73 1 1. postMenuItemReview : removed call to edu/ucsb/cs156/example/entities/MenuItemReview::setReviewerEmail → KILLED
        menuItemReview.setReviewerEmail(reviewerEmail);
74 1 1. postMenuItemReview : removed call to edu/ucsb/cs156/example/entities/MenuItemReview::setStars → KILLED
        menuItemReview.setStars(stars);
75 1 1. postMenuItemReview : removed call to edu/ucsb/cs156/example/entities/MenuItemReview::setDateReviewed → KILLED
        menuItemReview.setDateReviewed(dateReviewed);
76 1 1. postMenuItemReview : removed call to edu/ucsb/cs156/example/entities/MenuItemReview::setComments → KILLED
        menuItemReview.setComments(comments);
77
78
        MenuItemReview savedMenuItemReview = menuItemsReviewRepository.save(menuItemReview);
79
80 1 1. postMenuItemReview : replaced return value with null for edu/ucsb/cs156/example/controllers/MenuItemReviewController::postMenuItemReview → KILLED
        return savedMenuItemReview;
81
    }
82
83
    @Operation(summary="get a single menu item review")
84
    @PreAuthorize("hasRole('ROLE_USER')")
85
    @GetMapping("")
86
87
    //Get a single menu item review by id
88
    public MenuItemReview getById(
89
            @Parameter(name="id") @RequestParam Long id) {
90
        MenuItemReview menuItemReview = menuItemsReviewRepository.findById(id)
91 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));
92
93 1 1. getById : replaced return value with null for edu/ucsb/cs156/example/controllers/MenuItemReviewController::getById → KILLED
        return menuItemReview;
94
    }
95
96
    @Operation(summary="Delete a menu item review by id")
97
    @PreAuthorize("hasRole('ROLE_USER')")
98
    @DeleteMapping("")
99
100
    //Delete a menu item review by id(not itemId)
101
102
    public Object deleteMenuItemReview(
103
            @Parameter(name="id") @RequestParam Long id) {
104
        MenuItemReview menuItemReview = menuItemsReviewRepository.findById(id)
105 1 1. lambda$deleteMenuItemReview$1 : replaced return value with null for edu/ucsb/cs156/example/controllers/MenuItemReviewController::lambda$deleteMenuItemReview$1 → KILLED
                .orElseThrow(() -> new EntityNotFoundException(MenuItemReview.class, id));
106
107 1 1. deleteMenuItemReview : removed call to edu/ucsb/cs156/example/repositories/MenuItemReviewRepository::delete → KILLED
        menuItemsReviewRepository.delete(menuItemReview);
108 1 1. deleteMenuItemReview : replaced return value with null for edu/ucsb/cs156/example/controllers/MenuItemReviewController::deleteMenuItemReview → KILLED
        return genericMessage("MenuItemReview with id %s deleted".formatted(id));
109
    }
110
111
    @Operation(summary="Update a single menu item review")
112
    @PreAuthorize("hasRole('ROLE_USER')")
113
    @PutMapping("")
114
115
    //Update a single menu item review by id
116
    public MenuItemReview updateMenuItemReview(
117
            @Parameter(name="id") @RequestParam Long id,
118
            @RequestBody @Valid MenuItemReview incoming) {
119
120
        MenuItemReview menuItemReview = menuItemsReviewRepository.findById(id)
121 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));
122
123 1 1. updateMenuItemReview : removed call to edu/ucsb/cs156/example/entities/MenuItemReview::setItemId → KILLED
        menuItemReview.setItemId(incoming.getItemId());
124 1 1. updateMenuItemReview : removed call to edu/ucsb/cs156/example/entities/MenuItemReview::setReviewerEmail → KILLED
        menuItemReview.setReviewerEmail(incoming.getReviewerEmail());
125 1 1. updateMenuItemReview : removed call to edu/ucsb/cs156/example/entities/MenuItemReview::setStars → KILLED
        menuItemReview.setStars(incoming.getStars());
126 1 1. updateMenuItemReview : removed call to edu/ucsb/cs156/example/entities/MenuItemReview::setDateReviewed → KILLED
        menuItemReview.setDateReviewed(incoming.getDateReviewed());
127 1 1. updateMenuItemReview : removed call to edu/ucsb/cs156/example/entities/MenuItemReview::setComments → KILLED
        menuItemReview.setComments(incoming.getComments());
128
129
        menuItemsReviewRepository.save(menuItemReview);
130
131 1 1. updateMenuItemReview : replaced return value with null for edu/ucsb/cs156/example/controllers/MenuItemReviewController::updateMenuItemReview → KILLED
        return menuItemReview;
132
    }
133
}

Mutations

50

1.1
Location : allMenuItemReview
Killed by : edu.ucsb.cs156.example.controllers.MenuItemReviewControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.example.controllers.MenuItemReviewControllerTests]/[method:logged_in_users_can_get_all_menuitemreview()]
replaced return value with Collections.emptyList for edu/ucsb/cs156/example/controllers/MenuItemReviewController::allMenuItemReview → 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_menuitemreview()]
removed call to edu/ucsb/cs156/example/entities/MenuItemReview::setItemId → KILLED

73

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_menuitemreview()]
removed call to edu/ucsb/cs156/example/entities/MenuItemReview::setReviewerEmail → KILLED

74

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_menuitemreview()]
removed call to edu/ucsb/cs156/example/entities/MenuItemReview::setStars → KILLED

75

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_menuitemreview()]
removed call to edu/ucsb/cs156/example/entities/MenuItemReview::setDateReviewed → KILLED

76

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_menuitemreview()]
removed call to edu/ucsb/cs156/example/entities/MenuItemReview::setComments → KILLED

80

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_menuitemreview()]
replaced return value with null for edu/ucsb/cs156/example/controllers/MenuItemReviewController::postMenuItemReview → KILLED

91

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

93

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

105

1.1
Location : lambda$deleteMenuItemReview$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$deleteMenuItemReview$1 → KILLED

107

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

108

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

121

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_menuitemreview_that_does_not_exist()]
replaced return value with null for edu/ucsb/cs156/example/controllers/MenuItemReviewController::lambda$updateMenuItemReview$2 → KILLED

123

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

124

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

125

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

126

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

127

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

131

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