REMOVE unused authentication parameters

This commit is contained in:
2025-08-14 14:02:41 +02:00
parent 10ebcd5479
commit 85c9d4348c
2 changed files with 23 additions and 22 deletions

View File

@@ -3,11 +3,8 @@ package com.ddf.vodsystem.controllers;
import com.ddf.vodsystem.dto.ClipDTO; import com.ddf.vodsystem.dto.ClipDTO;
import com.ddf.vodsystem.dto.APIResponse; import com.ddf.vodsystem.dto.APIResponse;
import com.ddf.vodsystem.entities.Clip; import com.ddf.vodsystem.entities.Clip;
import com.ddf.vodsystem.exceptions.NotAuthenticated;
import com.ddf.vodsystem.services.ClipService; import com.ddf.vodsystem.services.ClipService;
import org.springframework.http.ResponseEntity; 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 org.springframework.web.bind.annotation.*;
import java.util.List; import java.util.List;
@@ -17,6 +14,7 @@ import java.util.Optional;
@RequestMapping("/api/v1/clips") @RequestMapping("/api/v1/clips")
public class ClipController { public class ClipController {
private final ClipService clipService; private final ClipService clipService;
private static final String SUCCESS = "success";
public ClipController(ClipService clipService) { public ClipController(ClipService clipService) {
this.clipService = clipService; this.clipService = clipService;
@@ -30,7 +28,10 @@ public class ClipController {
.toList(); .toList();
return ResponseEntity.ok( 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()); ClipDTO clipDTO = convertToDTO(clip.get());
return ResponseEntity.ok( return ResponseEntity.ok(
new APIResponse<>("success", "Clip retrieved successfully", clipDTO) new APIResponse<>(SUCCESS,
"Clip retrieved successfully",
clipDTO
)
); );
} }
@DeleteMapping("/{id}") @DeleteMapping("/{id}")
public ResponseEntity<APIResponse<String>> deleteClip(@AuthenticationPrincipal OAuth2User principal, @PathVariable Long id) { public ResponseEntity<APIResponse<String>> deleteClip(@PathVariable Long id) {
if (principal == null) { if (!clipService.deleteClip(id)) {
throw new NotAuthenticated("User is not authenticated");
}
boolean deleted = clipService.deleteClip(id);
if (!deleted) {
return ResponseEntity.notFound().build(); return ResponseEntity.notFound().build();
} }
return ResponseEntity.ok( 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"
)
); );
} }

View File

@@ -7,8 +7,6 @@ import org.springframework.http.HttpHeaders;
import org.springframework.http.MediaType; import org.springframework.http.MediaType;
import org.springframework.http.MediaTypeFactory; import org.springframework.http.MediaTypeFactory;
import org.springframework.http.ResponseEntity; 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.GetMapping;
import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
@@ -18,6 +16,7 @@ import org.springframework.web.bind.annotation.RestController;
@RequestMapping("api/v1/download") @RequestMapping("api/v1/download")
public class DownloadController { public class DownloadController {
private final DownloadService downloadService; private final DownloadService downloadService;
private static final String FILENAME_HEADER = "inline; filename=\"%s\"";
@Autowired @Autowired
public DownloadController(DownloadService downloadService) { public DownloadController(DownloadService downloadService) {
@@ -33,7 +32,7 @@ public class DownloadController {
} }
return ResponseEntity.ok() 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)) .contentType(MediaTypeFactory.getMediaType(resource).orElse(MediaType.APPLICATION_OCTET_STREAM))
.body(resource); .body(resource);
} }
@@ -47,13 +46,13 @@ public class DownloadController {
} }
return ResponseEntity.ok() 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)) .contentType(MediaTypeFactory.getMediaType(resource).orElse(MediaType.APPLICATION_OCTET_STREAM))
.body(resource); .body(resource);
} }
@GetMapping("/clip/{id}") @GetMapping("/clip/{id}")
public ResponseEntity<Resource> downloadClip(@AuthenticationPrincipal OAuth2User principal, @PathVariable Long id) { public ResponseEntity<Resource> downloadClip(@PathVariable Long id) {
Resource resource = downloadService.downloadClip(id); Resource resource = downloadService.downloadClip(id);
if (resource == null || !resource.exists()) { if (resource == null || !resource.exists()) {
@@ -61,13 +60,13 @@ public class DownloadController {
} }
return ResponseEntity.ok() 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)) .contentType(MediaTypeFactory.getMediaType(resource).orElse(MediaType.APPLICATION_OCTET_STREAM))
.body(resource); .body(resource);
} }
@GetMapping("/thumbnail/{id}") @GetMapping("/thumbnail/{id}")
public ResponseEntity<Resource> downloadThumbnail(@AuthenticationPrincipal OAuth2User principal, @PathVariable Long id) { public ResponseEntity<Resource> downloadThumbnail(@PathVariable Long id) {
Resource resource = downloadService.downloadThumbnail(id); Resource resource = downloadService.downloadThumbnail(id);
if (resource == null || !resource.exists()) { if (resource == null || !resource.exists()) {
@@ -75,7 +74,7 @@ public class DownloadController {
} }
return ResponseEntity.ok() 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)) .contentType(MediaTypeFactory.getMediaType(resource).orElse(MediaType.APPLICATION_OCTET_STREAM))
.body(resource); .body(resource);
} }