package com.ruoyi.user.controller; import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; 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; /** *

* 用户收藏表 前端控制器 *

* * @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 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 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> collectList(@RequestParam(name = "pageNum", defaultValue = "1") Integer pageNum, @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize) { LoginUserInfo loginUser = tokenService.getLoginUserByUser(); if (null == loginUser) { return R.loginExpire("登录失效!"); } IPage collectList = userCollectService.collectList(loginUser.getUserid(), Page.of(pageNum, pageSize)); return R.ok(collectList); } /** * 服务收藏列表 */ @GetMapping(value = "/detailHaveCollect") @ApiOperation(value = "服务详情取消/添加收藏", tags = {"用户端-收藏"}) public R> collectList(@RequestParam Integer serveId) { LoginUserInfo loginUser = tokenService.getLoginUserByUser(); if (null == loginUser) { return R.loginExpire("登录失效!"); } // IPage collectList = userCollectService.collectList(loginUser.getUserid()); return R.ok(); } }