Skip to content

Commit

Permalink
[#39] Modify videoservice
Browse files Browse the repository at this point in the history
Split video file and video infomation upload method
  • Loading branch information
SeongjinDaniel committed Dec 16, 2020
1 parent 02ef35f commit a13e5c4
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 22 deletions.
28 changes: 18 additions & 10 deletions src/main/java/me/dev/oliver/mytube/controller/VideoController.java
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
package me.dev.oliver.mytube.controller;

import java.io.IOException;
import javax.validation.Valid;
import lombok.AllArgsConstructor;
import me.dev.oliver.mytube.dto.VideoLikeDto;
import me.dev.oliver.mytube.dto.VideoUploadDto;
import me.dev.oliver.mytube.dto.VideoWatchDto;
import me.dev.oliver.mytube.service.VideoService;
import org.apache.ibatis.annotations.Delete;
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.PostMapping;
Expand All @@ -25,17 +23,27 @@ public class VideoController {
private final VideoService videoService;

/**
* 동영상 및 세부 사항 업로드
* 동영상 업로드
* 주의) uploadVideoInfo 메서드와 같이 사용해야함.
*
* @param multipartFile 동영상 파일을 및 userId, title, detail contents를 받아옴
* @param multipartFile 동영상 파일을 및 userId, title, detail contents를 받아옴.
*/
@PostMapping
public void uploadVideo(@RequestParam("fileVideo") MultipartFile multipartFile,
@Valid @RequestParam String userId,
@Valid @RequestParam String title,
@Valid @RequestParam String detailContents) throws IOException {
public void uploadVideo(@RequestParam("fileVideo") MultipartFile multipartFile) {

videoService.uploadVideo(multipartFile, userId, title, detailContents);
videoService.uploadVideo(multipartFile);
}

/**
* 동영상에 필요한 정보들을 업로드.
* 주의) uploadVideo 메서드와 같이 사용해야함.
*
* @param videoUploadDto userId, title, detailContents를 받아옴.
*/
@PostMapping("infos")
public void uploadVideoInfo(@Valid @RequestBody VideoUploadDto videoUploadDto) {

videoService.uploadDetailInfo(videoUploadDto);
}

/**
Expand Down
24 changes: 12 additions & 12 deletions src/main/java/me/dev/oliver/mytube/service/VideoService.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,16 +36,9 @@ public class VideoService {
* amazon s3에 동영상 업로드 및 file size는 byte 단위로 저장됨, 동영상 컨텐츠 내의 세부사항 기록 db에 저장.
*
* @param multipartFile 게시물 관련 정보를 담은 객체
* @param userId 회원 아이디
* @param title 동영상 제목
* @param detailContents 동영상에 대한 세부 내용
*/
@Transactional
@LoginValidation
public void uploadVideo(MultipartFile multipartFile,
String userId,
String title,
String detailContents) {
public void uploadVideo(MultipartFile multipartFile) {

String fileName = multipartFile.getOriginalFilename();

Expand All @@ -59,20 +52,27 @@ public void uploadVideo(MultipartFile multipartFile,
long fileSize = multipartFile.getSize();

VideoUploadDto videoUploadDto = VideoUploadDto.builder()
.userId(userId)
.title(title)
.detailContents(detailContents)
.fileUrl(fileUrl)
.fileSize(fileSize)
.build();
videoMapper.insertVideo(videoUploadDto);
videoMapper.insertDetailInfo(videoUploadDto);
} catch (RuntimeException e) {
log.error("uploadVideo 메서드에서 {} file 처리 중 에러가 발생했습니다. s3 활성화 유무와 관련 정보를 확인하십시오", fileName, e);
throw new IllegalStateException("서버에서 파일 처리중 예상치 못한 에러가 발생했습니다");
}
}

/**
* 동영상 파일과 관련된 세부 정보를 업로드.
*
* @param videoUploadDto userId, title, detailContents를 받아옴.
*/
@LoginValidation
public void uploadDetailInfo(VideoUploadDto videoUploadDto) {

videoMapper.insertDetailInfo(videoUploadDto);
}

/**
* 동영상 조회 특성상 여러 유저가 접근했을 때 데이터베이스에 데이터 요청 수를 줄이기 위해 caching을 사용.
* caching 할 때 key는 id를 사용, value는 getVideoInfo() 메서드의 return 값을 사용함.
Expand Down

0 comments on commit a13e5c4

Please sign in to comment.