Skip to content

Commit

Permalink
Add controller to load video data by ids and update service layer
Browse files Browse the repository at this point in the history
  • Loading branch information
leingenm committed Aug 10, 2024
1 parent 733c8b6 commit b44bdd5
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 7 deletions.
14 changes: 10 additions & 4 deletions src/main/java/com/ypm/controller/VideoController.java
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
package com.ypm.controller;

import com.ypm.dto.VideoDto;
import com.ypm.service.TokenService;
import com.ypm.service.VideoService;
import lombok.RequiredArgsConstructor;
import org.springframework.http.ResponseEntity;
import org.springframework.security.oauth2.client.OAuth2AuthorizedClient;
import org.springframework.security.oauth2.client.annotation.RegisteredOAuth2AuthorizedClient;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.*;

import java.io.IOException;
import java.util.List;

@RestController
@RequestMapping("/videos")
Expand All @@ -21,6 +20,13 @@ public class VideoController {
private final VideoService videosService;
private final TokenService tokenService;

@PostMapping("/videoData")
public ResponseEntity<List<VideoDto>> getVideoData(@RequestBody List<String> videoIds) throws IOException {
var videoData = videosService.getVideoData(videoIds);

return ResponseEntity.ok(videoData);
}

@DeleteMapping("/{videoId}")
public ResponseEntity<Void> deleteVideos(
@RegisteredOAuth2AuthorizedClient OAuth2AuthorizedClient authClient,
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/ypm/service/VideoService.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,5 @@ List<PlaylistItem> getPlayListVideos(String accessToken,

void deleteVideo(String accessToken, String videoId) throws IOException;

List<VideoDto> getVideoData(String accessToken, List<String> videoIds) throws IOException;
List<VideoDto> getVideoData(List<String> videoIds) throws IOException;
}
5 changes: 3 additions & 2 deletions src/main/java/com/ypm/service/VideoServiceImp.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
public class VideoServiceImp implements VideoService {

private final YouTube youTubeClient;
private final TokenService tokenService;

@Override
public List<PlaylistItem> moveVideos(String accessToken,
Expand Down Expand Up @@ -70,12 +71,12 @@ public void deleteVideo(String accessToken, String videoId) throws IOException {
}

@Override
public List<VideoDto> getVideoData(String accessToken, List<String> videoIds) throws IOException {
public List<VideoDto> getVideoData(List<String> videoIds) throws IOException {
var items = youTubeClient
.videos()
.list(List.of(Part.SNIPPET.toString(), Part.CONTENT_DETAILS.toString()))
.setId(videoIds)
.setAccessToken(accessToken)
.setAccessToken(tokenService.getAccessToken())
.execute()
.getItems();

Expand Down

0 comments on commit b44bdd5

Please sign in to comment.