parent
e7875cbda6
commit
5c57bdfaef
@ -0,0 +1,37 @@
|
||||
package com.luoo.user.controller;
|
||||
|
||||
|
||||
import api.Result;
|
||||
import com.luoo.user.pojo.UserCollectInfo;
|
||||
import com.luoo.user.service.UserCollectInfoService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/UserCollectInfo")
|
||||
public class UserCollectInfoController {
|
||||
|
||||
|
||||
@Autowired
|
||||
private UserCollectInfoService userCollectInfoService;
|
||||
|
||||
|
||||
@PostMapping("/save")
|
||||
public Result save(){
|
||||
userCollectInfoService.save();
|
||||
return Result.success();
|
||||
}
|
||||
|
||||
@GetMapping("/show")
|
||||
public Result show(){
|
||||
UserCollectInfo userCollectInfo =userCollectInfoService.findByUserId();
|
||||
return Result.success(userCollectInfo);
|
||||
}
|
||||
|
||||
@PutMapping("/unCollect")
|
||||
public Result unCollect() {
|
||||
userCollectInfoService.unCollect();
|
||||
return Result.success();
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,9 @@
|
||||
package com.luoo.user.dao;
|
||||
|
||||
import com.luoo.user.pojo.UserCollectInfo;
|
||||
import org.springframework.data.mongodb.repository.MongoRepository;
|
||||
|
||||
public interface UserCollectInfoDao extends MongoRepository<UserCollectInfo, String> {
|
||||
|
||||
UserCollectInfo findUserCollectInfoByUserId(String userId);
|
||||
}
|
@ -0,0 +1,40 @@
|
||||
package com.luoo.user.pojo;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||
import lombok.Data;
|
||||
import org.springframework.data.annotation.Id;
|
||||
import org.springframework.format.annotation.DateTimeFormat;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
|
||||
@Data
|
||||
public class UserCollectInfo implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
* 收藏ID
|
||||
*/
|
||||
@Id
|
||||
private String collectId;
|
||||
|
||||
/**
|
||||
* 用户ID
|
||||
*/
|
||||
private String userId;
|
||||
|
||||
/**
|
||||
* 收藏的单曲
|
||||
*/
|
||||
private List songList;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 收藏的期刊
|
||||
*/
|
||||
private List journalList;
|
||||
}
|
@ -0,0 +1,61 @@
|
||||
package com.luoo.user.service;
|
||||
|
||||
|
||||
import com.luoo.user.dao.UserCollectInfoDao;
|
||||
import com.luoo.user.dto.UserCollectSongDto;
|
||||
import com.luoo.user.pojo.UserCollectInfo;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
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;
|
||||
|
||||
@Service
|
||||
public class UserCollectInfoService {
|
||||
|
||||
@Autowired
|
||||
private UserCollectInfoDao userCollectInfoDao;
|
||||
|
||||
@Autowired
|
||||
private IdWorker idWorker;
|
||||
|
||||
|
||||
public void save() {
|
||||
|
||||
UserCollectInfo userCollectInfo = new UserCollectInfo();
|
||||
UserCollectSongDto userCollectSongDto = new UserCollectSongDto();
|
||||
userCollectSongDto.setName("smell like teensprit");
|
||||
userCollectSongDto.setArtist("Nirvana");
|
||||
|
||||
UserCollectSongDto userCollectSongDto1 = new UserCollectSongDto();
|
||||
userCollectSongDto1.setName("the unforgiven");
|
||||
userCollectSongDto1.setArtist("Metallica");
|
||||
|
||||
List list = new ArrayList();
|
||||
list.add(userCollectSongDto);
|
||||
list.add(userCollectSongDto1);
|
||||
userCollectInfo.setSongList(list);
|
||||
userCollectInfo.setCollectId(idWorker.nextId()+"");
|
||||
userCollectInfo.setUserId("111222");
|
||||
userCollectInfoDao.save(userCollectInfo);
|
||||
}
|
||||
|
||||
|
||||
public UserCollectInfo findByUserId(){
|
||||
|
||||
return userCollectInfoDao.findUserCollectInfoByUserId("111222");
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
Loading…
Reference in new issue