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