Skip to content

Commit

Permalink
Merge pull request #11 from GC-Project-Space/feature/10
Browse files Browse the repository at this point in the history
[Feature/10]: video 조회기능
  • Loading branch information
luke0408 authored Nov 30, 2023
2 parents d2ed3c6 + 517c27f commit 6628189
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Tag(name = "Video", description = "Video 관련 API")
@Slf4j
@RequiredArgsConstructor
Expand All @@ -23,5 +25,18 @@ public class VideoController {

private final VideoService videoService;

@GetMapping("/Video/{id}")
public ResponseDto<String> getVideoUrlById(Long id){
String url = videoService.getVideoUrlById(id);

return ResponseDto.onSuccess(url);
}

@GetMapping("/getActiveVideoUrlInOrder")
public ResponseDto<List<String>>getActiveVideoUrlInOrder(){
List<String> activeVideoUrls = videoService.getActiveVideoUrlInOrder();

return ResponseDto.onSuccess(activeVideoUrls);
}

}
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
package com.example.streaming_service.domain.video.repository;

import com.example.streaming_service.domain.video.domain.Video;
import com.example.streaming_service.global.constant.Status;
import org.springframework.data.jpa.repository.JpaRepository;

import java.util.List;

public interface VideoRepository extends JpaRepository<Video, Long> {
List<Video> findByStatusOrderByCreatedAtDesc(Status status);

}
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
package com.example.streaming_service.domain.video.service;

import com.example.streaming_service.domain.video.domain.Video;
import com.example.streaming_service.domain.video.repository.VideoRepository;
import com.example.streaming_service.global.constant.Status;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.Comparator;
import java.util.List;
import java.util.stream.Collectors;

/**
* Service class for Example
*/
Expand All @@ -14,5 +20,18 @@
public class VideoService {
private final VideoRepository videoRepository;

public String getVideoUrlById(Long id){
Video video = videoRepository.findById(id).orElseThrow();

return video.getVideoUrl();
}

public List<String> getActiveVideoUrlInOrder(){
List<Video> videos = videoRepository.findByStatusOrderByCreatedAtDesc(Status.ACTIVE);

return videos.stream()
.map(Video::getVideoUrl)
.collect(Collectors.toList());
}

}

0 comments on commit 6628189

Please sign in to comment.