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