| 1 | package edu.ucsb.cs156.example.controllers; | |
| 2 | ||
| 3 | import edu.ucsb.cs156.example.entities.Article; | |
| 4 | import edu.ucsb.cs156.example.errors.EntityNotFoundException; | |
| 5 | import edu.ucsb.cs156.example.repositories.ArticleRepository; | |
| 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 java.time.LocalDateTime; | |
| 10 | import lombok.extern.slf4j.Slf4j; | |
| 11 | import org.springframework.beans.factory.annotation.Autowired; | |
| 12 | import org.springframework.format.annotation.DateTimeFormat; | |
| 13 | import org.springframework.http.HttpStatus; | |
| 14 | import org.springframework.http.ResponseEntity; | |
| 15 | import org.springframework.security.access.prepost.PreAuthorize; | |
| 16 | import org.springframework.web.bind.annotation.DeleteMapping; | |
| 17 | import org.springframework.web.bind.annotation.GetMapping; | |
| 18 | import org.springframework.web.bind.annotation.PostMapping; | |
| 19 | import org.springframework.web.bind.annotation.PutMapping; | |
| 20 | import org.springframework.web.bind.annotation.RequestBody; | |
| 21 | import org.springframework.web.bind.annotation.RequestMapping; | |
| 22 | import org.springframework.web.bind.annotation.RequestParam; | |
| 23 | import org.springframework.web.bind.annotation.RestController; | |
| 24 | ||
| 25 | @Tag(name = "Articles") | |
| 26 | @RequestMapping("/api/articles") | |
| 27 | @RestController | |
| 28 | @Slf4j | |
| 29 | public class ArticlesController extends ApiController { | |
| 30 | @Autowired private ArticleRepository articleRepository; | |
| 31 | ||
| 32 | @Operation(summary = "List all articles") | |
| 33 | @PreAuthorize("hasRole('ROLE_USER')") | |
| 34 | @GetMapping("/all") | |
| 35 | public Iterable<Article> allArticles() { | |
| 36 |
1
1. allArticles : replaced return value with Collections.emptyList for edu/ucsb/cs156/example/controllers/ArticlesController::allArticles → KILLED |
return articleRepository.findAll(); |
| 37 | } | |
| 38 | ||
| 39 | @Operation(summary = "Create a new article") | |
| 40 | @PreAuthorize("hasRole('ROLE_ADMIN')") | |
| 41 | @PostMapping("/post") | |
| 42 | public Article postArticle( | |
| 43 | @Parameter(name = "title") @RequestParam String title, | |
| 44 | @Parameter(name = "url") @RequestParam String url, | |
| 45 | @Parameter(name = "explanation") @RequestParam String explanation, | |
| 46 | @Parameter(name = "email") @RequestParam String email, | |
| 47 | @Parameter(name = "dateAdded", description = "ISO datetime, e.g. 2025-10-27T13:45:00") | |
| 48 | @RequestParam("dateAdded") | |
| 49 | @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME) | |
| 50 | LocalDateTime dateAdded) { | |
| 51 | Article a = new Article(); | |
| 52 |
1
1. postArticle : removed call to edu/ucsb/cs156/example/entities/Article::setTitle → KILLED |
a.setTitle(title); |
| 53 |
1
1. postArticle : removed call to edu/ucsb/cs156/example/entities/Article::setUrl → KILLED |
a.setUrl(url); |
| 54 |
1
1. postArticle : removed call to edu/ucsb/cs156/example/entities/Article::setExplanation → KILLED |
a.setExplanation(explanation); |
| 55 |
1
1. postArticle : removed call to edu/ucsb/cs156/example/entities/Article::setEmail → KILLED |
a.setEmail(email); |
| 56 |
1
1. postArticle : removed call to edu/ucsb/cs156/example/entities/Article::setDateAdded → KILLED |
a.setDateAdded(dateAdded); |
| 57 | ||
| 58 |
1
1. postArticle : replaced return value with null for edu/ucsb/cs156/example/controllers/ArticlesController::postArticle → KILLED |
return articleRepository.save(a); |
| 59 | } | |
| 60 | ||
| 61 | @Operation(summary = "Get a single article") | |
| 62 | @PreAuthorize("hasRole('ROLE_USER')") | |
| 63 | @GetMapping("") | |
| 64 | public Article getById(@Parameter(name = "id") @RequestParam Long id) { | |
| 65 |
1
1. getById : replaced return value with null for edu/ucsb/cs156/example/controllers/ArticlesController::getById → KILLED |
return articleRepository |
| 66 | .findById(id) | |
| 67 |
1
1. lambda$getById$0 : replaced return value with null for edu/ucsb/cs156/example/controllers/ArticlesController::lambda$getById$0 → KILLED |
.orElseThrow(() -> new EntityNotFoundException(Article.class, id)); |
| 68 | } | |
| 69 | ||
| 70 | @Operation(summary = "Update a single article") | |
| 71 | @PreAuthorize("hasRole('ROLE_ADMIN')") | |
| 72 | @PutMapping("") | |
| 73 | public Article updateArticleById( | |
| 74 | @Parameter(name = "id") @RequestParam Long id, @RequestBody Article incoming) { | |
| 75 | Article article = | |
| 76 | articleRepository | |
| 77 | .findById(id) | |
| 78 |
1
1. lambda$updateArticleById$1 : replaced return value with null for edu/ucsb/cs156/example/controllers/ArticlesController::lambda$updateArticleById$1 → KILLED |
.orElseThrow(() -> new EntityNotFoundException(Article.class, id)); |
| 79 | ||
| 80 |
1
1. updateArticleById : removed call to edu/ucsb/cs156/example/entities/Article::setTitle → KILLED |
article.setTitle(incoming.getTitle()); |
| 81 |
1
1. updateArticleById : removed call to edu/ucsb/cs156/example/entities/Article::setUrl → KILLED |
article.setUrl(incoming.getUrl()); |
| 82 |
1
1. updateArticleById : removed call to edu/ucsb/cs156/example/entities/Article::setExplanation → KILLED |
article.setExplanation(incoming.getExplanation()); |
| 83 |
1
1. updateArticleById : removed call to edu/ucsb/cs156/example/entities/Article::setEmail → KILLED |
article.setEmail(incoming.getEmail()); |
| 84 |
1
1. updateArticleById : removed call to edu/ucsb/cs156/example/entities/Article::setDateAdded → KILLED |
article.setDateAdded(incoming.getDateAdded()); |
| 85 | ||
| 86 |
1
1. updateArticleById : replaced return value with null for edu/ucsb/cs156/example/controllers/ArticlesController::updateArticleById → KILLED |
return articleRepository.save(article); |
| 87 | } | |
| 88 | ||
| 89 | @Operation(summary = "Delete a single article") | |
| 90 | @PreAuthorize("hasRole('ROLE_ADMIN')") | |
| 91 | @DeleteMapping("") | |
| 92 | public ResponseEntity<String> deleteArticleById(@Parameter(name = "id") @RequestParam Long id) { | |
| 93 | ||
| 94 |
1
1. deleteArticleById : replaced return value with null for edu/ucsb/cs156/example/controllers/ArticlesController::deleteArticleById → KILLED |
return articleRepository |
| 95 | .findById(id) | |
| 96 | .map( | |
| 97 | existing -> { | |
| 98 |
1
1. lambda$deleteArticleById$2 : removed call to edu/ucsb/cs156/example/repositories/ArticleRepository::delete → KILLED |
articleRepository.delete(existing); |
| 99 |
1
1. lambda$deleteArticleById$2 : replaced return value with null for edu/ucsb/cs156/example/controllers/ArticlesController::lambda$deleteArticleById$2 → KILLED |
return ResponseEntity.ok("record " + id + " deleted"); |
| 100 | }) | |
| 101 | .orElseGet( | |
| 102 |
1
1. lambda$deleteArticleById$3 : replaced return value with null for edu/ucsb/cs156/example/controllers/ArticlesController::lambda$deleteArticleById$3 → KILLED |
() -> ResponseEntity.status(HttpStatus.NOT_FOUND).body("record " + id + " not found")); |
| 103 | } | |
| 104 | } | |
Mutations | ||
| 36 |
1.1 |
|
| 52 |
1.1 |
|
| 53 |
1.1 |
|
| 54 |
1.1 |
|
| 55 |
1.1 |
|
| 56 |
1.1 |
|
| 58 |
1.1 |
|
| 65 |
1.1 |
|
| 67 |
1.1 |
|
| 78 |
1.1 |
|
| 80 |
1.1 |
|
| 81 |
1.1 |
|
| 82 |
1.1 |
|
| 83 |
1.1 |
|
| 84 |
1.1 |
|
| 86 |
1.1 |
|
| 94 |
1.1 |
|
| 98 |
1.1 |
|
| 99 |
1.1 |
|
| 102 |
1.1 |