UserCollectInfo with MongoDB

main
wangqing 10 months ago
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,59 @@
package com.luoo.user.dto;
import lombok.Data;
import java.io.Serializable;
import java.time.LocalDateTime;
@Data
public class UserCollectJournalDto implements Serializable {
private String id;
/**
*
*/
private String number;
/**
*
*/
private String name;
/**
*
*/
private String summary;
/**
* ID
*/
private String userId;
/**
* 01
*/
private String state;
/**
* 01
*/
private String status;
/**
* 0 1
*/
private String scheduled;
/**
*
*/
private String coverPhoto;
/**
*
*/
private LocalDateTime pubTime;
/**
*
*/
private LocalDateTime createTime;
/**
*
*/
private LocalDateTime updateTime;
}

@ -0,0 +1,67 @@
package com.luoo.user.dto;
import lombok.Data;
import org.springframework.data.annotation.CreatedDate;
import org.springframework.data.annotation.LastModifiedDate;
import java.io.Serializable;
import java.time.LocalDateTime;
@Data
public class UserCollectSongDto implements Serializable {
private String id;
/**
*
*/
private String name;
/**
*
*/
private String artist;
/**
*
*/
private String album;
/**
*
*/
private String picture;
/**
* 0:1:
*/
private String state;
/**
*
*/
private Long size;
/**
*
*/
private Long duration;
/**
*
*/
private String url;
/**
*
*/
private String lyric;
/**
* ID
*/
private String userId;
/**
*
*/
private LocalDateTime createTime;
/**
*
*/
private LocalDateTime updateTime;
}

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