|
|
|
|
@ -0,0 +1,113 @@
|
|
|
|
|
// 定义包名
|
|
|
|
|
package com.macro.mall.portal.controller;
|
|
|
|
|
// 导入所需的类
|
|
|
|
|
import com.macro.mall.common.api.CommonPage;
|
|
|
|
|
import com.macro.mall.common.api.CommonResult;
|
|
|
|
|
import com.macro.mall.portal.domain.MemberProductCollection;
|
|
|
|
|
import com.macro.mall.portal.service.MemberCollectionService;
|
|
|
|
|
import io.swagger.annotations.Api;
|
|
|
|
|
import io.swagger.annotations.ApiOperation;
|
|
|
|
|
import io.swagger.v3.oas.annotations.tags.Tag;
|
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
|
import org.springframework.data.domain.Page;
|
|
|
|
|
import org.springframework.stereotype.Controller;
|
|
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 会员商品收藏管理Controller,用于处理会员商品收藏相关的请求。
|
|
|
|
|
* Created by macro on 2018/8/2.
|
|
|
|
|
*/
|
|
|
|
|
@Controller // 声明这是一个Spring MVC的控制器
|
|
|
|
|
@Api(tags = "MemberCollectionController") // Swagger注解,用于描述这个控制器的作用
|
|
|
|
|
@Tag(name = "MemberCollectionController",description = "会员收藏管理") // Swagger注解,定义控制器的标签和描述
|
|
|
|
|
@RequestMapping("/member/productCollection") // 定义这个控制器的基础请求路径
|
|
|
|
|
public class MemberProductCollectionController {
|
|
|
|
|
// 自动注入MemberCollectionService服务
|
|
|
|
|
@Autowired
|
|
|
|
|
private MemberCollectionService memberCollectionService;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 添加商品收藏的方法。
|
|
|
|
|
* @param productCollection 商品收藏对象
|
|
|
|
|
* @return 操作结果
|
|
|
|
|
*/
|
|
|
|
|
@ApiOperation("添加商品收藏") // Swagger注解,描述这个方法的作用
|
|
|
|
|
@RequestMapping(value = "/add", method = RequestMethod.POST) // 定义请求的路径和方法
|
|
|
|
|
@ResponseBody // 表示返回的数据直接写入响应体
|
|
|
|
|
public CommonResult add(@RequestBody MemberProductCollection productCollection) {
|
|
|
|
|
// 调用service层的方法添加商品收藏
|
|
|
|
|
int count = memberCollectionService.add(productCollection);
|
|
|
|
|
// 如果添加成功,返回成功结果
|
|
|
|
|
if (count > 0) {
|
|
|
|
|
return CommonResult.success(count);
|
|
|
|
|
} else {
|
|
|
|
|
// 如果添加失败,返回失败结果
|
|
|
|
|
return CommonResult.failed();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 删除商品收藏的方法。
|
|
|
|
|
* @param productId 要删除的商品收藏的ID
|
|
|
|
|
* @return 操作结果
|
|
|
|
|
*/
|
|
|
|
|
@ApiOperation("删除商品收藏") // Swagger注解,描述这个方法的作用
|
|
|
|
|
@RequestMapping(value = "/delete", method = RequestMethod.POST) // 定义请求的路径和方法
|
|
|
|
|
@ResponseBody // 表示返回的数据直接写入响应体
|
|
|
|
|
public CommonResult delete(Long productId) {
|
|
|
|
|
// 调用service层的方法删除商品收藏
|
|
|
|
|
int count = memberCollectionService.delete(productId);
|
|
|
|
|
// 如果删除成功,返回成功结果
|
|
|
|
|
if (count > 0) {
|
|
|
|
|
return CommonResult.success(count);
|
|
|
|
|
} else {
|
|
|
|
|
// 如果删除失败,返回失败结果
|
|
|
|
|
return CommonResult.failed();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 显示当前用户商品收藏列表的方法。
|
|
|
|
|
* @param pageNum 当前页码
|
|
|
|
|
* @param pageSize 每页显示的记录数
|
|
|
|
|
* @return 用户商品收藏列表
|
|
|
|
|
*/
|
|
|
|
|
@ApiOperation("显示当前用户商品收藏列表") // Swagger注解,描述这个方法的作用
|
|
|
|
|
@RequestMapping(value = "/list", method = RequestMethod.GET) // 定义请求的路径和方法
|
|
|
|
|
@ResponseBody // 表示返回的数据直接写入响应体
|
|
|
|
|
public CommonResult<CommonPage<MemberProductCollection>> list(@RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum,
|
|
|
|
|
@RequestParam(value = "pageSize", defaultValue = "5") Integer pageSize) {
|
|
|
|
|
// 调用service层的方法获取商品收藏列表
|
|
|
|
|
Page<MemberProductCollection> page = memberCollectionService.list(pageNum,pageSize);
|
|
|
|
|
// 返回商品收藏列表
|
|
|
|
|
return CommonResult.success(CommonPage.restPage(page));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 显示商品收藏详情的方法。
|
|
|
|
|
* @param productId 要查询的商品收藏的ID
|
|
|
|
|
* @return 商品收藏的详情
|
|
|
|
|
*/
|
|
|
|
|
@ApiOperation("显示商品收藏详情") // Swagger注解,描述这个方法的作用
|
|
|
|
|
@RequestMapping(value = "/detail", method = RequestMethod.GET) // 定义请求的路径和方法
|
|
|
|
|
@ResponseBody // 表示返回的数据直接写入响应体
|
|
|
|
|
public CommonResult<MemberProductCollection> detail(@RequestParam Long productId) {
|
|
|
|
|
// 调用service层的方法获取商品收藏详情
|
|
|
|
|
MemberProductCollection memberProductCollection = memberCollectionService.detail(productId);
|
|
|
|
|
// 返回商品收藏详情
|
|
|
|
|
return CommonResult.success(memberProductCollection);
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* 清空当前用户商品收藏列表的方法。
|
|
|
|
|
* @return 操作结果
|
|
|
|
|
*/
|
|
|
|
|
@ApiOperation("清空当前用户商品收藏列表") // Swagger注解,描述这个方法的作用
|
|
|
|
|
@RequestMapping(value = "/clear", method = RequestMethod.POST) // 定义请求的路径和方法
|
|
|
|
|
@ResponseBody // 表示返回的数据直接写入响应体
|
|
|
|
|
public CommonResult clear() {
|
|
|
|
|
// 调用service层的方法清空商品收藏列表
|
|
|
|
|
memberCollectionService.clear();
|
|
|
|
|
// 返回操作结果
|
|
|
|
|
return CommonResult.success(null);
|
|
|
|
|
}
|
|
|
|
|
}
|