diff --git a/src/main/java/com/ddf/vodsystem/controllers/ClipController.java b/src/main/java/com/ddf/vodsystem/controllers/ClipController.java index 7f5b506..82a31a4 100644 --- a/src/main/java/com/ddf/vodsystem/controllers/ClipController.java +++ b/src/main/java/com/ddf/vodsystem/controllers/ClipController.java @@ -3,11 +3,8 @@ package com.ddf.vodsystem.controllers; import com.ddf.vodsystem.dto.ClipDTO; import com.ddf.vodsystem.dto.APIResponse; import com.ddf.vodsystem.entities.Clip; -import com.ddf.vodsystem.exceptions.NotAuthenticated; import com.ddf.vodsystem.services.ClipService; import org.springframework.http.ResponseEntity; -import org.springframework.security.core.annotation.AuthenticationPrincipal; -import org.springframework.security.oauth2.core.user.OAuth2User; import org.springframework.web.bind.annotation.*; import java.util.List; @@ -17,6 +14,7 @@ import java.util.Optional; @RequestMapping("/api/v1/clips") public class ClipController { private final ClipService clipService; + private static final String SUCCESS = "success"; public ClipController(ClipService clipService) { this.clipService = clipService; @@ -30,7 +28,10 @@ public class ClipController { .toList(); return ResponseEntity.ok( - new APIResponse<>("success", "Clips retrieved successfully", clipDTOs) + new APIResponse<>(SUCCESS, + "Clips retrieved successfully", + clipDTOs + ) ); } @@ -44,24 +45,25 @@ public class ClipController { ClipDTO clipDTO = convertToDTO(clip.get()); return ResponseEntity.ok( - new APIResponse<>("success", "Clip retrieved successfully", clipDTO) + new APIResponse<>(SUCCESS, + "Clip retrieved successfully", + clipDTO + ) ); } @DeleteMapping("/{id}") - public ResponseEntity> deleteClip(@AuthenticationPrincipal OAuth2User principal, @PathVariable Long id) { - if (principal == null) { - throw new NotAuthenticated("User is not authenticated"); - } - - boolean deleted = clipService.deleteClip(id); - - if (!deleted) { + public ResponseEntity> deleteClip(@PathVariable Long id) { + if (!clipService.deleteClip(id)) { return ResponseEntity.notFound().build(); } return ResponseEntity.ok( - new APIResponse<>("success", "Clip deleted successfully", "Clip with ID " + id + " has been deleted") + new APIResponse<>( + SUCCESS, + "Clip deleted successfully", + "Clip with ID " + id + " has been deleted" + ) ); } diff --git a/src/main/java/com/ddf/vodsystem/controllers/DownloadController.java b/src/main/java/com/ddf/vodsystem/controllers/DownloadController.java index 6d99c7e..f91928c 100644 --- a/src/main/java/com/ddf/vodsystem/controllers/DownloadController.java +++ b/src/main/java/com/ddf/vodsystem/controllers/DownloadController.java @@ -7,8 +7,6 @@ import org.springframework.http.HttpHeaders; import org.springframework.http.MediaType; import org.springframework.http.MediaTypeFactory; import org.springframework.http.ResponseEntity; -import org.springframework.security.core.annotation.AuthenticationPrincipal; -import org.springframework.security.oauth2.core.user.OAuth2User; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.RequestMapping; @@ -18,6 +16,7 @@ import org.springframework.web.bind.annotation.RestController; @RequestMapping("api/v1/download") public class DownloadController { private final DownloadService downloadService; + private static final String FILENAME_HEADER = "inline; filename=\"%s\""; @Autowired public DownloadController(DownloadService downloadService) { @@ -33,7 +32,7 @@ public class DownloadController { } return ResponseEntity.ok() - .header(HttpHeaders.CONTENT_DISPOSITION, "inline; filename=\"" + resource.getFilename() + "\"") + .header(HttpHeaders.CONTENT_DISPOSITION, String.format(FILENAME_HEADER, resource.getFilename())) .contentType(MediaTypeFactory.getMediaType(resource).orElse(MediaType.APPLICATION_OCTET_STREAM)) .body(resource); } @@ -47,13 +46,13 @@ public class DownloadController { } return ResponseEntity.ok() - .header(HttpHeaders.CONTENT_DISPOSITION, "inline; filename=\"" + resource.getFilename() + "\"") + .header(HttpHeaders.CONTENT_DISPOSITION, String.format(FILENAME_HEADER, resource.getFilename())) .contentType(MediaTypeFactory.getMediaType(resource).orElse(MediaType.APPLICATION_OCTET_STREAM)) .body(resource); } @GetMapping("/clip/{id}") - public ResponseEntity downloadClip(@AuthenticationPrincipal OAuth2User principal, @PathVariable Long id) { + public ResponseEntity downloadClip(@PathVariable Long id) { Resource resource = downloadService.downloadClip(id); if (resource == null || !resource.exists()) { @@ -61,13 +60,13 @@ public class DownloadController { } return ResponseEntity.ok() - .header(HttpHeaders.CONTENT_DISPOSITION, "inline; filename=\"" + resource.getFilename() + "\"") + .header(HttpHeaders.CONTENT_DISPOSITION, String.format(FILENAME_HEADER, resource.getFilename())) .contentType(MediaTypeFactory.getMediaType(resource).orElse(MediaType.APPLICATION_OCTET_STREAM)) .body(resource); } @GetMapping("/thumbnail/{id}") - public ResponseEntity downloadThumbnail(@AuthenticationPrincipal OAuth2User principal, @PathVariable Long id) { + public ResponseEntity downloadThumbnail(@PathVariable Long id) { Resource resource = downloadService.downloadThumbnail(id); if (resource == null || !resource.exists()) { @@ -75,7 +74,7 @@ public class DownloadController { } return ResponseEntity.ok() - .header(HttpHeaders.CONTENT_DISPOSITION, "inline; filename=\"" + resource.getFilename() + "\"") + .header(HttpHeaders.CONTENT_DISPOSITION, String.format(FILENAME_HEADER, resource.getFilename())) .contentType(MediaTypeFactory.getMediaType(resource).orElse(MediaType.APPLICATION_OCTET_STREAM)) .body(resource); }