diff --git a/luoo_music/src/main/java/com/luoo/music/controller/SongController.java b/luoo_music/src/main/java/com/luoo/music/controller/SongController.java index 3c13b90..0334833 100644 --- a/luoo_music/src/main/java/com/luoo/music/controller/SongController.java +++ b/luoo_music/src/main/java/com/luoo/music/controller/SongController.java @@ -1,6 +1,7 @@ package com.luoo.music.controller; 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.pojo.JournalSong; import com.luoo.music.service.JournalService; @@ -21,7 +22,6 @@ import util.JwtUtil; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.data.domain.PageRequest; -import org.springframework.data.domain.Pageable; import org.springframework.web.bind.annotation.*; import java.util.Collections; @@ -77,20 +77,16 @@ public class SongController { return journalService.isLatest10ByJournalNo(journalNo); } - @ApiOperation(value = "2.查询收藏歌曲信息") + @ApiOperation(value = "2.查询收藏歌曲信息", notes = "pageNum/pageSize不传或者小于1,则返回所有收藏歌曲") @ApiImplicitParams({ @ApiImplicitParam(name = "userId", value = "用户id", required = true), - @ApiImplicitParam(name = "pageNum", value = "分页: 页码,以1开始", required = true), - @ApiImplicitParam(name = "pageSize", value = "分页: 每页数量", required = true) }) - @GetMapping("/collect/{userId}/{pageNum}/{pageSize}") + @ApiImplicitParam(name = "pageNum", value = "分页: 页码", required = false), + @ApiImplicitParam(name = "pageSize", value = "分页: 每页数量", required = false) }) + @GetMapping("/collect") @GlobalInterceptor(checkAppUserLogin = true) - public Result> collectPage( + public Result> collectSongs( @RequestHeader(value = "Authorization", required = true) String authorization, - @PathVariable @VerifyParam(required = true) String userId, - @PathVariable @VerifyParam(required = true) Integer pageNum, - @PathVariable @VerifyParam(required = true) Integer pageSize) { - - Pageable pageable = PageRequest.of(pageNum-1,pageSize); - List objectIds=userCollectInfoService.findByUserIdAndCollectType(userId, CollectTypeEnum.SONG, pageable); + @VerifyParam CollectQueryReq queryReq) { + List objectIds= getSongIds(queryReq); if (objectIds.isEmpty()) { return Result.success(new PageResult(0L, Collections.emptyList())); } @@ -101,6 +97,14 @@ public class SongController { .collect(Collectors.toList()); return Result.success(new PageResult(Long.valueOf(results.size()), results)); } + + private List 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") @ApiImplicitParams({ @ApiImplicitParam(name = "limit", value = "随机歌曲数,最少1首,最多30首", required = false) }) diff --git a/luoo_music/src/main/java/com/luoo/music/dao/UserCollectInfoDao.java b/luoo_music/src/main/java/com/luoo/music/dao/UserCollectInfoDao.java index 0002bb8..ddb2214 100644 --- a/luoo_music/src/main/java/com/luoo/music/dao/UserCollectInfoDao.java +++ b/luoo_music/src/main/java/com/luoo/music/dao/UserCollectInfoDao.java @@ -11,4 +11,5 @@ import com.luoo.music.pojo.UserCollectInfo; public interface UserCollectInfoDao extends MongoRepository { List findByUserIdAndCollectTypeOrderByCreateTimeDesc(String userId, Integer collectType, Pageable pageable); + List findByUserIdAndCollectTypeOrderByCreateTimeDesc(String userId, Integer collectType); } diff --git a/luoo_music/src/main/java/com/luoo/music/dto/request/CollectQueryReq.java b/luoo_music/src/main/java/com/luoo/music/dto/request/CollectQueryReq.java new file mode 100644 index 0000000..e67e329 --- /dev/null +++ b/luoo_music/src/main/java/com/luoo/music/dto/request/CollectQueryReq.java @@ -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; +} diff --git a/luoo_music/src/main/java/com/luoo/music/service/UserCollectInfoService.java b/luoo_music/src/main/java/com/luoo/music/service/UserCollectInfoService.java index d27eb91..cddbb8e 100644 --- a/luoo_music/src/main/java/com/luoo/music/service/UserCollectInfoService.java +++ b/luoo_music/src/main/java/com/luoo/music/service/UserCollectInfoService.java @@ -3,7 +3,6 @@ package com.luoo.music.service; import enums.CollectTypeEnum; import java.util.Collections; -import java.util.HashSet; import java.util.List; import java.util.Set; import java.util.stream.Collectors; @@ -52,4 +51,9 @@ public class UserCollectInfoService { Query query = new Query(criteria); return mongoTemplate.exists(query, UserCollectInfo.class); } + + public List findByUserIdAndCollectType(String userId, CollectTypeEnum collectTypeEnum) { + return userCollectInfoDao.findByUserIdAndCollectTypeOrderByCreateTimeDesc(userId, + collectTypeEnum.getType()).stream().map(UserCollectInfo::getObjectId).collect(Collectors.toList()); + } }