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