| 1 | package edu.ucsb.cs156.gauchoride.controllers; | |
| 2 | ||
| 3 | import edu.ucsb.cs156.gauchoride.entities.RiderApplication; | |
| 4 | import edu.ucsb.cs156.gauchoride.errors.EntityNotFoundException; | |
| 5 | import edu.ucsb.cs156.gauchoride.repositories.RiderApplicationRepository; | |
| 6 | import com.fasterxml.jackson.databind.ObjectMapper; | |
| 7 | ||
| 8 | import io.swagger.v3.oas.annotations.tags.Tag; | |
| 9 | import io.swagger.v3.oas.annotations.Operation; | |
| 10 | import io.swagger.v3.oas.annotations.Parameter; | |
| 11 | ||
| 12 | import com.fasterxml.jackson.core.JsonProcessingException; | |
| 13 | ||
| 14 | import org.springframework.beans.factory.annotation.Autowired; | |
| 15 | import org.springframework.security.access.prepost.PreAuthorize; | |
| 16 | import org.springframework.security.core.authority.SimpleGrantedAuthority; | |
| 17 | import org.springframework.security.oauth2.jwt.NimbusReactiveJwtDecoder.SecretKeyReactiveJwtDecoderBuilder; | |
| 18 | import org.springframework.http.ResponseEntity; | |
| 19 | import org.springframework.web.bind.annotation.DeleteMapping; | |
| 20 | import org.springframework.web.bind.annotation.GetMapping; | |
| 21 | import org.springframework.web.bind.annotation.PostMapping; | |
| 22 | import org.springframework.web.bind.annotation.PutMapping; | |
| 23 | import org.springframework.web.bind.annotation.RequestBody; | |
| 24 | import org.springframework.web.bind.annotation.RequestMapping; | |
| 25 | import org.springframework.web.bind.annotation.RequestParam; | |
| 26 | import org.springframework.web.bind.annotation.RestController; | |
| 27 | ||
| 28 | import java.util.Date; | |
| 29 | import java.text.SimpleDateFormat; | |
| 30 | import java.text.DateFormat; | |
| 31 | import java.util.Calendar; | |
| 32 | import java.text.ParseException; | |
| 33 | ||
| 34 | import javax.validation.Valid; | |
| 35 | ||
| 36 | ||
| 37 | @Tag(name = "Rider Application") | |
| 38 | @RequestMapping("/api/riderapplication") | |
| 39 | @RestController | |
| 40 | public class RiderApplicationController extends ApiController { | |
| 41 | @Autowired | |
| 42 | RiderApplicationRepository riderApplicationRepository; | |
| 43 | ||
| 44 | @Autowired | |
| 45 | ObjectMapper mapper; | |
| 46 | ||
| 47 | | |
| 48 | ||
| 49 | @Operation(summary = "Creates a new application") | |
| 50 | @PreAuthorize("hasRole('ROLE_MEMBER')") | |
| 51 | @PostMapping("/new") | |
| 52 | public RiderApplication newRiderApplication( | |
| 53 | | |
| 54 | @Parameter(name="perm_number") @RequestParam String perm_number, | |
| 55 | | |
| 56 | @Parameter(name="description") @RequestParam String description | |
| 57 | ) | |
| 58 | { | |
| 59 | | |
| 60 | long milli = 60 * 60 * 24 * 1000; | |
| 61 | long currentTime = new Date().getTime(); | |
| 62 |
2
1. newRiderApplication : Replaced long division with multiplication → KILLED 2. newRiderApplication : Replaced long multiplication with division → KILLED |
long dateOnly = (currentTime / milli) * milli; |
| 63 | ||
| 64 | Date date = new Date(dateOnly); | |
| 65 | ||
| 66 | ||
| 67 | RiderApplication riderApplication = new RiderApplication(); | |
| 68 |
1
1. newRiderApplication : removed call to edu/ucsb/cs156/gauchoride/entities/RiderApplication::setUserId → KILLED |
riderApplication.setUserId(getCurrentUser().getUser().getId()); |
| 69 | | |
| 70 |
1
1. newRiderApplication : removed call to edu/ucsb/cs156/gauchoride/entities/RiderApplication::setPerm_number → KILLED |
riderApplication.setPerm_number(perm_number); |
| 71 |
1
1. newRiderApplication : removed call to edu/ucsb/cs156/gauchoride/entities/RiderApplication::setCreated_date → KILLED |
riderApplication.setCreated_date(date); |
| 72 |
1
1. newRiderApplication : removed call to edu/ucsb/cs156/gauchoride/entities/RiderApplication::setDescription → KILLED |
riderApplication.setDescription(description); |
| 73 | | |
| 74 | RiderApplication savedRiderApplication = riderApplicationRepository.save(riderApplication); | |
| 75 | ||
| 76 |
1
1. newRiderApplication : replaced return value with null for edu/ucsb/cs156/gauchoride/controllers/RiderApplicationController::newRiderApplication → KILLED |
return savedRiderApplication; |
| 77 | ||
| 78 | } | |
| 79 | ||
| 80 | @Operation(summary = "Gets a list of all rider request owned by current user") | |
| 81 | @PreAuthorize("hasRole('ROLE_MEMBER')") | |
| 82 | @GetMapping("/all") | |
| 83 | public ResponseEntity<String> riderRequests() | |
| 84 | throws JsonProcessingException { | |
| 85 | Long userId = super.getCurrentUser().getUser().getId(); | |
| 86 | Iterable<RiderApplication> riderApplications = riderApplicationRepository.findByUserId(userId); | |
| 87 | String body = mapper.writeValueAsString(riderApplications); | |
| 88 |
1
1. riderRequests : replaced return value with null for edu/ucsb/cs156/gauchoride/controllers/RiderApplicationController::riderRequests → KILLED |
return ResponseEntity.ok().body(body); |
| 89 | ||
| 90 | } | |
| 91 | ||
| 92 | @Operation(summary = "Gets a personal rider request by id") | |
| 93 | @PreAuthorize("hasRole('ROLE_MEMBER')") | |
| 94 | @GetMapping("/get") | |
| 95 | public RiderApplication riderApplicationID( | |
| 96 | @Parameter(name = "id", description = "Long, id number ride to get ", example = "1", required = true) @RequestParam Long id) | |
| 97 | throws JsonProcessingException { | |
| 98 | RiderApplication riderApplication = riderApplicationRepository.findByIdAndUserId(id, getCurrentUser().getUser().getId()) | |
| 99 |
1
1. lambda$riderApplicationID$0 : replaced return value with null for edu/ucsb/cs156/gauchoride/controllers/RiderApplicationController::lambda$riderApplicationID$0 → KILLED |
.orElseThrow(() -> new EntityNotFoundException(RiderApplication.class, id)); |
| 100 |
1
1. riderApplicationID : replaced return value with null for edu/ucsb/cs156/gauchoride/controllers/RiderApplicationController::riderApplicationID → KILLED |
return riderApplication; |
| 101 | } | |
| 102 | ||
| 103 | @Operation(summary = "Update a personal application") | |
| 104 | @PreAuthorize("hasRole('ROLE_MEMBER')") | |
| 105 | @PutMapping("put") | |
| 106 | public RiderApplication updatePersonalApplication(@Parameter(name = "id", description = "Long, id number ride to get ", example = "1", required = true) @RequestParam long id, | |
| 107 | @RequestBody @Valid RiderApplication incoming | |
| 108 | ){ | |
| 109 | RiderApplication riderApplication = riderApplicationRepository.findByIdAndUserId(id, getCurrentUser().getUser().getId()) | |
| 110 |
1
1. lambda$updatePersonalApplication$1 : replaced return value with null for edu/ucsb/cs156/gauchoride/controllers/RiderApplicationController::lambda$updatePersonalApplication$1 → KILLED |
.orElseThrow(() -> new EntityNotFoundException(RiderApplication.class, id)); |
| 111 | ||
| 112 | long milli = 60 * 60 * 24 * 1000; | |
| 113 | long currentTime = new Date().getTime(); | |
| 114 |
2
1. updatePersonalApplication : Replaced long division with multiplication → KILLED 2. updatePersonalApplication : Replaced long multiplication with division → KILLED |
long dateOnly = (currentTime / milli) * milli; |
| 115 | ||
| 116 | Date date = new Date(dateOnly); | |
| 117 | ||
| 118 |
1
1. updatePersonalApplication : removed call to edu/ucsb/cs156/gauchoride/entities/RiderApplication::setUpdated_date → KILLED |
riderApplication.setUpdated_date(date); |
| 119 |
1
1. updatePersonalApplication : removed call to edu/ucsb/cs156/gauchoride/entities/RiderApplication::setPerm_number → KILLED |
riderApplication.setPerm_number(incoming.getPerm_number()); |
| 120 |
1
1. updatePersonalApplication : removed call to edu/ucsb/cs156/gauchoride/entities/RiderApplication::setDescription → KILLED |
riderApplication.setDescription(incoming.getDescription()); |
| 121 | ||
| 122 | riderApplicationRepository.save(riderApplication); | |
| 123 | ||
| 124 |
1
1. updatePersonalApplication : replaced return value with null for edu/ucsb/cs156/gauchoride/controllers/RiderApplicationController::updatePersonalApplication → KILLED |
return riderApplication; |
| 125 | } | |
| 126 | ||
| 127 | | |
| 128 | @Operation(summary = "Cancel a personal review") | |
| 129 | @PreAuthorize("hasRole('ROLE_MEMBER')") | |
| 130 | @PutMapping("/cancel") | |
| 131 | public RiderApplication cancelRiderApplication( | |
| 132 | @Parameter(name = "id", description = "Long, id number ride to get ", example = "1", required = true) @RequestParam long id, | |
| 133 | @RequestBody @Valid RiderApplication incoming | |
| 134 | ) { | |
| 135 | RiderApplication riderApplication = riderApplicationRepository.findByIdAndUserId(id, getCurrentUser().getUser().getId()) | |
| 136 |
1
1. lambda$cancelRiderApplication$2 : replaced return value with null for edu/ucsb/cs156/gauchoride/controllers/RiderApplicationController::lambda$cancelRiderApplication$2 → KILLED |
.orElseThrow(() -> new EntityNotFoundException(RiderApplication.class, id)); |
| 137 | ||
| 138 |
1
1. cancelRiderApplication : negated conditional → KILLED |
if(incoming.getStatus() != "cancelled"){ |
| 139 | long milli = 60 * 60 * 24 * 1000; | |
| 140 | long currentTime = new Date().getTime(); | |
| 141 |
2
1. cancelRiderApplication : Replaced long division with multiplication → KILLED 2. cancelRiderApplication : Replaced long multiplication with division → KILLED |
long dateOnly = (currentTime / milli) * milli; |
| 142 | ||
| 143 | Date date = new Date(dateOnly); | |
| 144 |
1
1. cancelRiderApplication : removed call to edu/ucsb/cs156/gauchoride/entities/RiderApplication::setUpdated_date → KILLED |
riderApplication.setUpdated_date(date); |
| 145 |
1
1. cancelRiderApplication : removed call to edu/ucsb/cs156/gauchoride/entities/RiderApplication::setStatus → KILLED |
riderApplication.setStatus("cancelled"); |
| 146 |
1
1. cancelRiderApplication : removed call to edu/ucsb/cs156/gauchoride/entities/RiderApplication::setCancelled_date → KILLED |
riderApplication.setCancelled_date(date); |
| 147 | riderApplicationRepository.save(riderApplication); | |
| 148 |
1
1. cancelRiderApplication : replaced return value with null for edu/ucsb/cs156/gauchoride/controllers/RiderApplicationController::cancelRiderApplication → KILLED |
return riderApplication; |
| 149 | ||
| 150 | ||
| 151 | }else{ | |
| 152 | throw new EntityNotFoundException(RiderApplication.class, id); | |
| 153 | | |
| 154 | } | |
| 155 | | |
| 156 | | |
| 157 | } | |
| 158 | ||
| 159 | @Operation(summary = "Gets all Rider Requests") | |
| 160 | @PreAuthorize("hasRole('ROLE_ADMIN')") | |
| 161 | @GetMapping("/admin/all") | |
| 162 | public ResponseEntity<String> allRequests() | |
| 163 | throws JsonProcessingException { | |
| 164 | Iterable<RiderApplication> riderApplications = riderApplicationRepository.findAll(); | |
| 165 | String body = mapper.writeValueAsString(riderApplications); | |
| 166 |
1
1. allRequests : replaced return value with null for edu/ucsb/cs156/gauchoride/controllers/RiderApplicationController::allRequests → KILLED |
return ResponseEntity.ok().body(body); |
| 167 | } | |
| 168 | ||
| 169 | @Operation(summary = "Gets all pending requests") | |
| 170 | @PreAuthorize("hasRole('ROLE_ADMIN')") | |
| 171 | @GetMapping("/admin/pending") | |
| 172 | public ResponseEntity<String> allPendingRequests() | |
| 173 | throws JsonProcessingException { | |
| 174 | Iterable<RiderApplication> riderApplications = riderApplicationRepository.findByStatus("pending"); | |
| 175 | String body = mapper.writeValueAsString(riderApplications); | |
| 176 |
1
1. allPendingRequests : replaced return value with null for edu/ucsb/cs156/gauchoride/controllers/RiderApplicationController::allPendingRequests → KILLED |
return ResponseEntity.ok().body(body); |
| 177 | } | |
| 178 | ||
| 179 | @Operation(summary = "Gets specific rider application by id") | |
| 180 | @PreAuthorize("hasRole('ROLE_ADMIN')") | |
| 181 | @GetMapping("/admin/get") | |
| 182 | public RiderApplication riderApplicationId( | |
| 183 | @Parameter(name = "id", description = "Long, id number ride to get ", example = "1", required = true) @RequestParam Long id) | |
| 184 | throws JsonProcessingException { | |
| 185 | RiderApplication riderApplication = riderApplicationRepository.findById(id) | |
| 186 |
1
1. lambda$riderApplicationId$3 : replaced return value with null for edu/ucsb/cs156/gauchoride/controllers/RiderApplicationController::lambda$riderApplicationId$3 → KILLED |
.orElseThrow(() -> new EntityNotFoundException(RiderApplication.class, id)); |
| 187 |
1
1. riderApplicationId : replaced return value with null for edu/ucsb/cs156/gauchoride/controllers/RiderApplicationController::riderApplicationId → KILLED |
return riderApplication; |
| 188 | } | |
| 189 | ||
| 190 | @Operation(summary = "Update a rider Application") | |
| 191 | @PreAuthorize("hasRole('ROLE_ADMIN')") | |
| 192 | @PutMapping("/admin") | |
| 193 | public RiderApplication editRiderApplication( | |
| 194 | @Parameter(name = "id", description = "Long, id number ride to get ", example = "1", required = true) @RequestParam long id, | |
| 195 | @RequestBody @Valid RiderApplication incoming | |
| 196 | ){ | |
| 197 | RiderApplication riderApplication = riderApplicationRepository.findById(id) | |
| 198 |
1
1. lambda$editRiderApplication$4 : replaced return value with null for edu/ucsb/cs156/gauchoride/controllers/RiderApplicationController::lambda$editRiderApplication$4 → KILLED |
.orElseThrow(() -> new EntityNotFoundException(RiderApplication.class, id)); |
| 199 | long milli = 60 * 60 * 24 * 1000; | |
| 200 | long currentTime = new Date().getTime(); | |
| 201 |
2
1. editRiderApplication : Replaced long division with multiplication → KILLED 2. editRiderApplication : Replaced long multiplication with division → KILLED |
long dateOnly = (currentTime / milli) * milli; |
| 202 | Date date = new Date(dateOnly); | |
| 203 | ||
| 204 |
1
1. editRiderApplication : removed call to edu/ucsb/cs156/gauchoride/entities/RiderApplication::setUpdated_date → KILLED |
riderApplication.setUpdated_date(date); |
| 205 |
1
1. editRiderApplication : removed call to edu/ucsb/cs156/gauchoride/entities/RiderApplication::setNotes → KILLED |
riderApplication.setNotes(incoming.getNotes()); |
| 206 |
1
1. editRiderApplication : removed call to edu/ucsb/cs156/gauchoride/entities/RiderApplication::setStatus → KILLED |
riderApplication.setStatus(incoming.getStatus()); |
| 207 | riderApplicationRepository.save(riderApplication); | |
| 208 |
1
1. editRiderApplication : replaced return value with null for edu/ucsb/cs156/gauchoride/controllers/RiderApplicationController::editRiderApplication → KILLED |
return riderApplication; |
| 209 | ||
| 210 | } | |
| 211 | ||
| 212 | ||
| 213 | ||
| 214 | } | |
Mutations | ||
| 62 |
1.1 2.2 |
|
| 68 |
1.1 |
|
| 70 |
1.1 |
|
| 71 |
1.1 |
|
| 72 |
1.1 |
|
| 76 |
1.1 |
|
| 88 |
1.1 |
|
| 99 |
1.1 |
|
| 100 |
1.1 |
|
| 110 |
1.1 |
|
| 114 |
1.1 2.2 |
|
| 118 |
1.1 |
|
| 119 |
1.1 |
|
| 120 |
1.1 |
|
| 124 |
1.1 |
|
| 136 |
1.1 |
|
| 138 |
1.1 |
|
| 141 |
1.1 2.2 |
|
| 144 |
1.1 |
|
| 145 |
1.1 |
|
| 146 |
1.1 |
|
| 148 |
1.1 |
|
| 166 |
1.1 |
|
| 176 |
1.1 |
|
| 186 |
1.1 |
|
| 187 |
1.1 |
|
| 198 |
1.1 |
|
| 201 |
1.1 2.2 |
|
| 204 |
1.1 |
|
| 205 |
1.1 |
|
| 206 |
1.1 |
|
| 208 |
1.1 |