package com.ruoyi.user.controller;
|
|
|
import com.ruoyi.common.core.domain.R;
|
import com.ruoyi.common.security.service.TokenService;
|
import com.ruoyi.system.api.model.LoginUserInfo;
|
import com.ruoyi.user.entity.UserCollect;
|
import com.ruoyi.user.service.UserCollectService;
|
import com.ruoyi.user.vo.UserCollectVO;
|
import io.swagger.annotations.Api;
|
import io.swagger.annotations.ApiImplicitParam;
|
import io.swagger.annotations.ApiImplicitParams;
|
import io.swagger.annotations.ApiOperation;
|
import org.springframework.web.bind.annotation.GetMapping;
|
import org.springframework.web.bind.annotation.RequestMapping;
|
import org.springframework.web.bind.annotation.RequestParam;
|
import org.springframework.web.bind.annotation.RestController;
|
|
import javax.annotation.Resource;
|
import java.util.List;
|
|
/**
|
* <p>
|
* 用户收藏表 前端控制器
|
* </p>
|
*
|
* @author hjl
|
* @since 2024-06-07
|
*/
|
@RestController
|
@RequestMapping("/collect")
|
@Api(tags = {"用户端-收藏"})
|
public class UserCollectController {
|
|
@Resource
|
private UserCollectService userCollectService;
|
@Resource
|
private TokenService tokenService;
|
|
/**
|
* 获取服务详情
|
*/
|
@GetMapping(value = "/haveCollect")
|
@ApiOperation(value = "收藏", tags = {"用户端-收藏"})
|
@ApiImplicitParams({
|
@ApiImplicitParam(value = "服务id", name = "serveId", dataType = "Integer", required = true)
|
})
|
public R<Boolean> serveDetail(@RequestParam Integer serveId) {
|
LoginUserInfo loginUser = tokenService.getLoginUserByUser();
|
if (null == loginUser) {
|
return R.loginExpire("登录失效!");
|
}
|
UserCollect userCollect = new UserCollect(loginUser.getUserid(), serveId);
|
return R.ok(userCollectService.save(userCollect));
|
}
|
|
/**
|
* 取消收藏
|
*/
|
@GetMapping(value = "/cancelCollect")
|
@ApiOperation(value = "取消收藏", tags = {"用户端-收藏"})
|
@ApiImplicitParams({
|
@ApiImplicitParam(value = "收藏记录id", name = "collectId", dataType = "Integer", required = true)
|
})
|
public R<Boolean> cancelCollect(@RequestParam Integer collectId) {
|
LoginUserInfo loginUser = tokenService.getLoginUserByUser();
|
if (null == loginUser) {
|
return R.loginExpire("登录失效!");
|
}
|
return R.ok(userCollectService.lambdaUpdate().set(UserCollect::getIsDelete, 1)
|
.eq(UserCollect::getIsDelete, collectId).update());
|
}
|
|
/**
|
* 服务收藏列表
|
*/
|
@GetMapping(value = "/collectList")
|
@ApiOperation(value = "服务收藏列表", tags = {"用户端-收藏"})
|
public R<List<UserCollectVO>> collectList() {
|
LoginUserInfo loginUser = tokenService.getLoginUserByUser();
|
if (null == loginUser) {
|
return R.loginExpire("登录失效!");
|
}
|
List<UserCollectVO> collectList = userCollectService.collectList(loginUser.getUserid());
|
return R.ok(collectList);
|
}
|
|
|
}
|