From 8c3e8e0e3f4aa531de3b0cbfc0417b8338ec37e8 Mon Sep 17 00:00:00 2001 From: Gary Date: Thu, 18 Jan 2024 07:50:00 +0800 Subject: [PATCH] 1.add collect controller and mock implement --- .../src/main/java/enums/CollectTypeEnum.java | 30 ++++++++++ .../controller/UserCollectController.java | 58 +++++++++++++++++++ .../luoo/user/service/UserCollectService.java | 18 ++++++ 3 files changed, 106 insertions(+) create mode 100644 luoo_common/src/main/java/enums/CollectTypeEnum.java create mode 100644 luoo_user/src/main/java/com/luoo/user/controller/UserCollectController.java create mode 100644 luoo_user/src/main/java/com/luoo/user/service/UserCollectService.java diff --git a/luoo_common/src/main/java/enums/CollectTypeEnum.java b/luoo_common/src/main/java/enums/CollectTypeEnum.java new file mode 100644 index 0000000..50cbea4 --- /dev/null +++ b/luoo_common/src/main/java/enums/CollectTypeEnum.java @@ -0,0 +1,30 @@ +package enums; + +public enum CollectTypeEnum { + SONG(0, "歌曲"), JOURNAL(1, "期刊"); + + private Integer type; + private String description; + + CollectTypeEnum(int type, String description) { + this.type = type; + this.description = description; + } + + public Integer getType() { + return type; + } + + public String getDescription() { + return description; + } + + public static CollectTypeEnum getByType(Integer type) { + for (CollectTypeEnum at : CollectTypeEnum.values()) { + if (at.type.equals(type)) { + return at; + } + } + return null; + } +} diff --git a/luoo_user/src/main/java/com/luoo/user/controller/UserCollectController.java b/luoo_user/src/main/java/com/luoo/user/controller/UserCollectController.java new file mode 100644 index 0000000..08c3e91 --- /dev/null +++ b/luoo_user/src/main/java/com/luoo/user/controller/UserCollectController.java @@ -0,0 +1,58 @@ +package com.luoo.user.controller; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.DeleteMapping; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestHeader; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; + +import com.luoo.user.service.UserCollectService; + +import annotation.GlobalInterceptor; +import annotation.VerifyParam; +import api.Result; +import dto.UserLoginDto; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiImplicitParam; +import io.swagger.annotations.ApiImplicitParams; +import io.swagger.annotations.ApiOperation; +import util.JwtUtil; + +@Api(tags = "UserCollectController") +@RestController("userCollectController") +@RequestMapping("/userCollect") +public class UserCollectController { + @Autowired + private JwtUtil jwtUtil; + @Autowired + private UserCollectService userCollectService; + + @ApiOperation(value = "1.收藏/喜欢") + @ApiImplicitParams({ @ApiImplicitParam(name = "objectId", value = "收藏/喜欢的id,此处为歌曲/期刊id", required = true), + @ApiImplicitParam(name = "collectType", value = "收藏/喜欢的类型,0为歌曲,1为期刊", required = true) }) + @PostMapping("/addCollect") + @GlobalInterceptor(checkLogin = true) + public Result addCollect(@RequestHeader(value = "token", required = false) String token, + @VerifyParam(required = true) @RequestParam("objectId") String objectId, + @VerifyParam(required = true) @RequestParam("collectType") Integer collectType) { + UserLoginDto loginDto = jwtUtil.getUserLoginDto(token); + userCollectService.saveCollect(loginDto.getUserId(), objectId, collectType); + return Result.success(); + } + + @ApiOperation(value = "2.取消 收藏/喜欢") + @ApiImplicitParams({ @ApiImplicitParam(name = "objectId", value = "收藏/喜欢的id,此处为歌曲/期刊id", required = true), + @ApiImplicitParam(name = "collectType", value = "收藏/喜欢的类型,0为歌曲,1为期刊", required = true) }) + @DeleteMapping("/cancelCollect") + @GlobalInterceptor(checkLogin = true) + public Result cancelCollect(@RequestHeader(value = "token", required = false) String token, + @VerifyParam(required = true) @RequestParam("objectId") String objectId, + @VerifyParam(required = true) @RequestParam("collectType") Integer collectType) { + UserLoginDto loginDto = jwtUtil.getUserLoginDto(token); + userCollectService.deleteUserCollectByUserIdAndObjectIdAndCollectType(loginDto.getUserId(), objectId, + collectType); + return Result.success(); + } +} diff --git a/luoo_user/src/main/java/com/luoo/user/service/UserCollectService.java b/luoo_user/src/main/java/com/luoo/user/service/UserCollectService.java new file mode 100644 index 0000000..f5bab47 --- /dev/null +++ b/luoo_user/src/main/java/com/luoo/user/service/UserCollectService.java @@ -0,0 +1,18 @@ +package com.luoo.user.service; + +import org.springframework.stereotype.Service; + +@Service +public class UserCollectService { + + public void saveCollect(String userId, String objectId, Integer collectType) { + + } + + public void deleteUserCollectByUserIdAndObjectIdAndCollectType(String userId, String objectId, + Integer collectType) { + // TODO Auto-generated method stub + + } + +}