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

@ -4,14 +4,19 @@ package com.luoo.user.controller;
import api.Result;
import com.luoo.user.pojo.UserCollectInfo;
import com.luoo.user.service.UserCollectInfoService;
import controller.BaseController;
import dto.UserLoginDto;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
@RestController
@RequestMapping("/UserCollectInfo")
public class UserCollectInfoController {
import javax.servlet.http.HttpServletRequest;
@RestController
@RequestMapping("/userCollectInfo")
public class UserCollectInfoController extends BaseController {
@Autowired
private HttpServletRequest request;
@Autowired
private UserCollectInfoService userCollectInfoService;
@ -27,11 +32,60 @@ public class UserCollectInfoController {
UserCollectInfo userCollectInfo =userCollectInfoService.findByUserId("111222");
return Result.success(userCollectInfo);
}
//
// @PutMapping("/unCollect")
// public Result unCollect() {
// userCollectInfoService.unCollect();
// return Result.success();
// }
/**
* typejournal typesong
*/
@PutMapping("/unCollect")
public Result unCollect() {
userCollectInfoService.unCollect();
@PostMapping("/collect/{type}/{id}")
public Result collect(@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.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();
}
}

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

@ -8,6 +8,7 @@ import org.springframework.format.annotation.DateTimeFormat;
import java.io.Serializable;
import java.util.Date;
import java.util.List;
import java.util.Set;
@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 util.IdWorker;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.*;
@Service
public class UserCollectInfoService {
@ -38,7 +35,7 @@ public class UserCollectInfoService {
List list = new ArrayList();
list.add(userCollectSongDto);
list.add(userCollectSongDto1);
userCollectInfo.setSongList(list);
// userCollectInfo.setSongList(list);
userCollectInfo.setCollectId(idWorker.nextId()+"");
userCollectInfo.setUserId("111222");
userCollectInfoDao.save(userCollectInfo);
@ -50,12 +47,76 @@ public class UserCollectInfoService {
return userCollectInfoDao.findUserCollectInfoByUserId(userId);
}
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 collectSong(String userid, String id) {
UserCollectInfo userCollectInfo = userCollectInfoDao.findUserCollectInfoByUserId(userid);
if (null == userCollectInfo) {
userCollectInfo = new 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