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 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 javax.validation.Valid; | |
27 | ||
28 | import java.time.LocalDateTime; | |
29 | ||
30 | @Tag(name = "Articles") | |
31 | @RequestMapping("/api/articles") | |
32 | @RestController | |
33 | @Slf4j | |
34 | public class ArticlesController extends ApiController { | |
35 | ||
36 | @Autowired | |
37 | ArticlesRepository articlesRepository; | |
38 | ||
39 | @Operation(summary= "List all articles") | |
40 | @PreAuthorize("hasRole('ROLE_USER')") | |
41 | @GetMapping("/all") | |
42 | public Iterable<Articles> allArticles() { | |
43 | Iterable<Articles> articles = articlesRepository.findAll(); | |
44 |
1
1. allArticles : replaced return value with null for edu/ucsb/cs156/example/controllers/ArticlesController::allArticles → KILLED |
return articles; |
45 | } | |
46 | ||
47 | @Operation(summary= "Create a new article") | |
48 | @PreAuthorize("hasRole('ROLE_ADMIN')") | |
49 | @PostMapping("/post") | |
50 | public Articles postArticle( | |
51 | // private String title; | |
52 | // private String url; | |
53 | // private String explanation; | |
54 | // private String email; | |
55 | // private LocalDateTime dateAdded; | |
56 | ||
57 | @Parameter(name="title") @RequestParam String title, | |
58 | @Parameter(name="url") @RequestParam String url, | |
59 | @Parameter(name="explanation") @RequestParam String explanation, | |
60 | @Parameter(name="email") @RequestParam String email, | |
61 | @Parameter(name="dateAdded", description="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) | |
62 | throws JsonProcessingException { | |
63 | ||
64 | // For an explanation of @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME) | |
65 | // See: https://www.baeldung.com/spring-date-parameters | |
66 | ||
67 | log.info("dateAdded={}", dateAdded); | |
68 | ||
69 | Articles article = new Articles(); | |
70 |
1
1. postArticle : removed call to edu/ucsb/cs156/example/entities/Articles::setTitle → KILLED |
article.setTitle(title); |
71 |
1
1. postArticle : removed call to edu/ucsb/cs156/example/entities/Articles::setUrl → KILLED |
article.setUrl(url); |
72 |
1
1. postArticle : removed call to edu/ucsb/cs156/example/entities/Articles::setExplanation → KILLED |
article.setExplanation(explanation); |
73 |
1
1. postArticle : removed call to edu/ucsb/cs156/example/entities/Articles::setEmail → KILLED |
article.setEmail(email); |
74 |
1
1. postArticle : removed call to edu/ucsb/cs156/example/entities/Articles::setDateAdded → KILLED |
article.setDateAdded(dateAdded); |
75 | ||
76 | Articles savedArticle = articlesRepository.save(article); | |
77 | ||
78 |
1
1. postArticle : replaced return value with null for edu/ucsb/cs156/example/controllers/ArticlesController::postArticle → KILLED |
return savedArticle; |
79 | } | |
80 | ||
81 | @Operation(summary= "Get a single article") | |
82 | @PreAuthorize("hasRole('ROLE_USER')") | |
83 | @GetMapping("") | |
84 | public Articles getById( | |
85 | @Parameter(name="id") @RequestParam Long id) { | |
86 | Articles article = articlesRepository.findById(id) | |
87 |
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)); |
88 | ||
89 |
1
1. getById : replaced return value with null for edu/ucsb/cs156/example/controllers/ArticlesController::getById → KILLED |
return article; |
90 | } | |
91 | ||
92 | @Operation(summary= "Update a single article") | |
93 | @PreAuthorize("hasRole('ROLE_ADMIN')") | |
94 | @PutMapping("") | |
95 | public Articles updateArticle( | |
96 | @Parameter(name="id") @RequestParam Long id, | |
97 | @RequestBody @Valid Articles incoming) { | |
98 | ||
99 | Articles article = articlesRepository.findById(id) | |
100 |
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)); |
101 | | |
102 |
1
1. updateArticle : removed call to edu/ucsb/cs156/example/entities/Articles::setTitle → KILLED |
article.setTitle(incoming.getTitle()); |
103 |
1
1. updateArticle : removed call to edu/ucsb/cs156/example/entities/Articles::setUrl → KILLED |
article.setUrl(incoming.getUrl()); |
104 |
1
1. updateArticle : removed call to edu/ucsb/cs156/example/entities/Articles::setExplanation → KILLED |
article.setExplanation(incoming.getExplanation()); |
105 |
1
1. updateArticle : removed call to edu/ucsb/cs156/example/entities/Articles::setEmail → KILLED |
article.setEmail(incoming.getEmail()); |
106 |
1
1. updateArticle : removed call to edu/ucsb/cs156/example/entities/Articles::setDateAdded → KILLED |
article.setDateAdded(incoming.getDateAdded()); |
107 | ||
108 | articlesRepository.save(article); | |
109 | ||
110 |
1
1. updateArticle : replaced return value with null for edu/ucsb/cs156/example/controllers/ArticlesController::updateArticle → KILLED |
return article; |
111 | } | |
112 | ||
113 | @Operation(summary= "Delete a Article") | |
114 | @PreAuthorize("hasRole('ROLE_ADMIN')") | |
115 | @DeleteMapping("") | |
116 | public Object deleteArticle( | |
117 | @Parameter(name="id") @RequestParam Long id) { | |
118 | Articles article = articlesRepository.findById(id) | |
119 |
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)); |
120 | ||
121 |
1
1. deleteArticle : removed call to edu/ucsb/cs156/example/repositories/ArticlesRepository::delete → KILLED |
articlesRepository.delete(article); |
122 |
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)); |
123 | } | |
124 | } | |
Mutations | ||
44 |
1.1 |
|
70 |
1.1 |
|
71 |
1.1 |
|
72 |
1.1 |
|
73 |
1.1 |
|
74 |
1.1 |
|
78 |
1.1 |
|
87 |
1.1 |
|
89 |
1.1 |
|
100 |
1.1 |
|
102 |
1.1 |
|
103 |
1.1 |
|
104 |
1.1 |
|
105 |
1.1 |
|
106 |
1.1 |
|
110 |
1.1 |
|
119 |
1.1 |
|
121 |
1.1 |
|
122 |
1.1 |