1 | package edu.ucsb.cs156.example.controllers; | |
2 | ||
3 | import edu.ucsb.cs156.example.entities.Help; | |
4 | import edu.ucsb.cs156.example.errors.EntityNotFoundException; | |
5 | import edu.ucsb.cs156.example.repositories.HelpRepository; | |
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 com.fasterxml.jackson.core.JsonProcessingException; | |
13 | ||
14 | import org.springframework.beans.factory.annotation.Autowired; | |
15 | import org.springframework.format.annotation.DateTimeFormat; | |
16 | import org.springframework.security.access.prepost.PreAuthorize; | |
17 | import org.springframework.web.bind.annotation.DeleteMapping; | |
18 | import org.springframework.web.bind.annotation.GetMapping; | |
19 | import org.springframework.web.bind.annotation.PostMapping; | |
20 | import org.springframework.web.bind.annotation.PutMapping; | |
21 | import org.springframework.web.bind.annotation.RequestBody; | |
22 | import org.springframework.web.bind.annotation.RequestMapping; | |
23 | import org.springframework.web.bind.annotation.RequestParam; | |
24 | import org.springframework.web.bind.annotation.RestController; | |
25 | ||
26 | import javax.validation.Valid; | |
27 | ||
28 | import java.time.LocalDateTime; | |
29 | ||
30 | @Tag(name = "Help") | |
31 | @RequestMapping("/api/help") | |
32 | @RestController | |
33 | @Slf4j | |
34 | public class HelpController extends ApiController { | |
35 | ||
36 | @Autowired | |
37 | HelpRepository helpRepository; | |
38 | ||
39 | @Operation(summary= "List help requests") | |
40 | @PreAuthorize("hasRole('ROLE_USER')") | |
41 | @GetMapping("/all") | |
42 | public Iterable<Help> allHelp() { | |
43 | Iterable<Help> requests = helpRepository.findAll(); | |
44 |
1
1. allHelp : replaced return value with null for edu/ucsb/cs156/example/controllers/HelpController::allHelp → KILLED |
return requests; |
45 | } | |
46 | ||
47 | @Operation(summary= "Create a new help request") | |
48 | @PreAuthorize("hasRole('ROLE_ADMIN')") | |
49 | @PostMapping("/post") | |
50 | public Help postHelp( | |
51 | @Parameter(name="requesterEmail") @RequestParam String requesterEmail, | |
52 | @Parameter(name="teamId") @RequestParam String teamId, | |
53 | @Parameter(name="tableOrBreakoutRoom") @RequestParam String tableOrBreakoutRoom, | |
54 | @Parameter(name="requestTime") @RequestParam("requestTime") @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME) LocalDateTime requestTime, | |
55 | @Parameter(name="explanation") @RequestParam String explanation, | |
56 | @Parameter(name="solved") @RequestParam boolean solved) | |
57 | throws JsonProcessingException { | |
58 | ||
59 | // For an explanation of @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME) | |
60 | // See: https://www.baeldung.com/spring-date-parameters | |
61 | ||
62 | log.info("requestTime={}", requestTime); | |
63 | ||
64 | Help help = new Help(); | |
65 |
1
1. postHelp : removed call to edu/ucsb/cs156/example/entities/Help::setRequesterEmail → KILLED |
help.setRequesterEmail(requesterEmail); |
66 |
1
1. postHelp : removed call to edu/ucsb/cs156/example/entities/Help::setTeamId → KILLED |
help.setTeamId(teamId); |
67 |
1
1. postHelp : removed call to edu/ucsb/cs156/example/entities/Help::setTableOrBreakoutRoom → KILLED |
help.setTableOrBreakoutRoom(tableOrBreakoutRoom); |
68 |
1
1. postHelp : removed call to edu/ucsb/cs156/example/entities/Help::setRequestTime → KILLED |
help.setRequestTime(requestTime); |
69 |
1
1. postHelp : removed call to edu/ucsb/cs156/example/entities/Help::setExplanation → KILLED |
help.setExplanation(explanation); |
70 |
1
1. postHelp : removed call to edu/ucsb/cs156/example/entities/Help::setSolved → KILLED |
help.setSolved(solved); |
71 | ||
72 | ||
73 | ||
74 | Help savedHelp = helpRepository.save(help); | |
75 | ||
76 |
1
1. postHelp : replaced return value with null for edu/ucsb/cs156/example/controllers/HelpController::postHelp → KILLED |
return savedHelp; |
77 | } | |
78 | ||
79 | @Operation(summary= "Get a single help request") | |
80 | @PreAuthorize("hasRole('ROLE_USER')") | |
81 | @GetMapping("") | |
82 | public Help getById( | |
83 | @Parameter(name="id") @RequestParam Long id) { | |
84 | Help help = helpRepository.findById(id) | |
85 |
1
1. lambda$getById$0 : replaced return value with null for edu/ucsb/cs156/example/controllers/HelpController::lambda$getById$0 → KILLED |
.orElseThrow(() -> new EntityNotFoundException(Help.class, id)); |
86 | ||
87 |
1
1. getById : replaced return value with null for edu/ucsb/cs156/example/controllers/HelpController::getById → KILLED |
return help; |
88 | } | |
89 | ||
90 | @Operation(summary= "Delete a help request") | |
91 | @PreAuthorize("hasRole('ROLE_ADMIN')") | |
92 | @DeleteMapping("") | |
93 | public Object deleteHelp( | |
94 | @Parameter(name="id") @RequestParam Long id) { | |
95 | Help help = helpRepository.findById(id) | |
96 |
1
1. lambda$deleteHelp$1 : replaced return value with null for edu/ucsb/cs156/example/controllers/HelpController::lambda$deleteHelp$1 → KILLED |
.orElseThrow(() -> new EntityNotFoundException(Help.class, id)); |
97 | ||
98 |
1
1. deleteHelp : removed call to edu/ucsb/cs156/example/repositories/HelpRepository::delete → KILLED |
helpRepository.delete(help); |
99 |
1
1. deleteHelp : replaced return value with null for edu/ucsb/cs156/example/controllers/HelpController::deleteHelp → KILLED |
return genericMessage("Help request with id %s deleted".formatted(id)); |
100 | } | |
101 | ||
102 | @Operation(summary= "Update a single help request") | |
103 | @PreAuthorize("hasRole('ROLE_ADMIN')") | |
104 | @PutMapping("") | |
105 | public Help updateHelp( | |
106 | @Parameter(name="id") @RequestParam Long id, | |
107 | @RequestBody @Valid Help incoming) { | |
108 | ||
109 | Help help = helpRepository.findById(id) | |
110 |
1
1. lambda$updateHelp$2 : replaced return value with null for edu/ucsb/cs156/example/controllers/HelpController::lambda$updateHelp$2 → KILLED |
.orElseThrow(() -> new EntityNotFoundException(Help.class, id)); |
111 | ||
112 |
1
1. updateHelp : removed call to edu/ucsb/cs156/example/entities/Help::setRequesterEmail → KILLED |
help.setRequesterEmail(incoming.getRequesterEmail()); |
113 |
1
1. updateHelp : removed call to edu/ucsb/cs156/example/entities/Help::setTeamId → KILLED |
help.setTeamId(incoming.getTeamId()); |
114 |
1
1. updateHelp : removed call to edu/ucsb/cs156/example/entities/Help::setTableOrBreakoutRoom → KILLED |
help.setTableOrBreakoutRoom(incoming.getTableOrBreakoutRoom()); |
115 |
1
1. updateHelp : removed call to edu/ucsb/cs156/example/entities/Help::setRequestTime → KILLED |
help.setRequestTime(incoming.getRequestTime()); |
116 |
1
1. updateHelp : removed call to edu/ucsb/cs156/example/entities/Help::setExplanation → KILLED |
help.setExplanation(incoming.getExplanation()); |
117 |
1
1. updateHelp : removed call to edu/ucsb/cs156/example/entities/Help::setSolved → KILLED |
help.setSolved(incoming.getSolved()); |
118 | ||
119 | helpRepository.save(help); | |
120 | ||
121 |
1
1. updateHelp : replaced return value with null for edu/ucsb/cs156/example/controllers/HelpController::updateHelp → KILLED |
return help; |
122 | } | |
123 | } | |
Mutations | ||
44 |
1.1 |
|
65 |
1.1 |
|
66 |
1.1 |
|
67 |
1.1 |
|
68 |
1.1 |
|
69 |
1.1 |
|
70 |
1.1 |
|
76 |
1.1 |
|
85 |
1.1 |
|
87 |
1.1 |
|
96 |
1.1 |
|
98 |
1.1 |
|
99 |
1.1 |
|
110 |
1.1 |
|
112 |
1.1 |
|
113 |
1.1 |
|
114 |
1.1 |
|
115 |
1.1 |
|
116 |
1.1 |
|
117 |
1.1 |
|
121 |
1.1 |