| 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 org.springframework.beans.factory.annotation.Autowired; | |
| 13 | import org.springframework.format.annotation.DateTimeFormat; | |
| 14 | import org.springframework.security.access.prepost.PreAuthorize; | |
| 15 | import org.springframework.web.bind.annotation.DeleteMapping; | |
| 16 | import org.springframework.web.bind.annotation.GetMapping; | |
| 17 | import org.springframework.web.bind.annotation.PostMapping; | |
| 18 | import org.springframework.web.bind.annotation.PutMapping; | |
| 19 | import org.springframework.web.bind.annotation.RequestBody; | |
| 20 | import org.springframework.web.bind.annotation.RequestMapping; | |
| 21 | import org.springframework.web.bind.annotation.RequestParam; | |
| 22 | import org.springframework.web.bind.annotation.RestController; | |
| 23 | ||
| 24 | import jakarta.validation.Valid; | |
| 25 | ||
| 26 | import java.time.LocalDateTime; | |
| 27 | ||
| 28 | /** | |
| 29 | * This is a REST controller for Articles | |
| 30 | */ | |
| 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 | /** | |
| 42 | * List all Articles | |
| 43 | * | |
| 44 | * @return an iterable of Articles | |
| 45 | */ | |
| 46 | @Operation(summary= "List all articles") | |
| 47 | @PreAuthorize("hasRole('ROLE_USER')") | |
| 48 | @GetMapping("/all") | |
| 49 | public Iterable<Articles> allArticles() { | |
| 50 | Iterable<Articles> articles = articlesRepository.findAll(); | |
| 51 |
1
1. allArticles : replaced return value with Collections.emptyList for edu/ucsb/cs156/example/controllers/ArticlesController::allArticles → KILLED |
return articles; |
| 52 | } | |
| 53 | ||
| 54 | /** | |
| 55 | * Get a single article by id | |
| 56 | * | |
| 57 | * @param id the id of the article | |
| 58 | * @return an article | |
| 59 | */ | |
| 60 | @Operation(summary= "Get a single article") | |
| 61 | @PreAuthorize("hasRole('ROLE_USER')") | |
| 62 | @GetMapping("") | |
| 63 | public Articles getById( | |
| 64 | @Parameter(name="id") @RequestParam Long id) { | |
| 65 | Articles article = articlesRepository.findById(id) | |
| 66 |
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)); |
| 67 | ||
| 68 |
1
1. getById : replaced return value with null for edu/ucsb/cs156/example/controllers/ArticlesController::getById → KILLED |
return article; |
| 69 | } | |
| 70 | ||
| 71 | /** | |
| 72 | * Create a new article | |
| 73 | * | |
| 74 | * @param title the title of the article | |
| 75 | * @param url the url of the article | |
| 76 | * @param explanation the explanation of the article | |
| 77 | * @param email the email of the submitter | |
| 78 | * @return the saved article | |
| 79 | */ | |
| 80 | @Operation(summary = "Create a new article") | |
| 81 | @PreAuthorize("hasRole('ROLE_ADMIN')") | |
| 82 | @PostMapping("/post") | |
| 83 | public Articles postArticles( | |
| 84 | @Parameter(name="title") @RequestParam String title, | |
| 85 | @Parameter(name="url") @RequestParam String url, | |
| 86 | @Parameter(name="explanation") @RequestParam(required = false) String explanation, | |
| 87 | @Parameter(name="email") @RequestParam String email) { | |
| 88 | ||
| 89 | Articles article = new Articles(); | |
| 90 |
1
1. postArticles : removed call to edu/ucsb/cs156/example/entities/Articles::setTitle → KILLED |
article.setTitle(title); |
| 91 |
1
1. postArticles : removed call to edu/ucsb/cs156/example/entities/Articles::setUrl → KILLED |
article.setUrl(url); |
| 92 |
1
1. postArticles : removed call to edu/ucsb/cs156/example/entities/Articles::setExplanation → KILLED |
article.setExplanation(explanation); |
| 93 |
1
1. postArticles : removed call to edu/ucsb/cs156/example/entities/Articles::setEmail → KILLED |
article.setEmail(email); |
| 94 |
1
1. postArticles : removed call to edu/ucsb/cs156/example/entities/Articles::setDateAdded → KILLED |
article.setDateAdded(LocalDateTime.now()); |
| 95 | ||
| 96 | Articles savedArticle = articlesRepository.save(article); | |
| 97 | ||
| 98 |
1
1. postArticles : replaced return value with null for edu/ucsb/cs156/example/controllers/ArticlesController::postArticles → KILLED |
return savedArticle; |
| 99 | } | |
| 100 | ||
| 101 | /** | |
| 102 | * Update a single article | |
| 103 | * | |
| 104 | * @param id id of the article to update | |
| 105 | * @param incoming the new article | |
| 106 | * @return the updated article object | |
| 107 | */ | |
| 108 | @Operation(summary= "Update a single article") | |
| 109 | @PreAuthorize("hasRole('ROLE_ADMIN')") | |
| 110 | @PutMapping("") | |
| 111 | public Articles updateArticle( | |
| 112 | @Parameter(name="id") @RequestParam Long id, | |
| 113 | @RequestBody @Valid Articles incoming) { | |
| 114 | ||
| 115 | Articles article = articlesRepository.findById(id) | |
| 116 |
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)); |
| 117 | ||
| 118 |
1
1. updateArticle : removed call to edu/ucsb/cs156/example/entities/Articles::setTitle → KILLED |
article.setTitle(incoming.getTitle()); |
| 119 |
1
1. updateArticle : removed call to edu/ucsb/cs156/example/entities/Articles::setUrl → KILLED |
article.setUrl(incoming.getUrl()); |
| 120 |
1
1. updateArticle : removed call to edu/ucsb/cs156/example/entities/Articles::setExplanation → KILLED |
article.setExplanation(incoming.getExplanation()); |
| 121 |
1
1. updateArticle : removed call to edu/ucsb/cs156/example/entities/Articles::setEmail → KILLED |
article.setEmail(incoming.getEmail()); |
| 122 |
1
1. updateArticle : removed call to edu/ucsb/cs156/example/entities/Articles::setDateAdded → KILLED |
article.setDateAdded(incoming.getDateAdded()); |
| 123 | ||
| 124 | articlesRepository.save(article); | |
| 125 | ||
| 126 |
1
1. updateArticle : replaced return value with null for edu/ucsb/cs156/example/controllers/ArticlesController::updateArticle → KILLED |
return article; |
| 127 | } | |
| 128 | ||
| 129 | /** | |
| 130 | * Delete an Article | |
| 131 | * | |
| 132 | * @param id the id of the article to delete | |
| 133 | * @return a message indicating the article was deleted | |
| 134 | */ | |
| 135 | @Operation(summary= "Delete an Article") | |
| 136 | @PreAuthorize("hasRole('ROLE_ADMIN')") | |
| 137 | @DeleteMapping("") | |
| 138 | public Object deleteArticle( | |
| 139 | @Parameter(name="id") @RequestParam Long id) { | |
| 140 | Articles article = articlesRepository.findById(id) | |
| 141 |
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)); |
| 142 | ||
| 143 |
1
1. deleteArticle : removed call to edu/ucsb/cs156/example/repositories/ArticlesRepository::delete → KILLED |
articlesRepository.delete(article); |
| 144 |
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)); |
| 145 | } | |
| 146 | } | |
Mutations | ||
| 51 |
1.1 |
|
| 66 |
1.1 |
|
| 68 |
1.1 |
|
| 90 |
1.1 |
|
| 91 |
1.1 |
|
| 92 |
1.1 |
|
| 93 |
1.1 |
|
| 94 |
1.1 |
|
| 98 |
1.1 |
|
| 116 |
1.1 |
|
| 118 |
1.1 |
|
| 119 |
1.1 |
|
| 120 |
1.1 |
|
| 121 |
1.1 |
|
| 122 |
1.1 |
|
| 126 |
1.1 |
|
| 141 |
1.1 |
|
| 143 |
1.1 |
|
| 144 |
1.1 |