feat(backend): Add user notifications and public video APIs
This commit is contained in:
@@ -4,6 +4,7 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|||||||
import com.nuaa.video.common.model.vo.Result;
|
import com.nuaa.video.common.model.vo.Result;
|
||||||
import com.nuaa.video.content.dto.*;
|
import com.nuaa.video.content.dto.*;
|
||||||
import com.nuaa.video.content.entity.ContentVideo;
|
import com.nuaa.video.content.entity.ContentVideo;
|
||||||
|
import com.nuaa.video.content.mapper.ContentVideoMapper;
|
||||||
import com.nuaa.video.content.service.VideoService;
|
import com.nuaa.video.content.service.VideoService;
|
||||||
import com.nuaa.video.content.vo.UploadResultVO;
|
import com.nuaa.video.content.vo.UploadResultVO;
|
||||||
import com.nuaa.video.content.vo.VideoInfoVO;
|
import com.nuaa.video.content.vo.VideoInfoVO;
|
||||||
@@ -25,6 +26,7 @@ import org.springframework.web.multipart.MultipartFile;
|
|||||||
public class VideoController {
|
public class VideoController {
|
||||||
|
|
||||||
private final VideoService videoService;
|
private final VideoService videoService;
|
||||||
|
private final ContentVideoMapper videoMapper;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 上传视频
|
* 上传视频
|
||||||
@@ -50,6 +52,29 @@ public class VideoController {
|
|||||||
return videoService.createVideo(uploadDTO, userId);
|
return videoService.createVideo(uploadDTO, userId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取视频详情(公开接口)
|
||||||
|
*/
|
||||||
|
@GetMapping("/public/{id}")
|
||||||
|
public Result<VideoInfoVO> getVideoInfoPublic(@PathVariable Long id, HttpServletRequest request) {
|
||||||
|
Long userId = getUserIdFromRequest(request);
|
||||||
|
return videoService.getVideoInfo(id, userId);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取视频列表(公开接口)
|
||||||
|
*/
|
||||||
|
@GetMapping("/public/list")
|
||||||
|
public Result<Page<VideoListVO>> getVideoListPublic(
|
||||||
|
@RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum,
|
||||||
|
@RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize,
|
||||||
|
VideoQueryDTO queryDTO,
|
||||||
|
HttpServletRequest request) {
|
||||||
|
Page<ContentVideo> page = new Page<>(pageNum, pageSize);
|
||||||
|
Long userId = getUserIdFromRequest(request);
|
||||||
|
return videoService.getVideoList(page, queryDTO, userId);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取视频详情
|
* 获取视频详情
|
||||||
*/
|
*/
|
||||||
@@ -217,6 +242,35 @@ public class VideoController {
|
|||||||
return videoService.reviewVideo(videoId, reviewerId, status, reason);
|
return videoService.reviewVideo(videoId, reviewerId, status, reason);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 增加视频评论数量
|
||||||
|
*/
|
||||||
|
@PostMapping("/count/comment/{videoId}/{count}")
|
||||||
|
public Result<Void> increaseCommentCount(
|
||||||
|
@PathVariable Long videoId,
|
||||||
|
@PathVariable Integer count,
|
||||||
|
HttpServletRequest request) {
|
||||||
|
// 验证权限(实际可以根据需要添加更复杂的权限验证)
|
||||||
|
Long userId = getUserIdFromRequest(request);
|
||||||
|
if (userId == null) {
|
||||||
|
return Result.error("未登录");
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
ContentVideo video = videoService.getById(videoId);
|
||||||
|
if (video == null) {
|
||||||
|
return Result.error("视频不存在");
|
||||||
|
}
|
||||||
|
|
||||||
|
// 更新评论数
|
||||||
|
videoMapper.increaseCommentCount(videoId, count);
|
||||||
|
return Result.success();
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error("增加视频评论数失败,videoId={},count={}", videoId, count, e);
|
||||||
|
return Result.error("更新视频评论数失败");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 从请求中获取用户ID
|
* 从请求中获取用户ID
|
||||||
*/
|
*/
|
||||||
|
|||||||
+58
@@ -10,6 +10,8 @@ import lombok.RequiredArgsConstructor;
|
|||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 用户通知控制器
|
* 用户通知控制器
|
||||||
*/
|
*/
|
||||||
@@ -74,6 +76,62 @@ public class UserNotificationController {
|
|||||||
return userNotificationService.getUnreadNotificationCount(userId);
|
return userNotificationService.getUnreadNotificationCount(userId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 发送用户通知
|
||||||
|
*/
|
||||||
|
@PostMapping("/send/{userId}/{type}")
|
||||||
|
public Result<Void> sendNotification(
|
||||||
|
@PathVariable("userId") Long userId,
|
||||||
|
@PathVariable("type") Integer type,
|
||||||
|
@RequestParam(required = false) String content,
|
||||||
|
@RequestParam(required = false) Long relatedId,
|
||||||
|
HttpServletRequest request) {
|
||||||
|
// 验证调用者身份
|
||||||
|
Long currentUserId = getUserIdFromRequest(request);
|
||||||
|
if (currentUserId == null) {
|
||||||
|
return Result.error("未登录");
|
||||||
|
}
|
||||||
|
|
||||||
|
// 创建通知对象
|
||||||
|
UserNotification notification = new UserNotification();
|
||||||
|
notification.setUserId(userId);
|
||||||
|
notification.setType(type);
|
||||||
|
|
||||||
|
// 设置通知内容
|
||||||
|
String notificationContent;
|
||||||
|
if (content != null && !content.isEmpty()) {
|
||||||
|
notificationContent = content;
|
||||||
|
} else {
|
||||||
|
// 根据类型生成默认内容
|
||||||
|
switch (type) {
|
||||||
|
case 1: // 点赞
|
||||||
|
notificationContent = "有人赞了你的内容";
|
||||||
|
break;
|
||||||
|
case 2: // 评论
|
||||||
|
notificationContent = "有人评论了你的内容";
|
||||||
|
break;
|
||||||
|
case 3: // 关注
|
||||||
|
notificationContent = "有人关注了你";
|
||||||
|
break;
|
||||||
|
case 4: // 系统通知
|
||||||
|
notificationContent = "系统通知";
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
notificationContent = "新通知";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
notification.setContent(notificationContent);
|
||||||
|
|
||||||
|
notification.setRelatedId(relatedId);
|
||||||
|
notification.setIsRead(0); // 未读
|
||||||
|
notification.setCreateTime(LocalDateTime.now());
|
||||||
|
|
||||||
|
// 保存通知
|
||||||
|
userNotificationService.save(notification);
|
||||||
|
|
||||||
|
return Result.success();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 从请求中获取用户ID
|
* 从请求中获取用户ID
|
||||||
*/
|
*/
|
||||||
|
|||||||
Reference in New Issue
Block a user