MenuItemReviewController.java

1
package edu.ucsb.cs156.example.controllers;
2
3
import edu.ucsb.cs156.example.entities.MenuItemReview;
4
import edu.ucsb.cs156.example.entities.MenuItemReview;
5
import edu.ucsb.cs156.example.errors.EntityNotFoundException;
6
import edu.ucsb.cs156.example.repositories.MenuItemReviewRepository;
7
8
import io.swagger.v3.oas.annotations.Operation;
9
import io.swagger.v3.oas.annotations.Parameter;
10
import io.swagger.v3.oas.annotations.tags.Tag;
11
import lombok.extern.slf4j.Slf4j;
12
13
import com.fasterxml.jackson.core.JsonProcessingException;
14
15
import org.springframework.beans.factory.annotation.Autowired;
16
import org.springframework.format.annotation.DateTimeFormat;
17
import org.springframework.security.access.prepost.PreAuthorize;
18
import org.springframework.web.bind.annotation.DeleteMapping;
19
import org.springframework.web.bind.annotation.GetMapping;
20
import org.springframework.web.bind.annotation.PostMapping;
21
import org.springframework.web.bind.annotation.PutMapping;
22
import org.springframework.web.bind.annotation.RequestBody;
23
import org.springframework.web.bind.annotation.RequestMapping;
24
import org.springframework.web.bind.annotation.RequestParam;
25
import org.springframework.web.bind.annotation.RestController;
26
27
import jakarta.validation.Valid;
28
29
import java.time.LocalDateTime;
30
31
/**
32
 * This is a REST controller for MenuItemReviews
33
 */
34
35
@Tag(name = "MenuItemReview")
36
@RequestMapping("/api/menuitemreview")
37
@RestController
38
@Slf4j
39
public class MenuItemReviewController extends ApiController {
40
41
    @Autowired
42
    MenuItemReviewRepository menuItemReviewRepository;
43
44
    /**
45
     * List all UCSB dates
46
     * 
47
     * @return an iterable of MenuItemReview
48
     */
49
    @Operation(summary= "List all menu item reviews")
50
    @PreAuthorize("hasRole('ROLE_USER')")
51
    @GetMapping("/all")
52
    public Iterable<MenuItemReview> allMenuItemReviews() {
53
        Iterable<MenuItemReview> reviews = menuItemReviewRepository.findAll();
54 1 1. allMenuItemReviews : replaced return value with Collections.emptyList for edu/ucsb/cs156/example/controllers/MenuItemReviewController::allMenuItemReviews → KILLED
        return reviews;
55
    }
56
57
    /**
58
     * Get a single review by id
59
     * 
60
     * @param id the id of the review (not the same as itemId)
61
     * @return a MenuItemReview
62
     */
63
    @Operation(summary= "Get a single review")
64
    @PreAuthorize("hasRole('ROLE_USER')")
65
    @GetMapping("")
66
    public MenuItemReview getById(
67
            @Parameter(name="id") @RequestParam Long id) {
68
        MenuItemReview menuItemReview = menuItemReviewRepository.findById(id)
69 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));
70
71 1 1. getById : replaced return value with null for edu/ucsb/cs156/example/controllers/MenuItemReviewController::getById → KILLED
        return menuItemReview;
72
    }
73
74
    /**
75
     * Delete a MenuItemReview
76
     * 
77
     * @param id the id of the review to delete
78
     * @return a message indicating the review was deleted
79
     */
80
    @Operation(summary= "Delete a MenuItemReview")
81
    @PreAuthorize("hasRole('ROLE_ADMIN')")
82
    @DeleteMapping("")
83
    public Object deleteMenuItemReview(
84
            @Parameter(name="id") @RequestParam Long id) {
85
        MenuItemReview menuItemReview = menuItemReviewRepository.findById(id)
86 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));
87
88 1 1. deleteMenuItemReview : removed call to edu/ucsb/cs156/example/repositories/MenuItemReviewRepository::delete → KILLED
        menuItemReviewRepository.delete(menuItemReview);
89 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));
90
    }
91
92
93
    /**
94
     * Create a new review
95
     * 
96
     * @param itemId            the id of the food item being reviewed
97
     * @param reviewerEmail     the email of the reviewer
98
     * @param stars             star rating of the review
99
     * @param dateReviewed      date of the review
100
     * @param comments          comments in the review
101
     * @return the saved menu item review
102
     */
103
    @Operation(summary= "Create a new menu item review")
104
    @PreAuthorize("hasRole('ROLE_ADMIN')")
105
    @PostMapping("/post")
106
    public MenuItemReview postMenuItemReview(
107
            @Parameter(name="itemId") @RequestParam long itemId,
108
            @Parameter(name="reviewerEmail") @RequestParam String reviewerEmail,
109
            @Parameter(name="stars") @RequestParam int stars,
110
            @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,
111
            @Parameter(name="comments") @RequestParam String comments)
112
            throws JsonProcessingException {
113
114
        // For an explanation of @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME)
115
        // See: https://www.baeldung.com/spring-date-parameters
116
117
        log.info("dateReviewed={}", dateReviewed);
118
119
        MenuItemReview menuItemReview = new MenuItemReview();
120 1 1. postMenuItemReview : removed call to edu/ucsb/cs156/example/entities/MenuItemReview::setItemId → KILLED
        menuItemReview.setItemId(itemId);
121 1 1. postMenuItemReview : removed call to edu/ucsb/cs156/example/entities/MenuItemReview::setReviewerEmail → KILLED
        menuItemReview.setReviewerEmail(reviewerEmail);
122 1 1. postMenuItemReview : removed call to edu/ucsb/cs156/example/entities/MenuItemReview::setStars → KILLED
        menuItemReview.setStars(stars);
123 1 1. postMenuItemReview : removed call to edu/ucsb/cs156/example/entities/MenuItemReview::setDateReviewed → KILLED
        menuItemReview.setDateReviewed(dateReviewed);
124 1 1. postMenuItemReview : removed call to edu/ucsb/cs156/example/entities/MenuItemReview::setComments → KILLED
        menuItemReview.setComments(comments);
125
126
        MenuItemReview savedReview = menuItemReviewRepository.save(menuItemReview);
127
128 1 1. postMenuItemReview : replaced return value with null for edu/ucsb/cs156/example/controllers/MenuItemReviewController::postMenuItemReview → KILLED
        return savedReview;
129
130
    }
131
132
    /**
133
     * Update a single review
134
     * 
135
     * @param id       id of the review to update
136
     * @param incoming the new review
137
     * @return the updated review object
138
     */
139
    @Operation(summary= "Update a single review")
140
    @PreAuthorize("hasRole('ROLE_ADMIN')")
141
    @PutMapping("")
142
    public MenuItemReview updateMenuItemReview(
143
            @Parameter(name="id") @RequestParam Long id,
144
            @RequestBody @Valid MenuItemReview incoming) {
145
146
        MenuItemReview menuItemReview = menuItemReviewRepository.findById(id)
147 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));
148
149 1 1. updateMenuItemReview : removed call to edu/ucsb/cs156/example/entities/MenuItemReview::setItemId → KILLED
        menuItemReview.setItemId(incoming.getItemId());
150 1 1. updateMenuItemReview : removed call to edu/ucsb/cs156/example/entities/MenuItemReview::setReviewerEmail → KILLED
        menuItemReview.setReviewerEmail(incoming.getReviewerEmail());
151 1 1. updateMenuItemReview : removed call to edu/ucsb/cs156/example/entities/MenuItemReview::setComments → KILLED
        menuItemReview.setComments(incoming.getComments());
152 1 1. updateMenuItemReview : removed call to edu/ucsb/cs156/example/entities/MenuItemReview::setDateReviewed → KILLED
        menuItemReview.setDateReviewed(incoming.getDateReviewed());
153 1 1. updateMenuItemReview : removed call to edu/ucsb/cs156/example/entities/MenuItemReview::setStars → KILLED
        menuItemReview.setStars(incoming.getStars());
154
155
        menuItemReviewRepository.save(menuItemReview);
156
157 1 1. updateMenuItemReview : replaced return value with null for edu/ucsb/cs156/example/controllers/MenuItemReviewController::updateMenuItemReview → KILLED
        return menuItemReview;
158
    }
159
160
}

Mutations

54

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_reviews()]
replaced return value with Collections.emptyList for edu/ucsb/cs156/example/controllers/MenuItemReviewController::allMenuItemReviews → KILLED

69

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

71

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

86

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

88

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_review()]
removed call to edu/ucsb/cs156/example/repositories/MenuItemReviewRepository::delete → KILLED

89

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

120

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

121

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

122

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

123

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

124

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

128

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

147

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

149

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

150

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

151

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

152

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

153

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

157

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