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