1.add collect controller and mock implement

main
Gary 1 year ago
parent be09572659
commit 8c3e8e0e3f

@ -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;
}
}

@ -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<Void> 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<Void> 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();
}
}

@ -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
}
}
Loading…
Cancel
Save