| 1 | package edu.ucsb.cs156.dining.controllers; | |
| 2 | ||
| 3 | import edu.ucsb.cs156.dining.entities.CurrentUser; | |
| 4 | import edu.ucsb.cs156.dining.errors.EntityNotFoundException; | |
| 5 | import edu.ucsb.cs156.dining.repositories.CurrentUserRepository; | |
| 6 | ||
| 7 | import io.swagger.v3.oas.annotations.Operation; | |
| 8 | import io.swagger.v3.oas.annotations.Parameter; | |
| 9 | import io.swagger.v3.oas.annotations.tags.Tag; | |
| 10 | import lombok.extern.slf4j.Slf4j; | |
| 11 | ||
| 12 | import org.springframework.beans.factory.annotation.Autowired; | |
| 13 | import org.springframework.security.access.prepost.PreAuthorize; | |
| 14 | import org.springframework.web.bind.annotation.DeleteMapping; | |
| 15 | import org.springframework.web.bind.annotation.GetMapping; | |
| 16 | import org.springframework.web.bind.annotation.PostMapping; | |
| 17 | import org.springframework.web.bind.annotation.PutMapping; | |
| 18 | import org.springframework.web.bind.annotation.RequestBody; | |
| 19 | import org.springframework.web.bind.annotation.RequestMapping; | |
| 20 | import org.springframework.web.bind.annotation.RequestParam; | |
| 21 | import org.springframework.web.bind.annotation.RestController; | |
| 22 | ||
| 23 | import jakarta.validation.Valid; | |
| 24 | ||
| 25 | /** | |
| 26 | * This is a REST controller for CurrentUser | |
| 27 | */ | |
| 28 | ||
| 29 | @Tag(name = "CurrentUser") | |
| 30 | @RequestMapping("/api/currentuser") | |
| 31 | @RestController | |
| 32 | @Slf4j | |
| 33 | public class CurrentUserController extends ApiController { | |
| 34 | ||
| 35 | @Autowired | |
| 36 | CurrentUserRepository currentUserRepository; | |
| 37 | ||
| 38 | /** | |
| 39 | * This method creates a new user. Accessible only to user with the role "ROLE_USER". | |
| 40 | * @param alias alias of the user | |
| 41 | * @return the save user | |
| 42 | */ | |
| 43 | @Operation(summary= "Modify alias") | |
| 44 | @PreAuthorize("hasRole('ROLE_USER')") | |
| 45 | @PostMapping("/updateAlias") | |
| 46 | public CurrentUser postUser( | |
| 47 | @Parameter(name="alias") @RequestParam String alias, | |
| 48 | @Parameter(name="modValue") @RequestParam long modValue | |
| 49 | ) | |
| 50 | { | |
| 51 | ||
| 52 | CurrentUser users = new CurrentUser(); | |
| 53 |
1
1. postUser : removed call to edu/ucsb/cs156/dining/entities/CurrentUser::setAlias → KILLED |
users.setAlias(alias); |
| 54 |
1
1. postUser : removed call to edu/ucsb/cs156/dining/entities/CurrentUser::setModValue → KILLED |
users.setModValue(modValue); |
| 55 | ||
| 56 | CurrentUser savedCurrentUsers = currentUserRepository.save(users); | |
| 57 | ||
| 58 |
1
1. postUser : replaced return value with null for edu/ucsb/cs156/dining/controllers/CurrentUserController::postUser → KILLED |
return savedCurrentUsers; |
| 59 | } | |
| 60 | ||
| 61 | /** | |
| 62 | * Update a single users. Accessible only to users with the role "ROLE_ADMIN". | |
| 63 | * @param alias alias moderation value of the users | |
| 64 | * @param incoming the new users contents | |
| 65 | * @return the updated users object | |
| 66 | */ | |
| 67 | @Operation(summary= "Update alias moderation value") | |
| 68 | @PreAuthorize("hasRole('ROLE_ADMIN')") | |
| 69 | @PutMapping("/updateModValue") | |
| 70 | public CurrentUser updateModValue( | |
| 71 | @Parameter(name="alias") @RequestParam String alias, | |
| 72 | @RequestBody @Valid CurrentUser incoming) { | |
| 73 | ||
| 74 | CurrentUser users = currentUserRepository.findById(alias) | |
| 75 |
1
1. lambda$updateModValue$0 : replaced return value with null for edu/ucsb/cs156/dining/controllers/CurrentUserController::lambda$updateModValue$0 → KILLED |
.orElseThrow(() -> new EntityNotFoundException(CurrentUser.class, alias)); |
| 76 | ||
| 77 | ||
| 78 | //users.setAlias(incoming.getAlias()); | |
| 79 |
1
1. updateModValue : removed call to edu/ucsb/cs156/dining/entities/CurrentUser::setModValue → KILLED |
users.setModValue(incoming.getModValue()); |
| 80 | ||
| 81 | currentUserRepository.save(users); | |
| 82 | ||
| 83 |
1
1. updateModValue : replaced return value with null for edu/ucsb/cs156/dining/controllers/CurrentUserController::updateModValue → KILLED |
return users; |
| 84 | } | |
| 85 | } | |
Mutations | ||
| 53 |
1.1 |
|
| 54 |
1.1 |
|
| 58 |
1.1 |
|
| 75 |
1.1 |
|
| 79 |
1.1 |
|
| 83 |
1.1 |