1 | package edu.ucsb.cs156.example.controllers; | |
2 | ||
3 | import edu.ucsb.cs156.example.entities.Commit; | |
4 | import edu.ucsb.cs156.example.entities.UCSBDate; | |
5 | import edu.ucsb.cs156.example.errors.EntityNotFoundException; | |
6 | import edu.ucsb.cs156.example.repositories.CommitRepository; | |
7 | import edu.ucsb.cs156.example.repositories.UCSBDateRepository; | |
8 | ||
9 | import io.swagger.v3.oas.annotations.Operation; | |
10 | import io.swagger.v3.oas.annotations.Parameter; | |
11 | import io.swagger.v3.oas.annotations.tags.Tag; | |
12 | import lombok.extern.slf4j.Slf4j; | |
13 | ||
14 | import com.fasterxml.jackson.core.JsonProcessingException; | |
15 | ||
16 | import org.springframework.beans.factory.annotation.Autowired; | |
17 | import org.springframework.format.annotation.DateTimeFormat; | |
18 | import org.springframework.security.access.prepost.PreAuthorize; | |
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 jakarta.validation.Valid; | |
29 | ||
30 | import java.time.LocalDateTime; | |
31 | import java.time.ZonedDateTime; | |
32 | ||
33 | /** | |
34 | * This is a REST controller for Commits | |
35 | */ | |
36 | ||
37 | @Tag(name = "Commits") | |
38 | @RequestMapping("/api/commits") | |
39 | @RestController | |
40 | @Slf4j | |
41 | public class CommitsController extends ApiController { | |
42 | ||
43 | @Autowired | |
44 | CommitRepository commitRepository; | |
45 | ||
46 | /** | |
47 | * List all Commits | |
48 | * | |
49 | * @return an iterable of Commits | |
50 | */ | |
51 | @Operation(summary = "List all commits") | |
52 | @PreAuthorize("hasRole('ROLE_USER')") | |
53 | @GetMapping("/all") | |
54 | public Iterable<Commit> allCommits() { | |
55 | Iterable<Commit> commits = commitRepository.findAll(); | |
56 |
1
1. allCommits : replaced return value with Collections.emptyList for edu/ucsb/cs156/example/controllers/CommitsController::allCommits → KILLED |
return commits; |
57 | } | |
58 | ||
59 | /** | |
60 | * Create a new commit | |
61 | * | |
62 | * @param message the commit message | |
63 | * @param url the commit url | |
64 | * @param authorLogin the github login id of the user that authored the commit | |
65 | * @param commitTime the timestamp on the commit, with time zone information | |
66 | * @return the saved commit | |
67 | */ | |
68 | @Operation(summary = "Create a new commit") | |
69 | @PreAuthorize("hasRole('ROLE_ADMIN')") | |
70 | @PostMapping("/post") | |
71 | public Commit postCommit( | |
72 | @Parameter(name = "message") @RequestParam String message, | |
73 | @Parameter(name = "url") @RequestParam String url, | |
74 | @Parameter(name = "authorLogin") @RequestParam String authorLogin, | |
75 | @Parameter(name = "commitTime") @RequestParam("commitTime") @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME) ZonedDateTime commitTime) | |
76 | throws JsonProcessingException { | |
77 | ||
78 | // For an explanation of @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME) | |
79 | // See: https://www.baeldung.com/spring-date-parameters | |
80 | ||
81 | log.info("commitTime={}", commitTime); | |
82 | ||
83 | Commit commit = new Commit(); | |
84 |
1
1. postCommit : removed call to edu/ucsb/cs156/example/entities/Commit::setMessage → KILLED |
commit.setMessage(message); |
85 |
1
1. postCommit : removed call to edu/ucsb/cs156/example/entities/Commit::setUrl → KILLED |
commit.setUrl(url); |
86 |
1
1. postCommit : removed call to edu/ucsb/cs156/example/entities/Commit::setAuthorLogin → KILLED |
commit.setAuthorLogin(authorLogin); |
87 |
1
1. postCommit : removed call to edu/ucsb/cs156/example/entities/Commit::setCommitTime → KILLED |
commit.setCommitTime(commitTime); |
88 | ||
89 | Commit savedCommit = commitRepository.save(commit); | |
90 | ||
91 |
1
1. postCommit : replaced return value with null for edu/ucsb/cs156/example/controllers/CommitsController::postCommit → KILLED |
return savedCommit; |
92 | } | |
93 | ||
94 | /** | |
95 | * Get a single commit by id | |
96 | * | |
97 | * @param id the id of the commit | |
98 | * @return a Commit | |
99 | */ | |
100 | @Operation(summary = "Get a single commit") | |
101 | @PreAuthorize("hasRole('ROLE_USER')") | |
102 | @GetMapping("") | |
103 | public Commit getById( | |
104 | @Parameter(name = "id") @RequestParam Long id) { | |
105 | Commit commit = commitRepository.findById(id) | |
106 |
1
1. lambda$getById$0 : replaced return value with null for edu/ucsb/cs156/example/controllers/CommitsController::lambda$getById$0 → KILLED |
.orElseThrow(() -> new EntityNotFoundException(Commit.class, id)); |
107 | ||
108 |
1
1. getById : replaced return value with null for edu/ucsb/cs156/example/controllers/CommitsController::getById → KILLED |
return commit; |
109 | } | |
110 | ||
111 | /** | |
112 | * Update a single commit | |
113 | * | |
114 | * @param id id of the commit to update | |
115 | * @param incoming the new commit | |
116 | * @return the updated commit object | |
117 | */ | |
118 | @Operation(summary = "Update a single commit") | |
119 | @PreAuthorize("hasRole('ROLE_ADMIN')") | |
120 | @PutMapping("") | |
121 | public Commit updateCommit( | |
122 | @Parameter(name = "id") @RequestParam Long id, | |
123 | @RequestBody @Valid Commit incoming) { | |
124 | ||
125 | Commit commit = commitRepository.findById(id) | |
126 |
1
1. lambda$updateCommit$1 : replaced return value with null for edu/ucsb/cs156/example/controllers/CommitsController::lambda$updateCommit$1 → KILLED |
.orElseThrow(() -> new EntityNotFoundException(Commit.class, id)); |
127 | ||
128 |
1
1. updateCommit : removed call to edu/ucsb/cs156/example/entities/Commit::setAuthorLogin → KILLED |
commit.setAuthorLogin(incoming.getAuthorLogin()); |
129 |
1
1. updateCommit : removed call to edu/ucsb/cs156/example/entities/Commit::setCommitTime → KILLED |
commit.setCommitTime(incoming.getCommitTime()); |
130 |
1
1. updateCommit : removed call to edu/ucsb/cs156/example/entities/Commit::setMessage → KILLED |
commit.setMessage(incoming.getMessage()); |
131 |
1
1. updateCommit : removed call to edu/ucsb/cs156/example/entities/Commit::setUrl → KILLED |
commit.setUrl(incoming.getUrl()); |
132 | ||
133 | commitRepository.save(commit); | |
134 | ||
135 |
1
1. updateCommit : replaced return value with null for edu/ucsb/cs156/example/controllers/CommitsController::updateCommit → KILLED |
return commit; |
136 | } | |
137 | ||
138 | /** | |
139 | * Delete a Commit | |
140 | * | |
141 | * @param id the id of the commit to delete | |
142 | * @return a message indicating the commit was deleted | |
143 | */ | |
144 | @Operation(summary = "Delete a Commit") | |
145 | @PreAuthorize("hasRole('ROLE_ADMIN')") | |
146 | @DeleteMapping("") | |
147 | public Object deleteUCSBDate( | |
148 | @Parameter(name = "id") @RequestParam Long id) { | |
149 | Commit commit = commitRepository.findById(id) | |
150 |
1
1. lambda$deleteUCSBDate$2 : replaced return value with null for edu/ucsb/cs156/example/controllers/CommitsController::lambda$deleteUCSBDate$2 → KILLED |
.orElseThrow(() -> new EntityNotFoundException(Commit.class, id)); |
151 | ||
152 |
1
1. deleteUCSBDate : removed call to edu/ucsb/cs156/example/repositories/CommitRepository::delete → KILLED |
commitRepository.delete(commit); |
153 |
1
1. deleteUCSBDate : replaced return value with null for edu/ucsb/cs156/example/controllers/CommitsController::deleteUCSBDate → KILLED |
return genericMessage("Commit with id %s deleted".formatted(id)); |
154 | } | |
155 | ||
156 | } | |
Mutations | ||
56 |
1.1 |
|
84 |
1.1 |
|
85 |
1.1 |
|
86 |
1.1 |
|
87 |
1.1 |
|
91 |
1.1 |
|
106 |
1.1 |
|
108 |
1.1 |
|
126 |
1.1 |
|
128 |
1.1 |
|
129 |
1.1 |
|
130 |
1.1 |
|
131 |
1.1 |
|
135 |
1.1 |
|
150 |
1.1 |
|
152 |
1.1 |
|
153 |
1.1 |