UCSBDiningCommonsController.java

1
package edu.ucsb.cs156.example.controllers;
2
3
import edu.ucsb.cs156.example.entities.UCSBDiningCommons;
4
import edu.ucsb.cs156.example.errors.EntityNotFoundException;
5
import edu.ucsb.cs156.example.repositories.UCSBDiningCommonsRepository;
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 jakarta.validation.Valid;
10
import lombok.extern.slf4j.Slf4j;
11
import org.springframework.beans.factory.annotation.Autowired;
12
import org.springframework.security.access.prepost.PreAuthorize;
13
import org.springframework.web.bind.annotation.DeleteMapping;
14
import org.springframework.web.bind.annotation.GetMapping;
15
import org.springframework.web.bind.annotation.PostMapping;
16
import org.springframework.web.bind.annotation.PutMapping;
17
import org.springframework.web.bind.annotation.RequestBody;
18
import org.springframework.web.bind.annotation.RequestMapping;
19
import org.springframework.web.bind.annotation.RequestParam;
20
import org.springframework.web.bind.annotation.RestController;
21
22
/** This is a REST controller for UCSBDiningCommons */
23
@Tag(name = "UCSBDiningCommons")
24
@RequestMapping("/api/ucsbdiningcommons")
25
@RestController
26
@Slf4j
27
public class UCSBDiningCommonsController extends ApiController {
28
29
  @Autowired UCSBDiningCommonsRepository ucsbDiningCommonsRepository;
30
31
  /**
32
   * THis method returns a list of all ucsbdiningcommons.
33
   *
34
   * @return a list of all ucsbdiningcommons
35
   */
36
  @Operation(summary = "List all ucsb dining commons")
37
  @PreAuthorize("hasRole('ROLE_USER')")
38
  @GetMapping("/all")
39
  public Iterable<UCSBDiningCommons> allCommonss() {
40
    Iterable<UCSBDiningCommons> commons = ucsbDiningCommonsRepository.findAll();
41 1 1. allCommonss : replaced return value with Collections.emptyList for edu/ucsb/cs156/example/controllers/UCSBDiningCommonsController::allCommonss → KILLED
    return commons;
42
  }
43
44
  /**
45
   * This method returns a single diningcommons.
46
   *
47
   * @param code code of the diningcommons
48
   * @return a single diningcommons
49
   */
50
  @Operation(summary = "Get a single commons")
51
  @PreAuthorize("hasRole('ROLE_USER')")
52
  @GetMapping("")
53
  public UCSBDiningCommons getById(@Parameter(name = "code") @RequestParam String code) {
54
    UCSBDiningCommons commons =
55
        ucsbDiningCommonsRepository
56
            .findById(code)
57 1 1. lambda$getById$0 : replaced return value with null for edu/ucsb/cs156/example/controllers/UCSBDiningCommonsController::lambda$getById$0 → KILLED
            .orElseThrow(() -> new EntityNotFoundException(UCSBDiningCommons.class, code));
58
59 1 1. getById : replaced return value with null for edu/ucsb/cs156/example/controllers/UCSBDiningCommonsController::getById → KILLED
    return commons;
60
  }
61
62
  /**
63
   * This method creates a new diningcommons. Accessible only to users with the role "ROLE_ADMIN".
64
   *
65
   * @param code code of the diningcommons
66
   * @param name name of the diningcommons
67
   * @param hasSackMeal whether or not the commons has sack meals
68
   * @param hasTakeOutMeal whether or not the commons has take out meals
69
   * @param hasDiningCam whether or not the commons has a dining cam
70
   * @param latitude latitude of the commons
71
   * @param longitude logitude of the commons
72
   * @return the save diningcommons
73
   */
74
  @Operation(summary = "Create a new commons")
75
  @PreAuthorize("hasRole('ROLE_ADMIN')")
76
  @PostMapping("/post")
77
  public UCSBDiningCommons postCommons(
78
      @Parameter(name = "code") @RequestParam String code,
79
      @Parameter(name = "name") @RequestParam String name,
80
      @Parameter(name = "hasSackMeal") @RequestParam boolean hasSackMeal,
81
      @Parameter(name = "hasTakeOutMeal") @RequestParam boolean hasTakeOutMeal,
82
      @Parameter(name = "hasDiningCam") @RequestParam boolean hasDiningCam,
83
      @Parameter(name = "latitude") @RequestParam double latitude,
84
      @Parameter(name = "longitude") @RequestParam double longitude) {
85
86
    UCSBDiningCommons commons = new UCSBDiningCommons();
87 1 1. postCommons : removed call to edu/ucsb/cs156/example/entities/UCSBDiningCommons::setCode → KILLED
    commons.setCode(code);
88 1 1. postCommons : removed call to edu/ucsb/cs156/example/entities/UCSBDiningCommons::setName → KILLED
    commons.setName(name);
89 1 1. postCommons : removed call to edu/ucsb/cs156/example/entities/UCSBDiningCommons::setHasSackMeal → KILLED
    commons.setHasSackMeal(hasSackMeal);
90 1 1. postCommons : removed call to edu/ucsb/cs156/example/entities/UCSBDiningCommons::setHasTakeOutMeal → KILLED
    commons.setHasTakeOutMeal(hasTakeOutMeal);
91 1 1. postCommons : removed call to edu/ucsb/cs156/example/entities/UCSBDiningCommons::setHasDiningCam → KILLED
    commons.setHasDiningCam(hasDiningCam);
92 1 1. postCommons : removed call to edu/ucsb/cs156/example/entities/UCSBDiningCommons::setLatitude → KILLED
    commons.setLatitude(latitude);
93 1 1. postCommons : removed call to edu/ucsb/cs156/example/entities/UCSBDiningCommons::setLongitude → KILLED
    commons.setLongitude(longitude);
94
95
    UCSBDiningCommons savedCommons = ucsbDiningCommonsRepository.save(commons);
96
97 1 1. postCommons : replaced return value with null for edu/ucsb/cs156/example/controllers/UCSBDiningCommonsController::postCommons → KILLED
    return savedCommons;
98
  }
99
100
  /**
101
   * Delete a diningcommons. Accessible only to users with the role "ROLE_ADMIN".
102
   *
103
   * @param code code of the commons
104
   * @return a message indiciating the commons was deleted
105
   */
106
  @Operation(summary = "Delete a UCSBDiningCommons")
107
  @PreAuthorize("hasRole('ROLE_ADMIN')")
108
  @DeleteMapping("")
109
  public Object deleteCommons(@Parameter(name = "code") @RequestParam String code) {
110
    UCSBDiningCommons commons =
111
        ucsbDiningCommonsRepository
112
            .findById(code)
113 1 1. lambda$deleteCommons$1 : replaced return value with null for edu/ucsb/cs156/example/controllers/UCSBDiningCommonsController::lambda$deleteCommons$1 → KILLED
            .orElseThrow(() -> new EntityNotFoundException(UCSBDiningCommons.class, code));
114
115 1 1. deleteCommons : removed call to edu/ucsb/cs156/example/repositories/UCSBDiningCommonsRepository::delete → KILLED
    ucsbDiningCommonsRepository.delete(commons);
116 1 1. deleteCommons : replaced return value with null for edu/ucsb/cs156/example/controllers/UCSBDiningCommonsController::deleteCommons → KILLED
    return genericMessage("UCSBDiningCommons with id %s deleted".formatted(code));
117
  }
118
119
  /**
120
   * Update a single diningcommons. Accessible only to users with the role "ROLE_ADMIN".
121
   *
122
   * @param code code of the diningcommons
123
   * @param incoming the new commons contents
124
   * @return the updated commons object
125
   */
126
  @Operation(summary = "Update a single commons")
127
  @PreAuthorize("hasRole('ROLE_ADMIN')")
128
  @PutMapping("")
129
  public UCSBDiningCommons updateCommons(
130
      @Parameter(name = "code") @RequestParam String code,
131
      @RequestBody @Valid UCSBDiningCommons incoming) {
132
133
    UCSBDiningCommons commons =
134
        ucsbDiningCommonsRepository
135
            .findById(code)
136 1 1. lambda$updateCommons$2 : replaced return value with null for edu/ucsb/cs156/example/controllers/UCSBDiningCommonsController::lambda$updateCommons$2 → KILLED
            .orElseThrow(() -> new EntityNotFoundException(UCSBDiningCommons.class, code));
137
138 1 1. updateCommons : removed call to edu/ucsb/cs156/example/entities/UCSBDiningCommons::setName → KILLED
    commons.setName(incoming.getName());
139 1 1. updateCommons : removed call to edu/ucsb/cs156/example/entities/UCSBDiningCommons::setHasSackMeal → KILLED
    commons.setHasSackMeal(incoming.getHasSackMeal());
140 1 1. updateCommons : removed call to edu/ucsb/cs156/example/entities/UCSBDiningCommons::setHasTakeOutMeal → KILLED
    commons.setHasTakeOutMeal(incoming.getHasTakeOutMeal());
141 1 1. updateCommons : removed call to edu/ucsb/cs156/example/entities/UCSBDiningCommons::setHasDiningCam → KILLED
    commons.setHasDiningCam(incoming.getHasDiningCam());
142 1 1. updateCommons : removed call to edu/ucsb/cs156/example/entities/UCSBDiningCommons::setLatitude → KILLED
    commons.setLatitude(incoming.getLatitude());
143 1 1. updateCommons : removed call to edu/ucsb/cs156/example/entities/UCSBDiningCommons::setLongitude → KILLED
    commons.setLongitude(incoming.getLongitude());
144
145
    ucsbDiningCommonsRepository.save(commons);
146
147 1 1. updateCommons : replaced return value with null for edu/ucsb/cs156/example/controllers/UCSBDiningCommonsController::updateCommons → KILLED
    return commons;
148
  }
149
}

Mutations

41

1.1
Location : allCommonss
Killed by : edu.ucsb.cs156.example.controllers.UCSBDiningCommonsControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.example.controllers.UCSBDiningCommonsControllerTests]/[method:logged_in_user_can_get_all_ucsbdiningcommons()]
replaced return value with Collections.emptyList for edu/ucsb/cs156/example/controllers/UCSBDiningCommonsController::allCommonss → KILLED

57

1.1
Location : lambda$getById$0
Killed by : edu.ucsb.cs156.example.controllers.UCSBDiningCommonsControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.example.controllers.UCSBDiningCommonsControllerTests]/[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/UCSBDiningCommonsController::lambda$getById$0 → KILLED

59

1.1
Location : getById
Killed by : edu.ucsb.cs156.example.controllers.UCSBDiningCommonsControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.example.controllers.UCSBDiningCommonsControllerTests]/[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/UCSBDiningCommonsController::getById → KILLED

87

1.1
Location : postCommons
Killed by : edu.ucsb.cs156.example.controllers.UCSBDiningCommonsControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.example.controllers.UCSBDiningCommonsControllerTests]/[method:an_admin_user_can_post_a_new_commons()]
removed call to edu/ucsb/cs156/example/entities/UCSBDiningCommons::setCode → KILLED

88

1.1
Location : postCommons
Killed by : edu.ucsb.cs156.example.controllers.UCSBDiningCommonsControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.example.controllers.UCSBDiningCommonsControllerTests]/[method:an_admin_user_can_post_a_new_commons()]
removed call to edu/ucsb/cs156/example/entities/UCSBDiningCommons::setName → KILLED

89

1.1
Location : postCommons
Killed by : edu.ucsb.cs156.example.controllers.UCSBDiningCommonsControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.example.controllers.UCSBDiningCommonsControllerTests]/[method:an_admin_user_can_post_a_new_commons()]
removed call to edu/ucsb/cs156/example/entities/UCSBDiningCommons::setHasSackMeal → KILLED

90

1.1
Location : postCommons
Killed by : edu.ucsb.cs156.example.controllers.UCSBDiningCommonsControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.example.controllers.UCSBDiningCommonsControllerTests]/[method:an_admin_user_can_post_a_new_commons()]
removed call to edu/ucsb/cs156/example/entities/UCSBDiningCommons::setHasTakeOutMeal → KILLED

91

1.1
Location : postCommons
Killed by : edu.ucsb.cs156.example.controllers.UCSBDiningCommonsControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.example.controllers.UCSBDiningCommonsControllerTests]/[method:an_admin_user_can_post_a_new_commons()]
removed call to edu/ucsb/cs156/example/entities/UCSBDiningCommons::setHasDiningCam → KILLED

92

1.1
Location : postCommons
Killed by : edu.ucsb.cs156.example.controllers.UCSBDiningCommonsControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.example.controllers.UCSBDiningCommonsControllerTests]/[method:an_admin_user_can_post_a_new_commons()]
removed call to edu/ucsb/cs156/example/entities/UCSBDiningCommons::setLatitude → KILLED

93

1.1
Location : postCommons
Killed by : edu.ucsb.cs156.example.controllers.UCSBDiningCommonsControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.example.controllers.UCSBDiningCommonsControllerTests]/[method:an_admin_user_can_post_a_new_commons()]
removed call to edu/ucsb/cs156/example/entities/UCSBDiningCommons::setLongitude → KILLED

97

1.1
Location : postCommons
Killed by : edu.ucsb.cs156.example.controllers.UCSBDiningCommonsControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.example.controllers.UCSBDiningCommonsControllerTests]/[method:an_admin_user_can_post_a_new_commons()]
replaced return value with null for edu/ucsb/cs156/example/controllers/UCSBDiningCommonsController::postCommons → KILLED

113

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

115

1.1
Location : deleteCommons
Killed by : edu.ucsb.cs156.example.controllers.UCSBDiningCommonsControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.example.controllers.UCSBDiningCommonsControllerTests]/[method:admin_can_delete_a_date()]
removed call to edu/ucsb/cs156/example/repositories/UCSBDiningCommonsRepository::delete → KILLED

116

1.1
Location : deleteCommons
Killed by : edu.ucsb.cs156.example.controllers.UCSBDiningCommonsControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.example.controllers.UCSBDiningCommonsControllerTests]/[method:admin_can_delete_a_date()]
replaced return value with null for edu/ucsb/cs156/example/controllers/UCSBDiningCommonsController::deleteCommons → KILLED

136

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

138

1.1
Location : updateCommons
Killed by : edu.ucsb.cs156.example.controllers.UCSBDiningCommonsControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.example.controllers.UCSBDiningCommonsControllerTests]/[method:admin_can_edit_an_existing_commons()]
removed call to edu/ucsb/cs156/example/entities/UCSBDiningCommons::setName → KILLED

139

1.1
Location : updateCommons
Killed by : edu.ucsb.cs156.example.controllers.UCSBDiningCommonsControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.example.controllers.UCSBDiningCommonsControllerTests]/[method:admin_can_edit_an_existing_commons()]
removed call to edu/ucsb/cs156/example/entities/UCSBDiningCommons::setHasSackMeal → KILLED

140

1.1
Location : updateCommons
Killed by : edu.ucsb.cs156.example.controllers.UCSBDiningCommonsControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.example.controllers.UCSBDiningCommonsControllerTests]/[method:admin_can_edit_an_existing_commons()]
removed call to edu/ucsb/cs156/example/entities/UCSBDiningCommons::setHasTakeOutMeal → KILLED

141

1.1
Location : updateCommons
Killed by : edu.ucsb.cs156.example.controllers.UCSBDiningCommonsControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.example.controllers.UCSBDiningCommonsControllerTests]/[method:admin_can_edit_an_existing_commons()]
removed call to edu/ucsb/cs156/example/entities/UCSBDiningCommons::setHasDiningCam → KILLED

142

1.1
Location : updateCommons
Killed by : edu.ucsb.cs156.example.controllers.UCSBDiningCommonsControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.example.controllers.UCSBDiningCommonsControllerTests]/[method:admin_can_edit_an_existing_commons()]
removed call to edu/ucsb/cs156/example/entities/UCSBDiningCommons::setLatitude → KILLED

143

1.1
Location : updateCommons
Killed by : edu.ucsb.cs156.example.controllers.UCSBDiningCommonsControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.example.controllers.UCSBDiningCommonsControllerTests]/[method:admin_can_edit_an_existing_commons()]
removed call to edu/ucsb/cs156/example/entities/UCSBDiningCommons::setLongitude → KILLED

147

1.1
Location : updateCommons
Killed by : edu.ucsb.cs156.example.controllers.UCSBDiningCommonsControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.example.controllers.UCSBDiningCommonsControllerTests]/[method:admin_can_edit_an_existing_commons()]
replaced return value with null for edu/ucsb/cs156/example/controllers/UCSBDiningCommonsController::updateCommons → KILLED

Active mutators

Tests examined


Report generated by PIT 1.17.0