From dff5b7eddd33d5e9b3c62579ea166075c5fbe2ae Mon Sep 17 00:00:00 2001 From: Gary Date: Mon, 29 Jan 2024 17:55:41 +0800 Subject: [PATCH 1/2] 1.update some Authorization to requried for better swagger desc --- .../java/com/luoo/music/controller/JournalController.java | 2 +- .../main/java/com/luoo/music/controller/SongController.java | 2 +- .../main/java/com/luoo/user/controller/LoginController.java | 2 +- .../java/com/luoo/user/controller/UserCollectController.java | 4 ++-- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/luoo_music/src/main/java/com/luoo/music/controller/JournalController.java b/luoo_music/src/main/java/com/luoo/music/controller/JournalController.java index b340c85..854a98f 100644 --- a/luoo_music/src/main/java/com/luoo/music/controller/JournalController.java +++ b/luoo_music/src/main/java/com/luoo/music/controller/JournalController.java @@ -120,7 +120,7 @@ public class JournalController { @GetMapping("/collect/{userId}/{pageNum}/{pageSize}") @GlobalInterceptor(checkAppUserLogin = true) public Result> collectPage( - @RequestHeader(value = "Authorization", required = false) String authorization, + @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) { 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 1135081..ae8515d 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 @@ -80,7 +80,7 @@ public class SongController { @GetMapping("/collect/{userId}/{pageNum}/{pageSize}") @GlobalInterceptor(checkAppUserLogin = true) public Result> collectPage( - @RequestHeader(value = "Authorization", required = false) String authorization, + @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) { diff --git a/luoo_user/src/main/java/com/luoo/user/controller/LoginController.java b/luoo_user/src/main/java/com/luoo/user/controller/LoginController.java index 5dc60fc..4ad2a20 100644 --- a/luoo_user/src/main/java/com/luoo/user/controller/LoginController.java +++ b/luoo_user/src/main/java/com/luoo/user/controller/LoginController.java @@ -206,7 +206,7 @@ public class LoginController extends BaseController { @ApiOperation(value = "6.退出登录") @PostMapping("/logout") @GlobalInterceptor(checkAppUserLogin = true) - public Result logout(@RequestHeader(value = "Authorization", required = false) String authorization){ + public Result logout(@RequestHeader(value = "Authorization", required = true) String authorization){ return Result.success(); } } diff --git a/luoo_user/src/main/java/com/luoo/user/controller/UserCollectController.java b/luoo_user/src/main/java/com/luoo/user/controller/UserCollectController.java index 0a5347b..9e1348c 100644 --- a/luoo_user/src/main/java/com/luoo/user/controller/UserCollectController.java +++ b/luoo_user/src/main/java/com/luoo/user/controller/UserCollectController.java @@ -31,7 +31,7 @@ public class UserCollectController { @ApiImplicitParam(name = "collectType", value = "0:歌曲,1:期刊,2:关注,3:黑名单", required = true) }) @PostMapping @GlobalInterceptor(checkAppUserLogin = true) - public Result addCollect(@RequestHeader(value = "Authorization", required = false) String authorization, + public Result addCollect(@RequestHeader(value = "Authorization", required = true) String authorization, @VerifyParam(required = true) @RequestParam("objectId") String objectId, @VerifyParam(required = true) @RequestParam("collectType") Integer collectType) { UserLoginDto loginDto = jwtUtil.getUserLoginDto(authorization); @@ -48,7 +48,7 @@ public class UserCollectController { @ApiImplicitParam(name = "collectType", value = "0:歌曲,1:期刊,2:关注,3:黑名单,4:粉丝", required = true) }) @DeleteMapping @GlobalInterceptor(checkAppUserLogin = true) - public Result cancelCollect(@RequestHeader(value = "Authorization", required = false) String authorization, + public Result cancelCollect(@RequestHeader(value = "Authorization", required = true) String authorization, @VerifyParam(required = true) @RequestParam("objectId") String objectId, @VerifyParam(required = true) @RequestParam("collectType") Integer collectType) { UserLoginDto loginDto = jwtUtil.getUserLoginDto(authorization); From 0a07fdd929b8cca6ae88d6dd90e11d27f7ae47e1 Mon Sep 17 00:00:00 2001 From: Gary Date: Mon, 29 Jan 2024 17:57:28 +0800 Subject: [PATCH 2/2] 1.format code --- .../music/controller/JournalController.java | 89 ++++++++++--------- 1 file changed, 47 insertions(+), 42 deletions(-) diff --git a/luoo_music/src/main/java/com/luoo/music/controller/JournalController.java b/luoo_music/src/main/java/com/luoo/music/controller/JournalController.java index 854a98f..c58f815 100644 --- a/luoo_music/src/main/java/com/luoo/music/controller/JournalController.java +++ b/luoo_music/src/main/java/com/luoo/music/controller/JournalController.java @@ -61,36 +61,38 @@ public class JournalController { private UserCollectService userCollectService; @Autowired private ArticleService articleService; - + @Autowired private TagDao tagDao; - + @Autowired private JwtUtil jwtUtil; - //mock data - private static final String JOURNAL_TAG_FILE_PATH="journalTags.txt"; - private Map> journalTagMap=new HashMap<>(); + // mock data + private static final String JOURNAL_TAG_FILE_PATH = "journalTags.txt"; + private Map> journalTagMap = new HashMap<>(); private static final String[] EDITOR = new String[] { "左岸以西", "落在低处" }; - + @PostConstruct @SneakyThrows private void init() { - getLines(JOURNAL_TAG_FILE_PATH).forEach(s->{ - String[] segs=s.split("\\|"); - List tags=Arrays.stream(segs[1].split(",")).collect(Collectors.toList()); + getLines(JOURNAL_TAG_FILE_PATH).forEach(s -> { + String[] segs = s.split("\\|"); + List tags = Arrays.stream(segs[1].split(",")).collect(Collectors.toList()); journalTagMap.put(segs[0], tags); }); } + private static List getLines(String filePath) { - try (InputStream is = new ClassPathResource(filePath).getInputStream(); - BufferedReader reader = new BufferedReader(new InputStreamReader(is));) { - return reader.lines().collect(Collectors.toList()); - } catch (IOException e) { - e.printStackTrace(); - } - return Collections.emptyList(); - } + try (InputStream is = new ClassPathResource(filePath).getInputStream(); + BufferedReader reader = new BufferedReader(new InputStreamReader(is));) { + return reader.lines().collect(Collectors.toList()); + } catch (IOException e) { + e.printStackTrace(); + } + return Collections.emptyList(); + } + @ApiOperation(value = "1.查询期刊信息", notes = "若authorization为空或authorization校验失败,默认返回最新的10期,期刊筛选条件对游客不可用") @GetMapping("/list") @GlobalInterceptor @@ -105,80 +107,83 @@ public class JournalController { queryReq.setPageSize(10); } Page
pageList = articleService.queryPage(queryReq); - Set journalCollectSet = null==user?Collections.emptySet():userCollectService.getCollectSet(user.getUserId(),CollectTypeEnum.JOURNAL); + Set journalCollectSet = null == user ? Collections.emptySet() + : userCollectService.getCollectSet(user.getUserId(), CollectTypeEnum.JOURNAL); List list = pageList.stream().map(a -> getJournalRespDTO(a, journalCollectSet)) .collect(Collectors.toList()); return Result.success(new PageResult(Long.valueOf(list.size()), list)); } @ApiOperation(value = "2.查询收藏期刊信息") - @ApiImplicitParams({ - @ApiImplicitParam(name = "userId", value = "用户id", required = true), - @ApiImplicitParam(name = "pageNum", value = "分页: 页码,以1开始", required = true), - @ApiImplicitParam(name = "pageSize", value = "分页: 每页数量", required = true) - }) + @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}") @GlobalInterceptor(checkAppUserLogin = true) public Result> collectPage( @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) { - List objectIds=userCollectService.getCollectList(userId,pageNum,pageSize,CollectTypeEnum.JOURNAL); - if(objectIds.isEmpty()) { + @PathVariable @VerifyParam(required = true) String userId, + @PathVariable @VerifyParam(required = true) Integer pageNum, + @PathVariable @VerifyParam(required = true) Integer pageSize) { + List objectIds = userCollectService.getCollectList(userId, pageNum, pageSize, CollectTypeEnum.JOURNAL); + if (objectIds.isEmpty()) { return Result.success(new PageResult(0L, Collections.emptyList())); } List
pageList = articleService.orderByField(objectIds); - Set journalCollectSet = objectIds.isEmpty()?Collections.emptySet(): new HashSet<>(objectIds); + Set journalCollectSet = objectIds.isEmpty() ? Collections.emptySet() : new HashSet<>(objectIds); List list = pageList.stream().map(a -> getJournalRespDTO(a, journalCollectSet)) .collect(Collectors.toList()); return Result.success(new PageResult(Long.valueOf(list.size()), list)); } - + @ApiOperation(value = "3.根据期刊id查询期刊信息") @GetMapping("/{id}") @GlobalInterceptor - public Result findById(@RequestHeader(value = "Authorization", required = false) String authorization, + public Result findById( + @RequestHeader(value = "Authorization", required = false) String authorization, @PathVariable @VerifyParam(required = true) String id) { UserLoginDto user = jwtUtil.getUserLoginDto(authorization); - Article journal=articleService.findById(id); - Set journalCollectSet = null==user?Collections.emptySet():userCollectService.getCollectSet(user.getUserId(),CollectTypeEnum.JOURNAL); + Article journal = articleService.findById(id); + Set journalCollectSet = null == user ? Collections.emptySet() + : userCollectService.getCollectSet(user.getUserId(), CollectTypeEnum.JOURNAL); return Result.success(getJournalRespDTO(journal, journalCollectSet)); } - + private JournalRespDTO getJournalRespDTO(Article article, Set journalCollectSet) { JournalRespDTO journalRespDTO = new JournalRespDTO(); journalRespDTO.setId(article.getId()); journalRespDTO.setJournalNo(article.getVolid()); journalRespDTO.setTitle(article.getTitle()); - journalRespDTO.setImage(Constants.MUSIC_RESOURCE_PREFIX + article.getImage()); + journalRespDTO.setImage(Constants.MUSIC_RESOURCE_PREFIX + article.getImage()); journalRespDTO.setDate(getEditDate(article)); journalRespDTO.setHaveCollect(journalCollectSet.contains(journalRespDTO.getId())); journalRespDTO.setIpLocation("广东"); - + journalRespDTO.setTags(getTags(journalRespDTO.getJournalNo())); - String content=article.getContent(); - if(StringTools.isEmpty(content)) { - Poem poem=RandomSource.languageSource().randomTangPoem(); + String content = article.getContent(); + if (StringTools.isEmpty(content)) { + Poem poem = RandomSource.languageSource().randomTangPoem(); journalRespDTO.setEditor(poem.getAuthor()); journalRespDTO.setContent(Arrays.stream(poem.getContent()).collect(Collectors.joining("\r\n"))); - }else { + } else { journalRespDTO.setContent(content); int index = RandomSource.numberSource().randomInt(0, EDITOR.length); String editor = EDITOR[index]; journalRespDTO.setEditor(editor); } - + return journalRespDTO; } private List getTags(String journalNo) { - return journalTagMap.computeIfAbsent(journalNo, a->getTags()); + return journalTagMap.computeIfAbsent(journalNo, a -> getTags()); } + private List getTags() { int limit = RandomSource.numberSource().randomInt(1, 3); return tagDao.random(limit).stream().map(Tag::getNameCh).sorted().collect(Collectors.toList()); } + private String getEditDate(Article article) { Date date = null == article.getUpdatetime() ? article.getCreatetime() : article.getUpdatetime(); return DateUtil.format(date, DateTimePatternEnum.YYYY_DOT_MM_DOT_DD.getPattern());