You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
111 lines
4.0 KiB
111 lines
4.0 KiB
package com.teaching.backend.controller.favour; |
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
|
import com.teaching.backend.common.BaseResponse; |
|
import com.teaching.backend.common.CommonResult; |
|
import com.teaching.backend.common.ErrorCode; |
|
import com.teaching.backend.common.ResultUtils; |
|
import com.teaching.backend.exception.BusinessException; |
|
import com.teaching.backend.model.dto.favour.courseFavour.CourseFavourAddRequest; |
|
import com.teaching.backend.model.dto.favour.courseFavour.CourseFavourAllRequest; |
|
import com.teaching.backend.model.dto.favour.courseFavour.CourseFavourQueryRequest; |
|
import com.teaching.backend.model.entity.courses.Courses; |
|
import com.teaching.backend.model.vo.courses.CoursesVO; |
|
import com.teaching.backend.model.vo.favour.CourseFavourDetailVO; |
|
import com.teaching.backend.service.favour.SeCourseFavourService; |
|
import io.swagger.annotations.ApiOperation; |
|
import lombok.extern.slf4j.Slf4j; |
|
import org.apache.commons.lang3.StringUtils; |
|
import org.springframework.web.bind.annotation.*; |
|
|
|
import javax.annotation.Resource; |
|
import java.util.List; |
|
|
|
/** |
|
* @Author:youhang |
|
* @Date:2024-05-30-20:22 |
|
* @Description: |
|
*/ |
|
@RestController |
|
@RequestMapping("/api/course_favour") |
|
@Slf4j |
|
public class SeCourseFavourController { |
|
|
|
@Resource |
|
private SeCourseFavourService seCourseFavourService; |
|
|
|
|
|
|
|
/** |
|
* 收藏/取消收藏 |
|
* |
|
* @param courseFavourAddRequest |
|
* @return result 执行情况 |
|
*/ |
|
@PostMapping("/add") |
|
// 加上 HttpServletRequest request 在一个fitter里面进行鉴权操作 |
|
public BaseResponse<Boolean> doFavour(@RequestBody CourseFavourAddRequest courseFavourAddRequest) { |
|
System.out.println(courseFavourAddRequest); |
|
//判断字段是否为空 |
|
if (StringUtils.isAnyBlank(courseFavourAddRequest.getCourseId(), courseFavourAddRequest.getUserId())) { |
|
throw new BusinessException(ErrorCode.PARAMS_ERROR); |
|
} |
|
|
|
return seCourseFavourService.doCourseFavour(courseFavourAddRequest.getCourseId(), courseFavourAddRequest.getUserId()); |
|
|
|
} |
|
|
|
|
|
/** |
|
* 课程点赞总数 |
|
* |
|
* @param courseFavourAddRequest |
|
* @return result 课程点赞总数 |
|
*/ |
|
@PostMapping("/count") |
|
// HttpServletRequest request 在一个fitter里面进行鉴权操作 |
|
public BaseResponse<Long> favourCount(@RequestBody CourseFavourAddRequest courseFavourAddRequest) { |
|
if (StringUtils.isAnyBlank(courseFavourAddRequest.getCourseId())) { |
|
throw new BusinessException(ErrorCode.PARAMS_ERROR, "请求参数不能为空"); |
|
} |
|
return seCourseFavourService.favourCount(courseFavourAddRequest.getCourseId()); |
|
} |
|
|
|
|
|
/** |
|
* 分页获取课程列表 |
|
* |
|
* @return |
|
*/ |
|
@PostMapping("/list/page") |
|
public BaseResponse<Page<CourseFavourDetailVO>> listPostByPage(@RequestBody CourseFavourQueryRequest courseFavourQueryRequest) { |
|
System.out.println(courseFavourQueryRequest); |
|
long current = courseFavourQueryRequest.getCurrent(); |
|
long size = courseFavourQueryRequest.getPageSize(); |
|
String userId = courseFavourQueryRequest.getUserId(); |
|
List<String> ids = seCourseFavourService.courseList(userId); |
|
QueryWrapper<Courses> courseQueryWrapper = new QueryWrapper<>(); |
|
courseQueryWrapper.in("id", ids); |
|
Page<CourseFavourDetailVO> courseFavourDetailVOPage = seCourseFavourService.listCourseFavourByPage(new Page<>(current, size), courseQueryWrapper); |
|
|
|
return ResultUtils.success(courseFavourDetailVOPage); |
|
} |
|
|
|
/** |
|
* 获取最新收藏的课程 |
|
* |
|
* @return |
|
*/ |
|
@ApiOperation("查询最新收藏") |
|
@PostMapping("/newCollect") |
|
public CommonResult<List<CoursesVO>> newCollect(@RequestParam String userId) { |
|
List<CoursesVO> newCoursesVO = seCourseFavourService.queryNewCollect(userId); |
|
if (newCoursesVO == null){ |
|
CommonResult.failed("用户或角色错误"); |
|
} |
|
return CommonResult.success(newCoursesVO); |
|
} |
|
|
|
} |
|
|
|
|