1.remove turist token 2.modify auth control in music component

main
Gary 10 months ago
parent 8c3e8e0e3f
commit b59c429ab2

@ -10,7 +10,7 @@ public class Constants {
public static final String TOKEN_ROLE_APP_USER="user";
public static final String TOKEN_ROLE_ADMIN_USER="admin";
public static final String TOKEN_ROLE_TOURIST="tourist";
//public static final String TOKEN_ROLE_TOURIST="tourist";
public static final String FOLDER_AVATAR = "avatar/";

@ -1,4 +1,5 @@
package com.luoo.music.controller;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@ -20,7 +21,11 @@ import annotation.VerifyParam;
import api.PageResult;
import api.Result;
import constants.Constants;
import dto.UserLoginDto;
import enums.DateTimePatternEnum;
import io.swagger.annotations.ApiOperation;
import util.DateUtil;
import util.JwtUtil;
/**
*
@ -34,23 +39,37 @@ public class JournalController {
@Autowired
private ArticleService articleService;
@ApiOperation(value = "1.查询期刊信息")
@Autowired
private JwtUtil jwtUtil;
@ApiOperation(value = "1.查询期刊信息", notes="若token为空或token校验失败默认返回最新的10期期刊筛选条件对游客不可用")
@GetMapping("/list")
@GlobalInterceptor(checkLogin = true)
@GlobalInterceptor
public Result<PageResult<JournalRespDTO>> page(@RequestHeader(value = "token", required = false) String token,
@VerifyParam JournalQueryReq queryReq){
UserLoginDto user=jwtUtil.getUserLoginDto(token);
if(null==user) {
queryReq.setLanguage(null);
queryReq.setStyle(null);
queryReq.setPageNum(1);
queryReq.setPageSize(10);
}
Page<Article> pageList = articleService.queryPage(queryReq);
List<JournalRespDTO> list=pageList.stream().map(a->getArticleRespDTO(a)).collect(Collectors.toList());
List<JournalRespDTO> list=pageList.stream().map(a->getArticleRespDTO(a,user)).collect(Collectors.toList());
return Result.success(new PageResult<JournalRespDTO>(Long.valueOf(list.size()), list) );
}
private JournalRespDTO getArticleRespDTO(Article article) {
private JournalRespDTO getArticleRespDTO(Article article, UserLoginDto user) {
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.setDate(getEditDate(article));
//TODO: 根据userId查询是否已收藏
return journalRespDTO;
}
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());
}
}

@ -3,6 +3,7 @@ package com.luoo.music.controller;
import com.luoo.music.dto.response.SongRespDTO;
import com.luoo.music.pojo.Article;
import com.luoo.music.pojo.Song;
import com.luoo.music.service.ArticleService;
import com.luoo.music.service.SongService;
import annotation.GlobalInterceptor;
@ -10,10 +11,12 @@ import annotation.VerifyParam;
import api.PageResult;
import api.Result;
import constants.Constants;
import dto.UserLoginDto;
import enums.VerifyRegexEnum;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import util.JwtUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
@ -32,7 +35,10 @@ public class SongController {
@Autowired
private SongService songService;
@Autowired
private ArticleService articleService;
@Autowired
private JwtUtil jwtUtil;
/**
*
*
@ -43,24 +49,31 @@ public class SongController {
return Result.success(songService.findAll());
}
@ApiOperation(value = "1.根据期刊号查询歌曲信息")
@ApiOperation(value = "1.根据期刊号查询歌曲信息",notes="若为游客期刊号须在最新10期内")
@GetMapping("/getByJournalNo/{journalNo}")
@GlobalInterceptor(checkLogin = true)
@GlobalInterceptor
public Result<List<SongRespDTO>> getByJournalNo(@RequestHeader(value = "token", required = false) String token,
@PathVariable String journalNo) {
UserLoginDto user=jwtUtil.getUserLoginDto(token);
if(null==user&&!isLatest10(journalNo)) {
return Result.unauthorized(null);
}
List<Song> songs = songService.findByVolid(journalNo);
List<SongRespDTO> results = songs.stream().map(s -> getSongRespDTO(s)).collect(Collectors.toList());
return Result.success(results);
}
private boolean isLatest10(String journalNo) {
return articleService.isLatest10(journalNo);
}
@ApiOperation(value = "2.随机播放歌曲", notes = "雀乐FM")
@ApiImplicitParams({
@ApiImplicitParam(name = "limit", value = "随机歌曲数最少1首最多30首", required = false)
})
@GetMapping("/random/{limit}")
@GlobalInterceptor(checkLogin = true)
public Result<List<SongRespDTO>> random(@RequestHeader(value = "token", required = false) String token,
@PathVariable @VerifyParam(required=true,regex=VerifyRegexEnum.RANDOM_SONG_LIMIT) Integer limit) {
@GlobalInterceptor
public Result<List<SongRespDTO>> random(@PathVariable @VerifyParam(required=true,regex=VerifyRegexEnum.RANDOM_SONG_LIMIT) Integer limit) {
List<Song> songs = songService.random(limit);
List<SongRespDTO> results = songs.stream().map(s -> getSongRespDTO(s)).collect(Collectors.toList());
return Result.success(results);

@ -1,16 +1,9 @@
package com.luoo.music.dto.request;
import com.fasterxml.jackson.annotation.JsonFormat;
import annotation.VerifyParam;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import org.springframework.format.annotation.DateTimeFormat;
import javax.validation.constraints.NotNull;
import java.io.Serializable;
import java.time.LocalDateTime;
/**
*
@ -23,10 +16,8 @@ public class JournalQueryReq implements Serializable {
private String style;
@ApiModelProperty(value = "筛选条件:语言")
private String language;
@VerifyParam(required=true)
@ApiModelProperty(value = "分页: 页码以1开始即获取最新的几期", example = "1")
private Integer pageNum = 1;
@VerifyParam(required=true)
@ApiModelProperty(value = "分页: 每页数量", example = "10")
private Integer pageSize = 10;
}

@ -1,5 +1,7 @@
package com.luoo.music.dto.response;
import java.util.List;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
@ -11,8 +13,16 @@ public class JournalRespDTO {
private String journalNo;
@ApiModelProperty(value = "期刊名")
private String title;
@ApiModelProperty(value = "文案")
private String content;
@ApiModelProperty(value = "期刊封面")
private String image;
@ApiModelProperty(value = "期刊标签")
private List<String> tags;
@ApiModelProperty(value = "文案")
private String content;
@ApiModelProperty(value = "编辑人")
private String editor;
@ApiModelProperty(value = "编辑日期,格式为: yyyy.MM.dd")
private String date;
@ApiModelProperty(value = "已收藏")
private boolean haveCollect;
}

@ -235,4 +235,10 @@ public class ArticleService {
};
}
public boolean isLatest10(String journalNo) {
// TODO Auto-generated method stub
return true;
}
}

@ -51,13 +51,13 @@ public class MyController {
public static String UPLOAD_DIRECTORY = System.getProperty("user.dir") + File.separator+"luoo_uploads"+File.separator;
@ApiOperation(value = "1.获取个人信息")
@ApiOperation(value = "1.获取个人信息", notes = "游客无法获取个人信息")
@GetMapping("/getUserInfo")
@GlobalInterceptor
public Result getUserInfo(@RequestHeader(value = "token", required = false) String token) {
UserLoginDto userLoginDto = jwtUtil.getUserLoginDto(token);
if (null == userLoginDto) {
return Result.validateFailed();
return Result.unauthorized(null);
}
UserRespDTO userRespDTO = new UserRespDTO();
if (Constants.TOKEN_ROLE_APP_USER.equals(userLoginDto.getRoles())) {
@ -130,7 +130,7 @@ public class MyController {
}
//待优化
@ApiOperation(value = "4.下载个人头像")
@GetMapping(value = "/avatar", produces = MediaType.IMAGE_JPEG_VALUE)
@GetMapping(value = "/downloadAvatar", produces = MediaType.IMAGE_JPEG_VALUE)
@GlobalInterceptor(checkLogin = true)
public @ResponseBody byte[] getImage(@RequestHeader(value = "token", required = false) String token)
throws IOException {

@ -111,13 +111,14 @@ public class UserController {
}
}
@Deprecated
@ApiOperation(value = "3.游客登录返回token", notes = "token中的subject和roles均为tourist")
@GetMapping("/touristLogin")
public Result<String> touristLogin() {
String nickName="游客-"+NickNameUtil.getRandomNickName();
String token = jwtUtil.createJWT(String.valueOf(idWorker.nextId()),nickName,Constants.TOKEN_ROLE_TOURIST);
return Result.success(token);
//String nickName="游客-"+NickNameUtil.getRandomNickName();
//String token = jwtUtil.createJWT(String.valueOf(idWorker.nextId()),nickName,Constants.TOKEN_ROLE_TOURIST);
//return Result.success(token);
return Result.success("");
}
/**

Loading…
Cancel
Save