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 @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME) LocalDateTime dateAdded) | |
57 | throws JsonProcessingException { | |
58 | ||
59 | log.info("dateAdded={}", dateAdded); | |
60 | ||
61 | Articles articles = new Articles(); | |
62 |
1
1. postArticles : removed call to edu/ucsb/cs156/example/entities/Articles::setTitle → KILLED |
articles.setTitle(title); |
63 |
1
1. postArticles : removed call to edu/ucsb/cs156/example/entities/Articles::setUrl → KILLED |
articles.setUrl(url); |
64 |
1
1. postArticles : removed call to edu/ucsb/cs156/example/entities/Articles::setExplanation → KILLED |
articles.setExplanation(explanation); |
65 |
1
1. postArticles : removed call to edu/ucsb/cs156/example/entities/Articles::setEmail → KILLED |
articles.setEmail(email); |
66 |
1
1. postArticles : removed call to edu/ucsb/cs156/example/entities/Articles::setDateAdded → KILLED |
articles.setDateAdded(dateAdded); |
67 | ||
68 | Articles savedArticles = articlesRepository.save(articles); | |
69 |
1
1. postArticles : replaced return value with null for edu/ucsb/cs156/example/controllers/ArticlesController::postArticles → KILLED |
return savedArticles; |
70 | } | |
71 | ||
72 | @Operation(summary= "Get a single article") | |
73 | @PreAuthorize("hasRole('ROLE_USER')") | |
74 | @GetMapping("") | |
75 | public Articles getById( | |
76 | @Parameter(name="id") @RequestParam Long id) { | |
77 | Articles articles = articlesRepository.findById(id) | |
78 |
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)); |
79 | ||
80 |
1
1. getById : replaced return value with null for edu/ucsb/cs156/example/controllers/ArticlesController::getById → KILLED |
return articles; |
81 | } | |
82 | ||
83 | @Operation(summary= "Delete an article") | |
84 | @PreAuthorize("hasRole('ROLE_ADMIN')") | |
85 | @DeleteMapping("") | |
86 | public Object deleteArticles( | |
87 | @Parameter(name="id") @RequestParam Long id) { | |
88 | Articles articles = articlesRepository.findById(id) | |
89 |
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)); |
90 |
1
1. deleteArticles : removed call to edu/ucsb/cs156/example/repositories/ArticlesRepository::delete → KILLED |
articlesRepository.delete(articles); |
91 |
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)); |
92 | } | |
93 | ||
94 | @Operation(summary= "Update a single article") | |
95 | @PreAuthorize("hasRole('ROLE_ADMIN')") | |
96 | @PutMapping("") | |
97 | public Articles updateArticles( | |
98 | @Parameter(name="id") @RequestParam Long id, | |
99 | @RequestBody @Valid Articles incoming) { | |
100 | ||
101 | Articles articles = articlesRepository.findById(id) | |
102 |
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)); |
103 |
1
1. updateArticles : removed call to edu/ucsb/cs156/example/entities/Articles::setTitle → KILLED |
articles.setTitle(incoming.getTitle()); |
104 |
1
1. updateArticles : removed call to edu/ucsb/cs156/example/entities/Articles::setUrl → KILLED |
articles.setUrl(incoming.getUrl()); |
105 |
1
1. updateArticles : removed call to edu/ucsb/cs156/example/entities/Articles::setExplanation → KILLED |
articles.setExplanation(incoming.getExplanation()); |
106 |
1
1. updateArticles : removed call to edu/ucsb/cs156/example/entities/Articles::setEmail → KILLED |
articles.setEmail(incoming.getEmail()); |
107 |
1
1. updateArticles : removed call to edu/ucsb/cs156/example/entities/Articles::setDateAdded → KILLED |
articles.setDateAdded(incoming.getDateAdded()); |
108 | articlesRepository.save(articles); | |
109 |
1
1. updateArticles : replaced return value with null for edu/ucsb/cs156/example/controllers/ArticlesController::updateArticles → KILLED |
return articles; |
110 | } | |
111 | } | |
Mutations | ||
45 |
1.1 |
|
62 |
1.1 |
|
63 |
1.1 |
|
64 |
1.1 |
|
65 |
1.1 |
|
66 |
1.1 |
|
69 |
1.1 |
|
78 |
1.1 |
|
80 |
1.1 |
|
89 |
1.1 |
|
90 |
1.1 |
|
91 |
1.1 |
|
102 |
1.1 |
|
103 |
1.1 |
|
104 |
1.1 |
|
105 |
1.1 |
|
106 |
1.1 |
|
107 |
1.1 |
|
109 |
1.1 |