20 modularize the code to split up large classes (#21)
* MODULARIZE ClipService by introducing CompressionService, MetadataService, and ThumbnailService * ADD deleteClip functionality to ClipController
This commit is contained in:
@@ -9,6 +9,7 @@ import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.security.core.annotation.AuthenticationPrincipal;
|
||||
import org.springframework.security.oauth2.core.user.OAuth2User;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.web.bind.annotation.DeleteMapping;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
@@ -58,6 +59,23 @@ public class ClipController {
|
||||
);
|
||||
}
|
||||
|
||||
@DeleteMapping("/{id}")
|
||||
public ResponseEntity<APIResponse<String>> deleteClip(@AuthenticationPrincipal OAuth2User principal, @PathVariable Long id) {
|
||||
if (principal == null) {
|
||||
throw new NotAuthenticated("User is not authenticated");
|
||||
}
|
||||
|
||||
boolean deleted = clipService.deleteClip(id);
|
||||
|
||||
if (!deleted) {
|
||||
return ResponseEntity.notFound().build();
|
||||
}
|
||||
|
||||
return ResponseEntity.ok(
|
||||
new APIResponse<>("success", "Clip deleted successfully", "Clip with ID " + id + " has been deleted")
|
||||
);
|
||||
}
|
||||
|
||||
private ClipDTO convertToDTO(Clip clip) {
|
||||
ClipDTO dto = new ClipDTO();
|
||||
dto.setId(clip.getId());
|
||||
|
||||
Reference in New Issue
Block a user