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.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 Menu Item Reviews
33
 */
34
35
36
@Tag(name = "MenuItemReview")
37
@RequestMapping("/api/MENUITEMREVIEW")
38
@RestController
39
@Slf4j
40
41
42
public class MenuItemReviewController extends ApiController {
43
44
    @Autowired
45
    MenuItemReviewRepository menuItemReviewRepository;
46
47
    /**
48
     * List all reviews
49
     * 
50
     * @return an iterable of menu item reviews
51
     */
52
53
    
54
55
    @Operation(summary= "List all menu item reviews")
56
    @PreAuthorize("hasRole('ROLE_USER')")
57
    @GetMapping("/all")
58
    public Iterable<MenuItemReview> allmenuitemreviews() {
59
        Iterable<MenuItemReview> reviews = menuItemReviewRepository.findAll();
60 1 1. allmenuitemreviews : replaced return value with Collections.emptyList for edu/ucsb/cs156/example/controllers/MenuItemReviewController::allmenuitemreviews → KILLED
        return reviews;
61
    }
62
63
    /**
64
     * Get a single review by id
65
     * 
66
     * @param id the id of the review
67
     * @return a menuItemReview
68
     */
69
    @Operation(summary= "Get a single review")
70
    @PreAuthorize("hasRole('ROLE_USER')")
71
    @GetMapping("")
72
    public MenuItemReview getById(
73
            @Parameter(name="id") @RequestParam Long id) {
74
        MenuItemReview menuItemReview = menuItemReviewRepository.findById(id)
75 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));
76
77 1 1. getById : replaced return value with null for edu/ucsb/cs156/example/controllers/MenuItemReviewController::getById → KILLED
        return menuItemReview;
78
    }
79
80
    @Operation(summary= "Create a new item review")
81
    @PreAuthorize("hasRole('ROLE_ADMIN')")
82
    @PostMapping("/post")
83
    public MenuItemReview postitemreview(
84
            @Parameter(name="reviewerEmail") @RequestParam String reviewerEmail,
85
            @Parameter(name="stars") @RequestParam int stars,
86
            @Parameter(name="comments") @RequestParam String comments,
87
            @Parameter(name="dateReviewed") @RequestParam @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME) LocalDateTime dateReviewed) 
88
            
89
            throws JsonProcessingException {
90
91
        // For an explanation of @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME)
92
        // See: https://www.baeldung.com/spring-date-parameters
93
94
        log.info("dateReviewed={}", dateReviewed);
95
96
        MenuItemReview menuItemReview = new MenuItemReview();
97 1 1. postitemreview : removed call to edu/ucsb/cs156/example/entities/MenuItemReview::setReviewerEmail → KILLED
        menuItemReview.setReviewerEmail(reviewerEmail);
98 1 1. postitemreview : removed call to edu/ucsb/cs156/example/entities/MenuItemReview::setStars → KILLED
        menuItemReview.setStars(stars);
99 1 1. postitemreview : removed call to edu/ucsb/cs156/example/entities/MenuItemReview::setComments → KILLED
        menuItemReview.setComments(comments);
100 1 1. postitemreview : removed call to edu/ucsb/cs156/example/entities/MenuItemReview::setDateReviewed → KILLED
        menuItemReview.setDateReviewed(dateReviewed);
101
102
        MenuItemReview savedMenuItemReview = menuItemReviewRepository.save(menuItemReview);
103
104 1 1. postitemreview : replaced return value with null for edu/ucsb/cs156/example/controllers/MenuItemReviewController::postitemreview → KILLED
        return savedMenuItemReview;
105
    }
106
107
    /**
108
     * Delete a MenuItemReview
109
     * 
110
     * @param id the id of the review to delete
111
     * @return a message indicating the review was deleted
112
     */
113
    @Operation(summary= "Delete a MenuItemReview")
114
    @PreAuthorize("hasRole('ROLE_ADMIN')")
115
    @DeleteMapping("")
116
    public Object deleteMenuItemReview(
117
            @Parameter(name="id") @RequestParam Long id) {
118
        MenuItemReview menuItemReview = menuItemReviewRepository.findById(id)
119 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));
120
121 1 1. deleteMenuItemReview : removed call to edu/ucsb/cs156/example/repositories/MenuItemReviewRepository::delete → KILLED
        menuItemReviewRepository.delete(menuItemReview);
122 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));
123
    }
124
    
125
    /**
126
     * Update a single review
127
     * 
128
     * @param id       id of the review to update
129
     * @param incoming the new review
130
     * @return the updated review object
131
     */
132
    @Operation(summary= "Update a single review")
133
    @PreAuthorize("hasRole('ROLE_ADMIN')")
134
    @PutMapping("")
135
    public MenuItemReview updateMenuItemReview(
136
            @Parameter(name="id") @RequestParam Long id,
137
            @RequestBody @Valid MenuItemReview incoming) {
138
139
        MenuItemReview menuItemReview = menuItemReviewRepository.findById(id)
140 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));
141 1 1. updateMenuItemReview : removed call to edu/ucsb/cs156/example/entities/MenuItemReview::setReviewerEmail → KILLED
        menuItemReview.setReviewerEmail(incoming.getReviewerEmail());
142 1 1. updateMenuItemReview : removed call to edu/ucsb/cs156/example/entities/MenuItemReview::setStars → KILLED
        menuItemReview.setStars(incoming.getStars());
143 1 1. updateMenuItemReview : removed call to edu/ucsb/cs156/example/entities/MenuItemReview::setComments → KILLED
        menuItemReview.setComments(incoming.getComments());
144 1 1. updateMenuItemReview : removed call to edu/ucsb/cs156/example/entities/MenuItemReview::setDateReviewed → KILLED
        menuItemReview.setDateReviewed(incoming.getDateReviewed());
145
        
146
147
        menuItemReviewRepository.save(menuItemReview);
148
149 1 1. updateMenuItemReview : replaced return value with null for edu/ucsb/cs156/example/controllers/MenuItemReviewController::updateMenuItemReview → KILLED
        return menuItemReview;
150
    }
151
}

Mutations

60

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

75

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

77

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

97

1.1
Location : postitemreview
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

98

1.1
Location : postitemreview
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

99

1.1
Location : postitemreview
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

100

1.1
Location : postitemreview
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

104

1.1
Location : postitemreview
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::postitemreview → KILLED

119

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

121

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

122

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

140

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

141

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

142

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

143

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

144

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

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