1.fix swagger annatation 2.unify collect request fot both journal and song

main
Gary 9 months ago
parent aeb18e7e5d
commit 6d94c8dc94

@ -1,6 +1,5 @@
package com.luoo.music.controller; package com.luoo.music.controller;
import java.util.Arrays;
import java.util.Collections; import java.util.Collections;
import java.util.HashMap; import java.util.HashMap;
import java.util.HashSet; import java.util.HashSet;
@ -13,6 +12,7 @@ import java.util.stream.Collectors;
import com.luoo.music.dao.CommentDao; import com.luoo.music.dao.CommentDao;
import com.luoo.music.dto.mapper.CommentMapper; import com.luoo.music.dto.mapper.CommentMapper;
import com.luoo.music.dto.mapper.JournalMapper; import com.luoo.music.dto.mapper.JournalMapper;
import com.luoo.music.dto.request.CollectQueryReq;
import com.luoo.music.dto.request.JournalQueryReq; import com.luoo.music.dto.request.JournalQueryReq;
import com.luoo.music.dto.response.CommentDTO; import com.luoo.music.dto.response.CommentDTO;
import com.luoo.music.dto.response.JournalFilterDTO; import com.luoo.music.dto.response.JournalFilterDTO;
@ -21,10 +21,8 @@ import com.luoo.music.dto.response.TagDTO;
import io.swagger.annotations.*; import io.swagger.annotations.*;
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.data.mongodb.core.MongoTemplate; import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.redis.core.RedisTemplate; import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.util.StopWatch;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import com.luoo.music.pojo.Journal; import com.luoo.music.pojo.Journal;
import com.luoo.music.pojo.Tag; import com.luoo.music.pojo.Tag;
@ -125,19 +123,13 @@ public class JournalController {
return set; return set;
} }
@ApiOperation(value = "2.查询收藏期刊信息") @ApiOperation(value = "2.查询收藏期刊信息", notes = "pageNum/pageSize不传或者小于1则返回所有收藏刊")
@ApiImplicitParams({ @ApiImplicitParam(name = "userId", value = "用户id", required = true), @GetMapping("/collect")
@ApiImplicitParam(name = "pageNum", value = "分页: 页码以1开始", required = true),
@ApiImplicitParam(name = "pageSize", value = "分页: 每页数量", required = true) })
@GetMapping("/collect/{userId}/{pageNum}/{pageSize}")
@GlobalInterceptor(checkAppUserLogin = true) @GlobalInterceptor(checkAppUserLogin = true)
public Result<PageResult<JournalRespDTO>> collectPage( public Result<PageResult<JournalRespDTO>> collectJournals(
@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= getObjectIds(queryReq);
@PathVariable @VerifyParam(required = true) Integer pageSize) {
Pageable pageable = PageRequest.of(pageNum-1,pageSize);
List<String> objectIds=userCollectInfoService.findByUserIdAndCollectType(userId, CollectTypeEnum.JOURNAL, pageable);
if (objectIds.isEmpty()) { if (objectIds.isEmpty()) {
return Result.success(new PageResult<JournalRespDTO>(0L, Collections.emptyList())); return Result.success(new PageResult<JournalRespDTO>(0L, Collections.emptyList()));
} }
@ -147,7 +139,15 @@ public class JournalController {
.collect(Collectors.toList()); .collect(Collectors.toList());
return Result.success(new PageResult<JournalRespDTO>(Long.valueOf(list.size()), list)); return Result.success(new PageResult<JournalRespDTO>(Long.valueOf(list.size()), list));
} }
private List<String> getObjectIds(CollectQueryReq queryReq) {
if(null==queryReq.getPageNum()||queryReq.getPageNum()<1||null==queryReq.getPageSize()||queryReq.getPageSize()<1) {
return userCollectInfoService.findByUserIdAndCollectType(queryReq.getUserId(), CollectTypeEnum.JOURNAL);
}
PageRequest pageRequest = PageRequest.of(queryReq.getPageNum()-1, queryReq.getPageSize());
return userCollectInfoService.findByUserIdAndCollectType(queryReq.getUserId(), CollectTypeEnum.JOURNAL, pageRequest);
}
@ApiOperation(value = "3.根据期刊id查询期刊信息") @ApiOperation(value = "3.根据期刊id查询期刊信息")
@GetMapping("/{id}") @GetMapping("/{id}")
@GlobalInterceptor @GlobalInterceptor

@ -78,9 +78,6 @@ public class SongController {
} }
@ApiOperation(value = "2.查询收藏歌曲信息", notes = "pageNum/pageSize不传或者小于1则返回所有收藏歌曲") @ApiOperation(value = "2.查询收藏歌曲信息", notes = "pageNum/pageSize不传或者小于1则返回所有收藏歌曲")
@ApiImplicitParams({ @ApiImplicitParam(name = "userId", value = "用户id", required = true),
@ApiImplicitParam(name = "pageNum", value = "分页: 页码", required = false),
@ApiImplicitParam(name = "pageSize", value = "分页: 每页数量", required = false) })
@GetMapping("/collect") @GetMapping("/collect")
@GlobalInterceptor(checkAppUserLogin = true) @GlobalInterceptor(checkAppUserLogin = true)
public Result<PageResult<SongRespDTO>> collectSongs( public Result<PageResult<SongRespDTO>> collectSongs(

@ -61,7 +61,7 @@ public class JournalMapper {
journalRespDTO.setJournalNo(journal.getJournalNo()); journalRespDTO.setJournalNo(journal.getJournalNo());
journalRespDTO.setTitle(journal.getTitle()); journalRespDTO.setTitle(journal.getTitle());
journalRespDTO.setImage(Constants.MUSIC_RESOURCE_PREFIX + journal.getImage()); journalRespDTO.setImage(Constants.MUSIC_RESOURCE_PREFIX + journal.getImage());
journalRespDTO.setDate(getEditDate(journal)); journalRespDTO.setDate(getPublishDate(journal));
journalRespDTO.setHaveCollect(journalCollectSet.contains(journalRespDTO.getId())); journalRespDTO.setHaveCollect(journalCollectSet.contains(journalRespDTO.getId()));
journalRespDTO.setIpLocation("广东"); journalRespDTO.setIpLocation("广东");
@ -104,8 +104,8 @@ public class JournalMapper {
return journalTagMap.getOrDefault(journalNo, Collections.emptyList()); return journalTagMap.getOrDefault(journalNo, Collections.emptyList());
} }
private static String getEditDate(Journal journal) { private static String getPublishDate(Journal journal) {
LocalDateTime date = null == journal.getUpdateTime() ? journal.getCreateTime() : journal.getUpdateTime(); LocalDateTime date = null == journal.getPubTime() ? journal.getCreateTime() : journal.getPubTime();
return DateUtil.format(date, DateTimePatternEnum.YYYY_DOT_MM_DOT_DD.getPattern()); return DateUtil.format(date, DateTimePatternEnum.YYYY_DOT_MM_DOT_DD.getPattern());
} }
} }

@ -14,13 +14,13 @@ import annotation.VerifyParam;
@ApiModel @ApiModel
public class CollectQueryReq implements Serializable { public class CollectQueryReq implements Serializable {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
@VerifyParam(required = true) @VerifyParam(required = true)
@ApiModelProperty(value = "用户id") @ApiModelProperty(value = "用户id", required = true)
private String userId; private String userId;
@VerifyParam(required = false) @VerifyParam(required = false)
@ApiModelProperty(value = "分页: 页码", example = "1") @ApiModelProperty(value = "分页: 页码", example = "1")
private Integer pageNum; private Integer pageNum;
@VerifyParam(required = false) @VerifyParam(required = false)
@ApiModelProperty(value = "分页: 每页数量", example = "10") @ApiModelProperty(value = "分页: 每页数量", example = "10")
private Integer pageSize; private Integer pageSize;
} }

Loading…
Cancel
Save