| 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 | import io.swagger.v3.oas.annotations.Operation; | |
| 7 | import io.swagger.v3.oas.annotations.Parameter; | |
| 8 | import io.swagger.v3.oas.annotations.tags.Tag; | |
| 9 | import jakarta.validation.Valid; | |
| 10 | import java.time.LocalDateTime; | |
| 11 | import org.springframework.beans.factory.annotation.Autowired; | |
| 12 | import org.springframework.format.annotation.DateTimeFormat; | |
| 13 | import org.springframework.security.access.prepost.PreAuthorize; | |
| 14 | import org.springframework.web.bind.annotation.DeleteMapping; | |
| 15 | import org.springframework.web.bind.annotation.GetMapping; | |
| 16 | import org.springframework.web.bind.annotation.PostMapping; | |
| 17 | import org.springframework.web.bind.annotation.PutMapping; | |
| 18 | import org.springframework.web.bind.annotation.RequestBody; | |
| 19 | import org.springframework.web.bind.annotation.RequestMapping; | |
| 20 | import org.springframework.web.bind.annotation.RequestParam; | |
| 21 | import org.springframework.web.bind.annotation.RestController; | |
| 22 | ||
| 23 | /** This is a REST controller for Articles. */ | |
| 24 | @Tag(name = "Articles") | |
| 25 | @RequestMapping("/api/articles") | |
| 26 | @RestController | |
| 27 | public class ArticlesController extends ApiController { | |
| 28 | ||
| 29 | @Autowired ArticlesRepository articlesRepository; | |
| 30 | ||
| 31 | /** | |
| 32 | * List all articles. | |
| 33 | * | |
| 34 | * @return an iterable of Articles | |
| 35 | */ | |
| 36 | @Operation(summary = "List all articles") | |
| 37 | @PreAuthorize("hasRole('ROLE_USER')") | |
| 38 | @GetMapping("/all") | |
| 39 | public Iterable<Articles> allArticles() { | |
| 40 | Iterable<Articles> articles = articlesRepository.findAll(); | |
| 41 |
1
1. allArticles : replaced return value with Collections.emptyList for edu/ucsb/cs156/example/controllers/ArticlesController::allArticles → KILLED |
return articles; |
| 42 | } | |
| 43 | ||
| 44 | /** | |
| 45 | * Get a single article by its ID. | |
| 46 | * | |
| 47 | * @param id the ID of the article | |
| 48 | * @return the article with the given ID | |
| 49 | */ | |
| 50 | @Operation(summary = "Get a single article by ID") | |
| 51 | @PreAuthorize("hasRole('ROLE_USER')") | |
| 52 | @GetMapping("") | |
| 53 | public Articles getById( | |
| 54 | @Parameter(name = "id", description = "ID of the article to retrieve") @RequestParam | |
| 55 | Long id) { | |
| 56 | ||
| 57 | Articles article = | |
| 58 | articlesRepository | |
| 59 | .findById(id) | |
| 60 |
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)); |
| 61 | ||
| 62 |
1
1. getById : replaced return value with null for edu/ucsb/cs156/example/controllers/ArticlesController::getById → KILLED |
return article; |
| 63 | } | |
| 64 | ||
| 65 | /** | |
| 66 | * Create a new article. | |
| 67 | * | |
| 68 | * @param title the article title | |
| 69 | * @param url the article URL | |
| 70 | * @param explanation why the article is useful | |
| 71 | * @param email email of the person submitting the article | |
| 72 | * @param dateAdded date and time the article was added | |
| 73 | * @return the saved article | |
| 74 | */ | |
| 75 | @Operation(summary = "Create a new article") | |
| 76 | @PreAuthorize("hasRole('ROLE_ADMIN')") | |
| 77 | @PostMapping("/post") | |
| 78 | public Articles postArticle( | |
| 79 | @Parameter(name = "title") @RequestParam String title, | |
| 80 | @Parameter(name = "url") @RequestParam String url, | |
| 81 | @Parameter(name = "explanation") @RequestParam String explanation, | |
| 82 | @Parameter(name = "email") @RequestParam String email, | |
| 83 | @Parameter(name = "dateAdded") | |
| 84 | @RequestParam("dateAdded") | |
| 85 | @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME) | |
| 86 | LocalDateTime dateAdded) { | |
| 87 | ||
| 88 | Articles article = new Articles(); | |
| 89 |
1
1. postArticle : removed call to edu/ucsb/cs156/example/entities/Articles::setTitle → KILLED |
article.setTitle(title); |
| 90 |
1
1. postArticle : removed call to edu/ucsb/cs156/example/entities/Articles::setUrl → KILLED |
article.setUrl(url); |
| 91 |
1
1. postArticle : removed call to edu/ucsb/cs156/example/entities/Articles::setExplanation → KILLED |
article.setExplanation(explanation); |
| 92 |
1
1. postArticle : removed call to edu/ucsb/cs156/example/entities/Articles::setEmail → KILLED |
article.setEmail(email); |
| 93 |
1
1. postArticle : removed call to edu/ucsb/cs156/example/entities/Articles::setDateAdded → KILLED |
article.setDateAdded(dateAdded); |
| 94 | ||
| 95 | Articles savedArticle = articlesRepository.save(article); | |
| 96 | ||
| 97 |
1
1. postArticle : replaced return value with null for edu/ucsb/cs156/example/controllers/ArticlesController::postArticle → KILLED |
return savedArticle; |
| 98 | } | |
| 99 | ||
| 100 | /** | |
| 101 | * Update an existing article. | |
| 102 | * | |
| 103 | * @param id the id of the article to update | |
| 104 | * @param incoming the new article contents | |
| 105 | * @return the updated article | |
| 106 | */ | |
| 107 | @Operation(summary = "Update a single article") | |
| 108 | @PreAuthorize("hasRole('ROLE_ADMIN')") | |
| 109 | @PutMapping("") | |
| 110 | public Articles updateArticle( | |
| 111 | @Parameter(name = "id") @RequestParam Long id, @RequestBody @Valid Articles incoming) { | |
| 112 | ||
| 113 | Articles article = | |
| 114 | articlesRepository | |
| 115 | .findById(id) | |
| 116 |
1
1. lambda$updateArticle$0 : replaced return value with null for edu/ucsb/cs156/example/controllers/ArticlesController::lambda$updateArticle$0 → 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 existing article. | |
| 131 | * | |
| 132 | * @param id the ID of the article to delete | |
| 133 | * @return a message confirming the article was deleted | |
| 134 | */ | |
| 135 | @Operation(summary = "Delete a single article by ID") | |
| 136 | @PreAuthorize("hasRole('ROLE_ADMIN')") | |
| 137 | @DeleteMapping("") | |
| 138 | public Object deleteArticle( | |
| 139 | @Parameter(name = "id", description = "ID of the article to delete") @RequestParam Long id) { | |
| 140 | ||
| 141 | Articles article = | |
| 142 | articlesRepository | |
| 143 | .findById(id) | |
| 144 |
1
1. lambda$deleteArticle$0 : replaced return value with null for edu/ucsb/cs156/example/controllers/ArticlesController::lambda$deleteArticle$0 → KILLED |
.orElseThrow(() -> new EntityNotFoundException(Articles.class, id)); |
| 145 | ||
| 146 |
1
1. deleteArticle : removed call to edu/ucsb/cs156/example/repositories/ArticlesRepository::delete → KILLED |
articlesRepository.delete(article); |
| 147 | ||
| 148 |
1
1. deleteArticle : replaced return value with null for edu/ucsb/cs156/example/controllers/ArticlesController::deleteArticle → KILLED |
return genericMessage("Articles with id %s deleted".formatted(id)); |
| 149 | } | |
| 150 | } | |
Mutations | ||
| 41 |
1.1 |
|
| 60 |
1.1 |
|
| 62 |
1.1 |
|
| 89 |
1.1 |
|
| 90 |
1.1 |
|
| 91 |
1.1 |
|
| 92 |
1.1 |
|
| 93 |
1.1 |
|
| 97 |
1.1 |
|
| 116 |
1.1 |
|
| 118 |
1.1 |
|
| 119 |
1.1 |
|
| 120 |
1.1 |
|
| 121 |
1.1 |
|
| 122 |
1.1 |
|
| 126 |
1.1 |
|
| 144 |
1.1 |
|
| 146 |
1.1 |
|
| 148 |
1.1 |