1 | package edu.ucsb.cs156.example.controllers; | |
2 | ||
3 | import edu.ucsb.cs156.example.entities.UCSBArticles; | |
4 | import edu.ucsb.cs156.example.entities.UCSBDate; | |
5 | import edu.ucsb.cs156.example.errors.EntityNotFoundException; | |
6 | import edu.ucsb.cs156.example.repositories.UCSBArticlesRepository; | |
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 | ||
32 | /** | |
33 | * This is a REST controller for UCSBArticles | |
34 | */ | |
35 | ||
36 | @Tag(name = "UCSBArticles") | |
37 | @RequestMapping("/api/ucsbarticles") | |
38 | @RestController | |
39 | @Slf4j | |
40 | public class UCSBArticlesController extends ApiController { | |
41 | ||
42 | @Autowired | |
43 | UCSBArticlesRepository ucsbArticlesRepository; | |
44 | ||
45 | /** | |
46 | * List all UCSB articles | |
47 | * | |
48 | * @return an iterable of UCSBArticles | |
49 | */ | |
50 | @Operation(summary= "List all ucsb articles") | |
51 | @PreAuthorize("hasRole('ROLE_USER')") | |
52 | @GetMapping("/all") | |
53 | public Iterable<UCSBArticles> allUCSBArticles() { | |
54 | Iterable<UCSBArticles> articles = ucsbArticlesRepository.findAll(); | |
55 |
1
1. allUCSBArticles : replaced return value with Collections.emptyList for edu/ucsb/cs156/example/controllers/UCSBArticlesController::allUCSBArticles → KILLED |
return articles; |
56 | } | |
57 | ||
58 | ||
59 | /** | |
60 | * Create a new article | |
61 | * | |
62 | * @param title the title of the article | |
63 | * @param url the url of the article | |
64 | * @param explanation a summary of the article | |
65 | * @param email an email address | |
66 | * @param dateAdded the date | |
67 | * @return the saved ucsbarticle | |
68 | */ | |
69 | @Operation(summary= "Create a new article") | |
70 | @PreAuthorize("hasRole('ROLE_ADMIN')") | |
71 | @PostMapping("/post") | |
72 | public UCSBArticles postUCSBArticles( | |
73 | @Parameter(name="title") @RequestParam String title, | |
74 | @Parameter(name="url") @RequestParam String url, | |
75 | @Parameter(name="explanation") @RequestParam String explanation, | |
76 | @Parameter(name="email") @RequestParam String email, | |
77 | @Parameter(name="dateAdded", description="date (in iso format, e.g. YYYY-mm-ddTHH:MM:SS; see https://en.wikipedia.org/wiki/ISO_8601)") @RequestParam("dateAdded") @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME) LocalDateTime dateAdded) | |
78 | throws JsonProcessingException { | |
79 | ||
80 | // For an explanation of @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME) | |
81 | // See: https://www.baeldung.com/spring-date-parameters | |
82 | ||
83 | log.info("dateAdded={}", dateAdded); | |
84 | ||
85 | UCSBArticles ucsbArticles = new UCSBArticles(); | |
86 |
1
1. postUCSBArticles : removed call to edu/ucsb/cs156/example/entities/UCSBArticles::setTitle → KILLED |
ucsbArticles.setTitle(title); |
87 |
1
1. postUCSBArticles : removed call to edu/ucsb/cs156/example/entities/UCSBArticles::setUrl → KILLED |
ucsbArticles.setUrl(url); |
88 |
1
1. postUCSBArticles : removed call to edu/ucsb/cs156/example/entities/UCSBArticles::setExplanation → KILLED |
ucsbArticles.setExplanation(explanation); |
89 |
1
1. postUCSBArticles : removed call to edu/ucsb/cs156/example/entities/UCSBArticles::setEmail → KILLED |
ucsbArticles.setEmail(email); |
90 |
1
1. postUCSBArticles : removed call to edu/ucsb/cs156/example/entities/UCSBArticles::setDateAdded → KILLED |
ucsbArticles.setDateAdded(dateAdded); |
91 | ||
92 | UCSBArticles savedUcsbArticles = ucsbArticlesRepository.save(ucsbArticles); | |
93 | ||
94 |
1
1. postUCSBArticles : replaced return value with null for edu/ucsb/cs156/example/controllers/UCSBArticlesController::postUCSBArticles → KILLED |
return savedUcsbArticles; |
95 | } | |
96 | ||
97 | /** | |
98 | * Get a single article by id | |
99 | * | |
100 | * @param id the id of the article | |
101 | * @return a UCSBArticles | |
102 | */ | |
103 | @Operation(summary= "Get a single article") | |
104 | @PreAuthorize("hasRole('ROLE_USER')") | |
105 | @GetMapping("") | |
106 | public UCSBArticles getById( | |
107 | @Parameter(name="id") @RequestParam Long id) { | |
108 | UCSBArticles ucsbArticles = ucsbArticlesRepository.findById(id) | |
109 |
1
1. lambda$getById$0 : replaced return value with null for edu/ucsb/cs156/example/controllers/UCSBArticlesController::lambda$getById$0 → KILLED |
.orElseThrow(() -> new EntityNotFoundException(UCSBArticles.class, id)); |
110 | ||
111 |
1
1. getById : replaced return value with null for edu/ucsb/cs156/example/controllers/UCSBArticlesController::getById → KILLED |
return ucsbArticles; |
112 | } | |
113 | ||
114 | /** | |
115 | * Delete a UCSBArticles | |
116 | * | |
117 | * @param id the id of the article to delete | |
118 | * @return a message indicating the article was deleted | |
119 | */ | |
120 | @Operation(summary= "Delete a UCSBArticles") | |
121 | @PreAuthorize("hasRole('ROLE_ADMIN')") | |
122 | @DeleteMapping("") | |
123 | public Object deleteUCSBArticles( | |
124 | @Parameter(name="id") @RequestParam Long id) { | |
125 | UCSBArticles ucsbArticles = ucsbArticlesRepository.findById(id) | |
126 |
1
1. lambda$deleteUCSBArticles$1 : replaced return value with null for edu/ucsb/cs156/example/controllers/UCSBArticlesController::lambda$deleteUCSBArticles$1 → KILLED |
.orElseThrow(() -> new EntityNotFoundException(UCSBArticles.class, id)); |
127 | ||
128 |
1
1. deleteUCSBArticles : removed call to edu/ucsb/cs156/example/repositories/UCSBArticlesRepository::delete → KILLED |
ucsbArticlesRepository.delete(ucsbArticles); |
129 |
1
1. deleteUCSBArticles : replaced return value with null for edu/ucsb/cs156/example/controllers/UCSBArticlesController::deleteUCSBArticles → KILLED |
return genericMessage("UCSBArticle with id %s deleted".formatted(id)); |
130 | } | |
131 | ||
132 | /** | |
133 | * Update a single article | |
134 | * | |
135 | * @param id id of the article to update | |
136 | * @param incoming the new article | |
137 | * @return the updated article object | |
138 | */ | |
139 | @Operation(summary= "Update a single article") | |
140 | @PreAuthorize("hasRole('ROLE_ADMIN')") | |
141 | @PutMapping("") | |
142 | public UCSBArticles updateUCSBArticles( | |
143 | @Parameter(name="id") @RequestParam Long id, | |
144 | @RequestBody @Valid UCSBArticles incoming) { | |
145 | ||
146 | UCSBArticles ucsbArticles = ucsbArticlesRepository.findById(id) | |
147 |
1
1. lambda$updateUCSBArticles$2 : replaced return value with null for edu/ucsb/cs156/example/controllers/UCSBArticlesController::lambda$updateUCSBArticles$2 → KILLED |
.orElseThrow(() -> new EntityNotFoundException(UCSBArticles.class, id)); |
148 | ||
149 |
1
1. updateUCSBArticles : removed call to edu/ucsb/cs156/example/entities/UCSBArticles::setTitle → KILLED |
ucsbArticles.setTitle(incoming.getTitle()); |
150 |
1
1. updateUCSBArticles : removed call to edu/ucsb/cs156/example/entities/UCSBArticles::setUrl → KILLED |
ucsbArticles.setUrl(incoming.getUrl()); |
151 |
1
1. updateUCSBArticles : removed call to edu/ucsb/cs156/example/entities/UCSBArticles::setExplanation → KILLED |
ucsbArticles.setExplanation(incoming.getExplanation()); |
152 |
1
1. updateUCSBArticles : removed call to edu/ucsb/cs156/example/entities/UCSBArticles::setEmail → KILLED |
ucsbArticles.setEmail(incoming.getEmail()); |
153 |
1
1. updateUCSBArticles : removed call to edu/ucsb/cs156/example/entities/UCSBArticles::setDateAdded → KILLED |
ucsbArticles.setDateAdded(incoming.getDateAdded()); |
154 | ||
155 | ucsbArticlesRepository.save(ucsbArticles); | |
156 | ||
157 |
1
1. updateUCSBArticles : replaced return value with null for edu/ucsb/cs156/example/controllers/UCSBArticlesController::updateUCSBArticles → KILLED |
return ucsbArticles; |
158 | } | |
159 | ||
160 | ||
161 | } | |
Mutations | ||
55 |
1.1 |
|
86 |
1.1 |
|
87 |
1.1 |
|
88 |
1.1 |
|
89 |
1.1 |
|
90 |
1.1 |
|
94 |
1.1 |
|
109 |
1.1 |
|
111 |
1.1 |
|
126 |
1.1 |
|
128 |
1.1 |
|
129 |
1.1 |
|
147 |
1.1 |
|
149 |
1.1 |
|
150 |
1.1 |
|
151 |
1.1 |
|
152 |
1.1 |
|
153 |
1.1 |
|
157 |
1.1 |