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