小视频功能开发 参考代码 controller


import com.tanhua.server.service.VideoService;
import com.tanhua.server.vo.PageResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.Map;




/*
  *    小视频功能  controller层
* */



@RestController
@RequestMapping("smallVideos")
public class VideoController {

 @Autowired
 private VideoService videoService;
 /**
 * 发布⼩视频
 *
 * @param picFile
 * @param videoFile
 * @return
 */
 @PostMapping
 public ResponseEntity saveVideo(@RequestParam("videoThumbnail")
MultipartFile picFile,
 @RequestParam("videoFile")
MultipartFile videoFile) {
 try {
 Boolean bool = this.videoService.saveVideo(picFile, videoFile);
 if (bool) {
 return ResponseEntity.ok(null);
 }
 } catch (Exception e) {
 e.printStackTrace();
 }
 return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).build();
 }





 /**
  * 查询⼩视频列表   controller
  *
  */
 @GetMapping
 public ResponseEntity queryVideoList(@RequestParam(value =
         "page", defaultValue = "1") Integer page,
                                                  @RequestParam(value =
                                                          "pagesize", defaultValue = "10") Integer pageSize) {
  try {
   if (page <= 0) {
    page = 1;
   }
   PageResult pageResult = this.videoService.queryVideoList(page,
           pageSize);
   if (null != pageResult) {
    return ResponseEntity.ok(pageResult);
   }
  } catch (Exception e) {
   e.printStackTrace();
  }
  return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).build();
 }





 /**
  * 视频点赞
  *
  * @param videoId 视频id
  * @return
  */
 @PostMapping("/{id}/like")
 public ResponseEntity likeComment(@PathVariable("id") String videoId) {
  try {
   Long likeCount = this.videoService.likeComment(videoId);
   if (likeCount != null) {
    return ResponseEntity.ok(likeCount);
   }
  } catch (Exception e) {
   e.printStackTrace();
  }
  return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).build();
 }

 /**
  * 取消点赞
  *
  * @param videoId
  * @return
  */
 @PostMapping("/{id}/dislike")
 public ResponseEntity disLikeComment(@PathVariable("id") String videoId) {
  try {
   Long likeCount = this.videoService.disLikeComment(videoId);
   if (null != likeCount) {
    return ResponseEntity.ok(likeCount);
   }
  } catch (Exception e) {
   e.printStackTrace();
  }
  return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).build();
 }






 /**
  * 评论列表
  */
 @GetMapping("/{id}/comments")
 public ResponseEntity queryCommentsList(@PathVariable("id") String videoId,
                                                     @RequestParam(value = "page", defaultValue = "1") Integer page,
                                                     @RequestParam(value = "pagesize", defaultValue = "10") Integer pageSize) {
  try {
   PageResult pageResult = this.videoService.queryCommentList(videoId, page, pageSize);
   return ResponseEntity.ok(pageResult);
  } catch (Exception e) {
   e.printStackTrace();
  }
  return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).build();
 }

 /**
  * 提交评论
  *
  * @param param
  * @param videoId
  * @return
  */
 @PostMapping("/{id}/comments")
 public ResponseEntity saveComments(@RequestBody Map param,
                                          @PathVariable("id") String videoId) {
  try {
   String content = param.get("comment");
   Boolean result = this.videoService.saveComment(videoId, content);
   if (result) {
    return ResponseEntity.ok(null);
   }
  } catch (Exception e) {
   e.printStackTrace();
  }
  return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).build();
 }

 /**
  * 评论点赞
  *
  * @param videoCommentId 视频中的评论id
  * @return
  */
 @PostMapping("/comments/{id}/like")
 public ResponseEntity commentsLikeComment(@PathVariable("id") String videoCommentId) {
  try {
   Long likeCount = this.videoService.likeComment(videoCommentId);
   if (likeCount != null) {
    return ResponseEntity.ok(likeCount);
   }
  } catch (Exception e) {
   e.printStackTrace();
  }
  return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).build();
 }

 /**
  * 评论取消点赞
  *
  * @param videoCommentId 视频中的评论id
  * @return
  */
 @PostMapping("/comments/{id}/dislike")
 public ResponseEntity disCommentsLikeComment(@PathVariable("id") String videoCommentId) {
  try {
   Long likeCount = this.videoService.disLikeComment(videoCommentId);
   if (null != likeCount) {
    return ResponseEntity.ok(likeCount);
   }
  } catch (Exception e) {
   e.printStackTrace();
  }
  return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).build();
 }



 /**
  * 视频用户关注    小视频
  */
 @PostMapping("/{id}/userFocus")
 public ResponseEntity saveUserFocusComments(@PathVariable("id") Long userId) {
  try {
   Boolean bool = this.videoService.followUser(userId);
   if (bool) {
    return ResponseEntity.ok(null);
   }
  } catch (Exception e) {
   e.printStackTrace();
  }
  return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).build();
 }

 /**
  * 取消视频用户关注    小视频
  */
 @PostMapping("/{id}/userUnFocus")
 public ResponseEntity saveUserUnFocusComments(@PathVariable("id") Long userId) {
  try {
   Boolean bool = this.videoService.disFollowUser(userId);
   if (bool) {
    return ResponseEntity.ok(null);
   }
  } catch (Exception e) {
   e.printStackTrace();
  }
  return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).build();
 }
}
发表评论
留言与评论(共有 0 条评论) “”
   
验证码:

相关文章

推荐文章