1.update song collect interface to support all collected songs

main
Gary 9 months ago
parent 77054a7a2a
commit a58a6c9ffc

@ -1,6 +1,7 @@
package com.luoo.music.controller; package com.luoo.music.controller;
import com.luoo.music.dto.mapper.SongMapper; import com.luoo.music.dto.mapper.SongMapper;
import com.luoo.music.dto.request.CollectQueryReq;
import com.luoo.music.dto.response.SongRespDTO; import com.luoo.music.dto.response.SongRespDTO;
import com.luoo.music.pojo.JournalSong; import com.luoo.music.pojo.JournalSong;
import com.luoo.music.service.JournalService; import com.luoo.music.service.JournalService;
@ -21,7 +22,6 @@ import util.JwtUtil;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.PageRequest; import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import java.util.Collections; import java.util.Collections;
@ -77,20 +77,16 @@ public class SongController {
return journalService.isLatest10ByJournalNo(journalNo); return journalService.isLatest10ByJournalNo(journalNo);
} }
@ApiOperation(value = "2.查询收藏歌曲信息") @ApiOperation(value = "2.查询收藏歌曲信息", notes = "pageNum/pageSize不传或者小于1则返回所有收藏歌曲")
@ApiImplicitParams({ @ApiImplicitParam(name = "userId", value = "用户id", required = true), @ApiImplicitParams({ @ApiImplicitParam(name = "userId", value = "用户id", required = true),
@ApiImplicitParam(name = "pageNum", value = "分页: 页码以1开始", required = true), @ApiImplicitParam(name = "pageNum", value = "分页: 页码", required = false),
@ApiImplicitParam(name = "pageSize", value = "分页: 每页数量", required = true) }) @ApiImplicitParam(name = "pageSize", value = "分页: 每页数量", required = false) })
@GetMapping("/collect/{userId}/{pageNum}/{pageSize}") @GetMapping("/collect")
@GlobalInterceptor(checkAppUserLogin = true) @GlobalInterceptor(checkAppUserLogin = true)
public Result<PageResult<SongRespDTO>> collectPage( public Result<PageResult<SongRespDTO>> collectSongs(
@RequestHeader(value = "Authorization", required = true) String authorization, @RequestHeader(value = "Authorization", required = true) String authorization,
@PathVariable @VerifyParam(required = true) String userId, @VerifyParam CollectQueryReq queryReq) {
@PathVariable @VerifyParam(required = true) Integer pageNum, List<String> objectIds= getSongIds(queryReq);
@PathVariable @VerifyParam(required = true) Integer pageSize) {
Pageable pageable = PageRequest.of(pageNum-1,pageSize);
List<String> objectIds=userCollectInfoService.findByUserIdAndCollectType(userId, CollectTypeEnum.SONG, pageable);
if (objectIds.isEmpty()) { if (objectIds.isEmpty()) {
return Result.success(new PageResult<SongRespDTO>(0L, Collections.emptyList())); return Result.success(new PageResult<SongRespDTO>(0L, Collections.emptyList()));
} }
@ -101,6 +97,14 @@ public class SongController {
.collect(Collectors.toList()); .collect(Collectors.toList());
return Result.success(new PageResult<SongRespDTO>(Long.valueOf(results.size()), results)); return Result.success(new PageResult<SongRespDTO>(Long.valueOf(results.size()), results));
} }
private List<String> getSongIds(CollectQueryReq queryReq) {
if(null==queryReq.getPageNum()||queryReq.getPageNum()<1||null==queryReq.getPageSize()||queryReq.getPageSize()<1) {
return userCollectInfoService.findByUserIdAndCollectType(queryReq.getUserId(), CollectTypeEnum.SONG);
}
PageRequest pageRequest = PageRequest.of(queryReq.getPageNum()-1, queryReq.getPageSize());
return userCollectInfoService.findByUserIdAndCollectType(queryReq.getUserId(), CollectTypeEnum.SONG, pageRequest);
}
@ApiOperation(value = "3.随机播放歌曲", notes = "雀乐FM") @ApiOperation(value = "3.随机播放歌曲", notes = "雀乐FM")
@ApiImplicitParams({ @ApiImplicitParam(name = "limit", value = "随机歌曲数最少1首最多30首", required = false) }) @ApiImplicitParams({ @ApiImplicitParam(name = "limit", value = "随机歌曲数最少1首最多30首", required = false) })

@ -11,4 +11,5 @@ import com.luoo.music.pojo.UserCollectInfo;
public interface UserCollectInfoDao extends MongoRepository<UserCollectInfo, String> { public interface UserCollectInfoDao extends MongoRepository<UserCollectInfo, String> {
List<UserCollectInfo> findByUserIdAndCollectTypeOrderByCreateTimeDesc(String userId, Integer collectType, List<UserCollectInfo> findByUserIdAndCollectTypeOrderByCreateTimeDesc(String userId, Integer collectType,
Pageable pageable); Pageable pageable);
List<UserCollectInfo> findByUserIdAndCollectTypeOrderByCreateTimeDesc(String userId, Integer collectType);
} }

@ -0,0 +1,26 @@
package com.luoo.music.dto.request;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.io.Serializable;
import annotation.VerifyParam;
/**
*
*/
@Data
@ApiModel
public class CollectQueryReq implements Serializable {
private static final long serialVersionUID = 1L;
@VerifyParam(required = true)
@ApiModelProperty(value = "用户id")
private String userId;
@VerifyParam(required = false)
@ApiModelProperty(value = "分页: 页码", example = "1")
private Integer pageNum;
@VerifyParam(required = false)
@ApiModelProperty(value = "分页: 每页数量", example = "10")
private Integer pageSize;
}

@ -3,7 +3,6 @@ package com.luoo.music.service;
import enums.CollectTypeEnum; import enums.CollectTypeEnum;
import java.util.Collections; import java.util.Collections;
import java.util.HashSet;
import java.util.List; import java.util.List;
import java.util.Set; import java.util.Set;
import java.util.stream.Collectors; import java.util.stream.Collectors;
@ -52,4 +51,9 @@ public class UserCollectInfoService {
Query query = new Query(criteria); Query query = new Query(criteria);
return mongoTemplate.exists(query, UserCollectInfo.class); return mongoTemplate.exists(query, UserCollectInfo.class);
} }
public List<String> findByUserIdAndCollectType(String userId, CollectTypeEnum collectTypeEnum) {
return userCollectInfoDao.findByUserIdAndCollectTypeOrderByCreateTimeDesc(userId,
collectTypeEnum.getType()).stream().map(UserCollectInfo::getObjectId).collect(Collectors.toList());
}
} }

Loading…
Cancel
Save