parent
ef622fbf95
commit
1fa68d070b
@ -0,0 +1,46 @@
|
|||||||
|
package cn.iocoder.mall.user.application.controller.users;
|
||||||
|
|
||||||
|
import cn.iocoder.common.framework.vo.CommonResult;
|
||||||
|
import cn.iocoder.mall.user.api.UserProductSpuCollectionsService;
|
||||||
|
import cn.iocoder.mall.user.api.bo.UserProductSpuCollectionsPageBO;
|
||||||
|
import cn.iocoder.mall.user.api.dto.UserProductSpuCollectionsPageDTO;
|
||||||
|
import cn.iocoder.mall.user.sdk.annotation.RequiresLogin;
|
||||||
|
import cn.iocoder.mall.user.sdk.context.UserSecurityContextHolder;
|
||||||
|
import io.swagger.annotations.Api;
|
||||||
|
import io.swagger.annotations.ApiOperation;
|
||||||
|
import org.apache.dubbo.config.annotation.Reference;
|
||||||
|
import org.springframework.validation.annotation.Validated;
|
||||||
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 用户收藏
|
||||||
|
* @author xiaofeng
|
||||||
|
* @date 2019/07/07 11:06
|
||||||
|
* @version 1.0
|
||||||
|
*/
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("users/favorite")
|
||||||
|
@Api("用户收藏")
|
||||||
|
public class UserFavoriteController {
|
||||||
|
|
||||||
|
@Reference(validation = "true", version = "${dubbo.provider.UserProductSpuCollectionsService.version}")
|
||||||
|
private UserProductSpuCollectionsService userProductSpuCollectionsService;
|
||||||
|
|
||||||
|
@GetMapping("page")
|
||||||
|
@RequiresLogin
|
||||||
|
@ApiOperation("用户商品收藏列表")
|
||||||
|
public CommonResult<UserProductSpuCollectionsPageBO> getUserProductSpuCollectionsPage(
|
||||||
|
@Validated UserProductSpuCollectionsPageDTO userProductSpuCollectionsPageDTO) {
|
||||||
|
final Integer userId = UserSecurityContextHolder.getContext().getUserId();
|
||||||
|
userProductSpuCollectionsPageDTO.setUserId(userId);
|
||||||
|
return userProductSpuCollectionsService.getUserProductSpuCollectionsPage(userProductSpuCollectionsPageDTO);
|
||||||
|
}
|
||||||
|
|
||||||
|
@DeleteMapping("remove")
|
||||||
|
@RequiresLogin
|
||||||
|
@ApiOperation(value = "用户商品收藏-删除")
|
||||||
|
public CommonResult<Boolean> removeFavorite(@RequestParam("spuId") final Integer spuId) {
|
||||||
|
final Integer userId = UserSecurityContextHolder.getContext().getUserId();
|
||||||
|
return userProductSpuCollectionsService.deleteUserProductSpuCollections(userId, spuId);
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,30 @@
|
|||||||
|
package cn.iocoder.mall.user.api.bo;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.experimental.Accessors;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 商品收藏分页
|
||||||
|
* @author xiaofeng
|
||||||
|
* @date 2019/07/06 18:37
|
||||||
|
* @version 1.0
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
@Accessors(chain = true)
|
||||||
|
public class UserProductSpuCollectionsPageBO implements Serializable {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 返回的数据列表
|
||||||
|
*/
|
||||||
|
private List<UserProductSpuCollectionsBO> list;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 总量
|
||||||
|
*/
|
||||||
|
private Integer total;
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,35 @@
|
|||||||
|
package cn.iocoder.mall.user.api.dto;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.experimental.Accessors;
|
||||||
|
|
||||||
|
import javax.validation.constraints.NotNull;
|
||||||
|
import java.io.Serializable;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 商品收藏分页参数
|
||||||
|
* @author xiaofeng
|
||||||
|
* @date 2019/07/06 18:40
|
||||||
|
* @version 1.0
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
@Accessors(chain = true)
|
||||||
|
public class UserProductSpuCollectionsPageDTO implements Serializable {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 用户ID
|
||||||
|
*/
|
||||||
|
private Integer userId;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 当前页
|
||||||
|
*/
|
||||||
|
@NotNull(message = "页码不能为空")
|
||||||
|
private Integer pageNo;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 每页显示的条数
|
||||||
|
*/
|
||||||
|
@NotNull(message = "每页条数不能为空")
|
||||||
|
private Integer pageSize;
|
||||||
|
}
|
||||||
@ -0,0 +1,42 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||||
|
<mapper namespace="cn.iocoder.mall.user.biz.dao.UserProductSpuCollectionsMapper">
|
||||||
|
|
||||||
|
<sql id="FIELDS">
|
||||||
|
id, user_id, nickname, spu_id, spu_name,
|
||||||
|
spu_image, create_time, update_time,
|
||||||
|
deleted
|
||||||
|
</sql>
|
||||||
|
|
||||||
|
<select id="selectById" parameterType="Integer" resultType="cn.iocoder.mall.user.biz.dataobject.UserProductSpuCollectionsDO">
|
||||||
|
SELECT
|
||||||
|
<include refid="FIELDS" />
|
||||||
|
FROM user_spu_collections
|
||||||
|
WHERE id = #{id}
|
||||||
|
AND deleted = 0
|
||||||
|
</select>
|
||||||
|
|
||||||
|
|
||||||
|
<select id="selectListByUser" resultType="cn.iocoder.mall.user.biz.dataobject.UserProductSpuCollectionsDO">
|
||||||
|
SELECT
|
||||||
|
<include refid="FIELDS" />
|
||||||
|
FROM user_spu_collections
|
||||||
|
<where>
|
||||||
|
user_id = #{userId} AND deleted = 0
|
||||||
|
</where>
|
||||||
|
ORDER BY sort ASC
|
||||||
|
<if test="offset != null and limit != null">
|
||||||
|
LIMIT #{offset}, #{limit}
|
||||||
|
</if>
|
||||||
|
</select>
|
||||||
|
|
||||||
|
<select id="selectCountByUser" resultType="Integer">
|
||||||
|
SELECT
|
||||||
|
COUNT(1)
|
||||||
|
FROM user_spu_collections
|
||||||
|
<where>
|
||||||
|
user_id = #{userId} AND deleted = 0
|
||||||
|
</where>
|
||||||
|
</select>
|
||||||
|
|
||||||
|
</mapper>
|
||||||
Loading…
Reference in new issue