1 | package edu.ucsb.cs156.example.controllers; | |
2 | ||
3 | import edu.ucsb.cs156.example.entities.Article; | |
4 | import edu.ucsb.cs156.example.errors.EntityNotFoundException; | |
5 | import edu.ucsb.cs156.example.repositories.ArticleRepository; | |
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 jakarta.validation.Valid; | |
27 | ||
28 | import java.time.LocalDateTime; | |
29 | ||
30 | /** | |
31 | * This is a REST controller for Article | |
32 | */ | |
33 | ||
34 | @Tag(name = "Articles") | |
35 | @RequestMapping("/api/articles") | |
36 | @RestController | |
37 | @Slf4j | |
38 | public class ArticlesController extends ApiController { | |
39 | ||
40 | @Autowired | |
41 | ArticleRepository articleRepository; | |
42 | ||
43 | /** | |
44 | * List all Articles | |
45 | * | |
46 | * @return an iterable of Articles | |
47 | */ | |
48 | @Operation(summary= "List all articles") | |
49 | @PreAuthorize("hasRole('ROLE_USER')") | |
50 | @GetMapping("/all") | |
51 | public Iterable<Article> allArticles() { | |
52 | Iterable<Article> article = articleRepository.findAll(); | |
53 |
1
1. allArticles : replaced return value with Collections.emptyList for edu/ucsb/cs156/example/controllers/ArticlesController::allArticles → KILLED |
return article; |
54 | } | |
55 | ||
56 | /** | |
57 | * Get a single article by id | |
58 | * | |
59 | * @param id the id of the article | |
60 | * @return a Article | |
61 | */ | |
62 | @Operation(summary= "Get a single article") | |
63 | @PreAuthorize("hasRole('ROLE_USER')") | |
64 | @GetMapping("") | |
65 | public Article getById( | |
66 | @Parameter(name="id") @RequestParam Long id) { | |
67 | Article article = articleRepository.findById(id) | |
68 |
1
1. lambda$getById$0 : replaced return value with null for edu/ucsb/cs156/example/controllers/ArticlesController::lambda$getById$0 → KILLED |
.orElseThrow(() -> new EntityNotFoundException(Article.class, id)); |
69 | ||
70 |
1
1. getById : replaced return value with null for edu/ucsb/cs156/example/controllers/ArticlesController::getById → KILLED |
return article; |
71 | } | |
72 | ||
73 | /** | |
74 | * Create a new article | |
75 | * | |
76 | * @param title the title of the article | |
77 | * @param url the url of the article | |
78 | * @param explanation the explanation within the article | |
79 | * @param email the email of the user making the article | |
80 | * @param dateAdded the date the article was added | |
81 | * @return the saved article | |
82 | */ | |
83 | @Operation(summary= "Create a new article") | |
84 | @PreAuthorize("hasRole('ROLE_ADMIN')") | |
85 | @PostMapping("/post") | |
86 | public Article postArticle( | |
87 | @Parameter(name="title") @RequestParam String title, | |
88 | @Parameter(name="url") @RequestParam String url, | |
89 | @Parameter(name="explanation") @RequestParam String explanation, | |
90 | @Parameter(name="email") @RequestParam String email, | |
91 | @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) | |
92 | throws JsonProcessingException { | |
93 | ||
94 | log.info("dateAdded={}", dateAdded); | |
95 | ||
96 | Article article = new Article(); | |
97 |
1
1. postArticle : removed call to edu/ucsb/cs156/example/entities/Article::setTitle → KILLED |
article.setTitle(title); |
98 |
1
1. postArticle : removed call to edu/ucsb/cs156/example/entities/Article::setUrl → KILLED |
article.setUrl(url); |
99 |
1
1. postArticle : removed call to edu/ucsb/cs156/example/entities/Article::setExplanation → KILLED |
article.setExplanation(explanation); |
100 |
1
1. postArticle : removed call to edu/ucsb/cs156/example/entities/Article::setEmail → KILLED |
article.setEmail(email); |
101 |
1
1. postArticle : removed call to edu/ucsb/cs156/example/entities/Article::setDateAdded → KILLED |
article.setDateAdded(dateAdded); |
102 | ||
103 | Article savedArticle = articleRepository.save(article); | |
104 | ||
105 |
1
1. postArticle : replaced return value with null for edu/ucsb/cs156/example/controllers/ArticlesController::postArticle → KILLED |
return savedArticle; |
106 | } | |
107 | ||
108 | /** | |
109 | * Delete a article | |
110 | * | |
111 | * @param id the id of the article to delete | |
112 | * @return a message indicating the article was deleted | |
113 | */ | |
114 | @Operation(summary= "Delete an article") | |
115 | @PreAuthorize("hasRole('ROLE_ADMIN')") | |
116 | @DeleteMapping("") | |
117 | public Object deleteArticle( | |
118 | @Parameter(name="id") @RequestParam Long id) { | |
119 | Article ucsbDate = articleRepository.findById(id) | |
120 |
1
1. lambda$deleteArticle$1 : replaced return value with null for edu/ucsb/cs156/example/controllers/ArticlesController::lambda$deleteArticle$1 → KILLED |
.orElseThrow(() -> new EntityNotFoundException(Article.class, id)); |
121 | ||
122 |
1
1. deleteArticle : removed call to edu/ucsb/cs156/example/repositories/ArticleRepository::delete → KILLED |
articleRepository.delete(ucsbDate); |
123 |
1
1. deleteArticle : replaced return value with null for edu/ucsb/cs156/example/controllers/ArticlesController::deleteArticle → KILLED |
return genericMessage("Article with id %s deleted".formatted(id)); |
124 | } | |
125 | ||
126 | /** | |
127 | * Update a single article | |
128 | * | |
129 | * @param id id of the article to update | |
130 | * @param incoming the new article | |
131 | * @return the updated article object | |
132 | */ | |
133 | @Operation(summary= "Update a single article") | |
134 | @PreAuthorize("hasRole('ROLE_ADMIN')") | |
135 | @PutMapping("") | |
136 | public Article updateArticle( | |
137 | @Parameter(name="id") @RequestParam Long id, | |
138 | @RequestBody @Valid Article incoming) { | |
139 | ||
140 | Article article = articleRepository.findById(id) | |
141 |
1
1. lambda$updateArticle$2 : replaced return value with null for edu/ucsb/cs156/example/controllers/ArticlesController::lambda$updateArticle$2 → KILLED |
.orElseThrow(() -> new EntityNotFoundException(Article.class, id)); |
142 | ||
143 |
1
1. updateArticle : removed call to edu/ucsb/cs156/example/entities/Article::setTitle → KILLED |
article.setTitle(incoming.getTitle()); |
144 |
1
1. updateArticle : removed call to edu/ucsb/cs156/example/entities/Article::setUrl → KILLED |
article.setUrl(incoming.getUrl()); |
145 |
1
1. updateArticle : removed call to edu/ucsb/cs156/example/entities/Article::setExplanation → KILLED |
article.setExplanation(incoming.getExplanation()); |
146 |
1
1. updateArticle : removed call to edu/ucsb/cs156/example/entities/Article::setEmail → KILLED |
article.setEmail(incoming.getEmail()); |
147 |
1
1. updateArticle : removed call to edu/ucsb/cs156/example/entities/Article::setDateAdded → KILLED |
article.setDateAdded(incoming.getDateAdded()); |
148 | ||
149 | articleRepository.save(article); | |
150 | ||
151 |
1
1. updateArticle : replaced return value with null for edu/ucsb/cs156/example/controllers/ArticlesController::updateArticle → KILLED |
return article; |
152 | } | |
153 | } | |
Mutations | ||
53 |
1.1 |
|
68 |
1.1 |
|
70 |
1.1 |
|
97 |
1.1 |
|
98 |
1.1 |
|
99 |
1.1 |
|
100 |
1.1 |
|
101 |
1.1 |
|
105 |
1.1 |
|
120 |
1.1 |
|
122 |
1.1 |
|
123 |
1.1 |
|
141 |
1.1 |
|
143 |
1.1 |
|
144 |
1.1 |
|
145 |
1.1 |
|
146 |
1.1 |
|
147 |
1.1 |
|
151 |
1.1 |