collect/uncollect journal/song

main
wangqing 10 months ago
parent edfefa6271
commit 746660ca8f

@ -8,6 +8,7 @@ import java.nio.file.Paths;
import java.util.Date; import java.util.Date;
import java.util.EnumMap; import java.util.EnumMap;
import java.util.List; import java.util.List;
import java.util.Set;
import com.luoo.user.pojo.UserCollectInfo; import com.luoo.user.pojo.UserCollectInfo;
import com.luoo.user.service.UserCollectInfoService; import com.luoo.user.service.UserCollectInfoService;
@ -98,16 +99,16 @@ public class MyController extends BaseController{
} }
UserCollectInfo userCollectInfo = userCollectInfoService.findByUserId(userLoginDto.getUserId()); UserCollectInfo userCollectInfo = userCollectInfoService.findByUserId(userLoginDto.getUserId());
if(null!=userCollectInfo) { if(null!=userCollectInfo) {
List songList =userCollectInfo.getSongList(); Set songSet =userCollectInfo.getSongSet();
List journalList = userCollectInfo.getJournalList(); Set journalSet = userCollectInfo.getJournalSet();
userRespDTO.setJournalList(journalList); userRespDTO.setJournalSet(journalSet);
userRespDTO.setSongList(songList); userRespDTO.setSongSet(songSet);
if(null != songList){ if(null != songSet){
userRespDTO.setSongCount(songList.size()); userRespDTO.setSongCount(songSet.size());
} }
if(null != journalList) { if(null != journalSet) {
userRespDTO.setJournalCount(journalList.size()); userRespDTO.setJournalCount(journalSet.size());
} }
} }

@ -4,14 +4,19 @@ package com.luoo.user.controller;
import api.Result; import api.Result;
import com.luoo.user.pojo.UserCollectInfo; import com.luoo.user.pojo.UserCollectInfo;
import com.luoo.user.service.UserCollectInfoService; import com.luoo.user.service.UserCollectInfoService;
import controller.BaseController;
import dto.UserLoginDto;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
@RestController import javax.servlet.http.HttpServletRequest;
@RequestMapping("/UserCollectInfo")
public class UserCollectInfoController {
@RestController
@RequestMapping("/userCollectInfo")
public class UserCollectInfoController extends BaseController {
@Autowired
private HttpServletRequest request;
@Autowired @Autowired
private UserCollectInfoService userCollectInfoService; private UserCollectInfoService userCollectInfoService;
@ -27,11 +32,60 @@ public class UserCollectInfoController {
UserCollectInfo userCollectInfo =userCollectInfoService.findByUserId("111222"); UserCollectInfo userCollectInfo =userCollectInfoService.findByUserId("111222");
return Result.success(userCollectInfo); return Result.success(userCollectInfo);
} }
//
// @PutMapping("/unCollect")
// public Result unCollect() {
// userCollectInfoService.unCollect();
// return Result.success();
// }
/**
* typejournal typesong
*/
@PutMapping("/unCollect") @PostMapping("/collect/{type}/{id}")
public Result unCollect() { public Result collect(@PathVariable String type,@PathVariable String id) {
userCollectInfoService.unCollect(); //验证是否登录并且拿到ID
String token = (String) request.getAttribute("claims_user");
UserLoginDto userLoginDto = getUserLoginDto(token);
if (null == userLoginDto) {
return Result.unauthorized(null);
}
String userid = userLoginDto.getUserId();
if("journal".equals(type)) {
userCollectInfoService.collectJournal(userid,id);
}
if("song".equals(type)) {
userCollectInfoService.collectSong(userid,id);
}
return Result.success();
}
/**
* typejournal typesong
*/
@PostMapping("/unCollect/{type}/{id}")
public Result unCollect(@PathVariable String type,@PathVariable String id) {
//验证是否登录并且拿到ID
String token = (String) request.getAttribute("claims_user");
UserLoginDto userLoginDto = getUserLoginDto(token);
if (null == userLoginDto) {
return Result.unauthorized(null);
}
String userid = userLoginDto.getUserId();
if("journal".equals(type)) {
userCollectInfoService.unCollectJournal(userid,id);
}
if("song".equals(type)) {
userCollectInfoService.unCollectSong(userid,id);
}
return Result.success(); return Result.success();
} }
} }

@ -6,6 +6,7 @@ import io.swagger.annotations.ApiModelProperty;
import lombok.Data; import lombok.Data;
import java.util.List; import java.util.List;
import java.util.Set;
@Data @Data
public class UserRespDTO { public class UserRespDTO {
@ -30,11 +31,11 @@ public class UserRespDTO {
@ApiModelProperty(value = "喜欢歌曲数") @ApiModelProperty(value = "喜欢歌曲数")
private int songCount; private int songCount;
private List songList; private Set songSet;
@ApiModelProperty(value = "收藏期刊数") @ApiModelProperty(value = "收藏期刊数")
private int journalCount; private int journalCount;
private List journalList; private Set journalSet;
@ApiModelProperty(value = "获得评论数") @ApiModelProperty(value = "获得评论数")
private int commentReplyCount; private int commentReplyCount;
@ApiModelProperty(value = "生日,格式为: yyyy.MM.dd") @ApiModelProperty(value = "生日,格式为: yyyy.MM.dd")

@ -8,6 +8,7 @@ import org.springframework.format.annotation.DateTimeFormat;
import java.io.Serializable; import java.io.Serializable;
import java.util.Date; import java.util.Date;
import java.util.List; import java.util.List;
import java.util.Set;
@Data @Data
@ -29,12 +30,12 @@ public class UserCollectInfo implements Serializable {
/** /**
* *
*/ */
private List songList; private Set songSet;
/** /**
* *
*/ */
private List journalList; private Set journalSet;
} }

@ -9,10 +9,7 @@ import org.springframework.data.annotation.CreatedDate;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import util.IdWorker; import util.IdWorker;
import java.util.ArrayList; import java.util.*;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@Service @Service
public class UserCollectInfoService { public class UserCollectInfoService {
@ -38,7 +35,7 @@ public class UserCollectInfoService {
List list = new ArrayList(); List list = new ArrayList();
list.add(userCollectSongDto); list.add(userCollectSongDto);
list.add(userCollectSongDto1); list.add(userCollectSongDto1);
userCollectInfo.setSongList(list); // userCollectInfo.setSongList(list);
userCollectInfo.setCollectId(idWorker.nextId()+""); userCollectInfo.setCollectId(idWorker.nextId()+"");
userCollectInfo.setUserId("111222"); userCollectInfo.setUserId("111222");
userCollectInfoDao.save(userCollectInfo); userCollectInfoDao.save(userCollectInfo);
@ -50,12 +47,76 @@ public class UserCollectInfoService {
return userCollectInfoDao.findUserCollectInfoByUserId(userId); return userCollectInfoDao.findUserCollectInfoByUserId(userId);
} }
public void unCollect(){
UserCollectInfo userCollectInfo = userCollectInfoDao.findUserCollectInfoByUserId("111222"); public void collectSong(String userid, String id) {
UserCollectSongDto userCollectSongDto = new UserCollectSongDto();
userCollectSongDto.setName("smell like teensprit"); UserCollectInfo userCollectInfo = userCollectInfoDao.findUserCollectInfoByUserId(userid);
userCollectSongDto.setArtist("Nirvana"); if (null == userCollectInfo) {
userCollectInfo.getSongList().remove(userCollectSongDto); userCollectInfo = new UserCollectInfo();
userCollectInfoDao.save(userCollectInfo); userCollectInfo.setUserId(userid);
} Set songSet = new HashSet();
songSet.add(id);
userCollectInfo.setSongSet(songSet);
userCollectInfoDao.save(userCollectInfo);
} else {
Set songSet = userCollectInfo.getSongSet();
if(null == songSet) {
songSet = new HashSet<>();
}
songSet.add(id);
userCollectInfo.setSongSet(songSet);
userCollectInfoDao.save(userCollectInfo);
}
}
public void collectJournal(String userid, String id) {
UserCollectInfo userCollectInfo = userCollectInfoDao.findUserCollectInfoByUserId(userid);
if (null == userCollectInfo) {
userCollectInfo = new UserCollectInfo();
userCollectInfo.setUserId(userid);
Set journalSet = new HashSet();
journalSet.add(id);
userCollectInfo.setJournalSet(journalSet);
userCollectInfoDao.save(userCollectInfo);
} else {
Set journalSet =userCollectInfo.getJournalSet();
if(null== journalSet) {
journalSet = new HashSet();
}
journalSet.add(id);
userCollectInfo.setJournalSet(journalSet);
userCollectInfoDao.save(userCollectInfo);
}
}
/**
*
*/
public void unCollect(){
UserCollectInfo userCollectInfo = userCollectInfoDao.findUserCollectInfoByUserId("111222");
UserCollectSongDto userCollectSongDto = new UserCollectSongDto();
userCollectSongDto.setName("smell like teensprit");
userCollectSongDto.setArtist("Nirvana");
// userCollectInfo.getSongList().remove(userCollectSongDto);
userCollectInfoDao.save(userCollectInfo);
}
public void unCollectJournal(String userid, String id) {
UserCollectInfo userCollectInfo = userCollectInfoDao.findUserCollectInfoByUserId(userid);
userCollectInfo.getJournalSet().remove(id);
userCollectInfoDao.save(userCollectInfo);
}
public void unCollectSong(String userid, String id) {
UserCollectInfo userCollectInfo = userCollectInfoDao.findUserCollectInfoByUserId(userid);
userCollectInfo.getSongSet().remove(id);
userCollectInfoDao.save(userCollectInfo);
}
} }

Loading…
Cancel
Save