| 1 | package com.edtech.controller; | |
| 2 | ||
| 3 | import com.edtech.dto.DocumentResponseDto; | |
| 4 | import com.edtech.model.User; | |
| 5 | import com.edtech.service.AuditExportService; | |
| 6 | import com.edtech.service.DocumentService; | |
| 7 | import java.util.UUID; | |
| 8 | import org.springframework.data.domain.Page; | |
| 9 | import org.springframework.data.domain.Pageable; | |
| 10 | import org.springframework.data.web.PageableDefault; | |
| 11 | import org.springframework.http.HttpHeaders; | |
| 12 | import org.springframework.http.HttpStatus; | |
| 13 | import org.springframework.http.MediaType; | |
| 14 | import org.springframework.http.ResponseEntity; | |
| 15 | import org.springframework.security.core.Authentication; | |
| 16 | import org.springframework.web.bind.annotation.DeleteMapping; | |
| 17 | import org.springframework.web.bind.annotation.GetMapping; | |
| 18 | import org.springframework.web.bind.annotation.PatchMapping; | |
| 19 | import org.springframework.web.bind.annotation.PathVariable; | |
| 20 | import org.springframework.web.bind.annotation.PostMapping; | |
| 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 | import org.springframework.web.multipart.MultipartFile; | |
| 26 | ||
| 27 | /** Documentacao para DocumentController. */ | |
| 28 | @RestController | |
| 29 | @RequestMapping("/api/documents") | |
| 30 | public class DocumentController { | |
| 31 | ||
| 32 | private final DocumentService documentService; | |
| 33 | private final AuditExportService auditExportService; | |
| 34 | ||
| 35 | /** Documentacao para o metodo DocumentController. */ | |
| 36 | public DocumentController( | |
| 37 | DocumentService documentService, AuditExportService auditExportService) { | |
| 38 | this.documentService = documentService; | |
| 39 | this.auditExportService = auditExportService; | |
| 40 | } | |
| 41 | ||
| 42 | /** Documentacao. */ | |
| 43 | @PostMapping(consumes = "multipart/form-data") | |
| 44 | public ResponseEntity<DocumentResponseDto> uploadDocument( | |
| 45 | @RequestParam("file") MultipartFile file, | |
| 46 | @RequestParam("title") String title, | |
| 47 | @RequestParam("projectId") UUID projectId, | |
| 48 | Authentication authentication) { | |
| 49 | User user = (User) authentication.getPrincipal(); | |
| 50 |
1
1. uploadDocument : replaced return value with null for com/edtech/controller/DocumentController::uploadDocument → KILLED |
return ResponseEntity.status(HttpStatus.CREATED) |
| 51 | .body(documentService.uploadDocument(file, title, projectId, user.getId())); | |
| 52 | } | |
| 53 | ||
| 54 | /** Documentacao. */ | |
| 55 | @GetMapping | |
| 56 | public ResponseEntity<Page<DocumentResponseDto>> listDocuments( | |
| 57 | @RequestParam(required = false) UUID projectId, | |
| 58 | @RequestParam(required = false) String title, | |
| 59 | @RequestParam(required = false) com.edtech.model.DocumentStatus status, | |
| 60 | @PageableDefault(size = 20) Pageable pageable, | |
| 61 | Authentication authentication) { | |
| 62 | User user = (User) authentication.getPrincipal(); | |
| 63 |
1
1. listDocuments : replaced return value with null for com/edtech/controller/DocumentController::listDocuments → SURVIVED |
return ResponseEntity.ok( |
| 64 | documentService.listDocumentsByUser(user.getId(), projectId, title, status, pageable)); | |
| 65 | } | |
| 66 | ||
| 67 | @GetMapping("/{id}/download") | |
| 68 | public ResponseEntity<String> downloadDocument( | |
| 69 | @PathVariable UUID id, Authentication authentication) { | |
| 70 | User user = (User) authentication.getPrincipal(); | |
| 71 |
1
1. downloadDocument : replaced return value with null for com/edtech/controller/DocumentController::downloadDocument → KILLED |
return ResponseEntity.ok(documentService.getPresignedUrl(id, user.getId())); |
| 72 | } | |
| 73 | ||
| 74 | /** Exporta a trilha de auditoria de um documento em arquivo CSV. */ | |
| 75 | @GetMapping("/{id}/audit/export") | |
| 76 | public ResponseEntity<byte[]> exportAuditTrail( | |
| 77 | @PathVariable UUID id, | |
| 78 | @RequestParam(defaultValue = "csv") String format, | |
| 79 | Authentication authentication) { | |
| 80 | User user = (User) authentication.getPrincipal(); | |
| 81 | byte[] file = auditExportService.exportDocumentAuditTrail(id, user.getId(), format); | |
| 82 | String filename = auditExportService.buildFilename(id, format); | |
| 83 | ||
| 84 |
1
1. exportAuditTrail : replaced return value with null for com/edtech/controller/DocumentController::exportAuditTrail → KILLED |
return ResponseEntity.ok() |
| 85 | .header(HttpHeaders.CONTENT_DISPOSITION, "attachment; filename=\"" + filename + "\"") | |
| 86 | .contentType(MediaType.parseMediaType("text/csv")) | |
| 87 | .body(file); | |
| 88 | } | |
| 89 | ||
| 90 | /** Documentacao. */ | |
| 91 | @DeleteMapping("/{id}") | |
| 92 | public ResponseEntity<Void> deleteDocument(@PathVariable UUID id, Authentication authentication) { | |
| 93 | User user = (User) authentication.getPrincipal(); | |
| 94 |
1
1. deleteDocument : removed call to com/edtech/service/DocumentService::deleteDocument → SURVIVED |
documentService.deleteDocument(id, user.getId()); |
| 95 |
1
1. deleteDocument : replaced return value with null for com/edtech/controller/DocumentController::deleteDocument → KILLED |
return ResponseEntity.noContent().build(); |
| 96 | } | |
| 97 | ||
| 98 | /** Documentacao. */ | |
| 99 | @PatchMapping("/{id}/status") | |
| 100 | public ResponseEntity<DocumentResponseDto> updateDocumentStatus( | |
| 101 | @PathVariable UUID id, | |
| 102 | @RequestBody com.edtech.dto.DocumentStatusUpdateDto dto, | |
| 103 | Authentication authentication) { | |
| 104 | User user = (User) authentication.getPrincipal(); | |
| 105 | DocumentResponseDto response = | |
| 106 | documentService.reviewDocument(id, user.getId(), dto.getStatus(), dto.getFeedback()); | |
| 107 |
1
1. updateDocumentStatus : replaced return value with null for com/edtech/controller/DocumentController::updateDocumentStatus → SURVIVED |
return ResponseEntity.ok(response); |
| 108 | } | |
| 109 | ||
| 110 | @PatchMapping("/{id}/star") | |
| 111 | public ResponseEntity<DocumentResponseDto> toggleStar( | |
| 112 | @PathVariable UUID id, Authentication authentication) { | |
| 113 | User user = (User) authentication.getPrincipal(); | |
| 114 |
1
1. toggleStar : replaced return value with null for com/edtech/controller/DocumentController::toggleStar → SURVIVED |
return ResponseEntity.ok(documentService.toggleStar(id, user.getId())); |
| 115 | } | |
| 116 | ||
| 117 | @GetMapping("/{id}/comments") | |
| 118 | public ResponseEntity<java.util.List<com.edtech.dto.CommentResponseDto>> getComments( | |
| 119 | @PathVariable UUID id, Authentication authentication) { | |
| 120 | User user = (User) authentication.getPrincipal(); | |
| 121 |
1
1. getComments : replaced return value with null for com/edtech/controller/DocumentController::getComments → SURVIVED |
return ResponseEntity.ok(documentService.getComments(id, user.getId())); |
| 122 | } | |
| 123 | ||
| 124 | /** Javadoc. */ | |
| 125 | @PostMapping("/{id}/comments") | |
| 126 | public ResponseEntity<com.edtech.dto.CommentResponseDto> addComment( | |
| 127 | @PathVariable UUID id, | |
| 128 | @jakarta.validation.Valid @RequestBody com.edtech.dto.CommentRequestDto dto, | |
| 129 | Authentication authentication) { | |
| 130 | User user = (User) authentication.getPrincipal(); | |
| 131 |
1
1. addComment : replaced return value with null for com/edtech/controller/DocumentController::addComment → KILLED |
return ResponseEntity.status(HttpStatus.CREATED) |
| 132 | .body(documentService.addComment(id, user.getId(), dto.getContent())); | |
| 133 | } | |
| 134 | } | |
Mutations | ||
| 50 |
1.1 |
|
| 63 |
1.1 |
|
| 71 |
1.1 |
|
| 84 |
1.1 |
|
| 94 |
1.1 |
|
| 95 |
1.1 |
|
| 107 |
1.1 |
|
| 114 |
1.1 |
|
| 121 |
1.1 |
|
| 131 |
1.1 |