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

Mutations

53

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

86

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

87

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

88

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

89

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

90

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

94

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

110

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

112

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

127

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

129

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

130

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

149

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_menu_item_review_that_does_not_exist()]
replaced return value with null for edu/ucsb/cs156/example/controllers/MenuItemReviewController::lambda$updateMenuItemReview$2 → 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_menu_item_review()]
removed call to edu/ucsb/cs156/example/entities/MenuItemReview::setItemId → 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_menu_item_review()]
removed call to edu/ucsb/cs156/example/entities/MenuItemReview::setReviewerEmail → 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_menu_item_review()]
removed call to edu/ucsb/cs156/example/entities/MenuItemReview::setStars → KILLED

154

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

155

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

160

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_menu_item_review()]
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