1.remove auth check for web request

main
Gary 6 months ago
parent 2bae413674
commit 694250d313

@ -13,6 +13,7 @@ import com.luoo.music.dto.response.SearchCategoryDTO;
import com.luoo.music.dto.response.SongRespDTO; import com.luoo.music.dto.response.SongRespDTO;
import io.swagger.annotations.*; import io.swagger.annotations.*;
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;
@ -23,10 +24,13 @@ import com.luoo.music.service.JournalService;
import com.luoo.music.service.JournalSongService; import com.luoo.music.service.JournalSongService;
import com.luoo.music.service.SearchService; import com.luoo.music.service.SearchService;
import com.luoo.music.service.TagService; import com.luoo.music.service.TagService;
import com.luoo.music.util.DeviceTypeUtil;
import annotation.GlobalInterceptor; import annotation.GlobalInterceptor;
import annotation.VerifyParam; import annotation.VerifyParam;
import api.PageResult; import api.PageResult;
import api.Result; import api.Result;
import dto.UserLoginDto;
/** /**
* *
@ -55,6 +59,9 @@ public class SearchController {
@Autowired @Autowired
private TagService tagService; private TagService tagService;
@Autowired
private JwtUtil jwtUtil;
@ApiOperation(value = "1.查询搜索大类", notes = "如 ‘民谣’,‘电子’") @ApiOperation(value = "1.查询搜索大类", notes = "如 ‘民谣’,‘电子’")
@GetMapping("/category") @GetMapping("/category")
@GlobalInterceptor @GlobalInterceptor
@ -64,12 +71,17 @@ public class SearchController {
@ApiOperation(value = "2.1 搜索歌曲", notes = "根据关键词模糊搜索歌曲") @ApiOperation(value = "2.1 搜索歌曲", notes = "根据关键词模糊搜索歌曲")
@GetMapping("/fuzzy/song") @GetMapping("/fuzzy/song")
@GlobalInterceptor(checkAppUserLogin = true) @GlobalInterceptor
public Result<PageResult<SongRespDTO>> fuzzySearchSong( public Result<PageResult<SongRespDTO>> fuzzySearchSong(
@RequestHeader(value = "Authorization", required = false) String authorization, @RequestHeader(value = "Authorization", required = false) String authorization,
@RequestHeader(value = "device_type", required = false) String deviceType,
@VerifyParam(required = true) FuzzySearchReq query) throws InterruptedException, ExecutionException { @VerifyParam(required = true) FuzzySearchReq query) throws InterruptedException, ExecutionException {
PageRequest pageRequest = PageRequest.of(getPageNum(query.getPageNum()), getPageSize(query.getPageSize())); UserLoginDto user = jwtUtil.getUserLoginDto(authorization);
if (!DeviceTypeUtil.isWeb(deviceType) && null == user) {
return Result.unauthorized(null);
}
PageRequest pageRequest = PageRequest.of(getPageNum(query.getPageNum()), getPageSize(query.getPageSize()));
List<JournalSong> pageResults=journalSongService.fuzzySearch(query.getKeyword(),pageRequest); List<JournalSong> pageResults=journalSongService.fuzzySearch(query.getKeyword(),pageRequest);
List<SongRespDTO> list = pageResults.stream().map(SongMapper::getSongRespDTO) List<SongRespDTO> list = pageResults.stream().map(SongMapper::getSongRespDTO)
.collect(Collectors.toList()); .collect(Collectors.toList());
@ -86,10 +98,16 @@ public class SearchController {
@ApiOperation(value = "2.2 搜索期刊", notes = "根据关键词模糊搜索期刊") @ApiOperation(value = "2.2 搜索期刊", notes = "根据关键词模糊搜索期刊")
@GetMapping("/fuzzy/journal") @GetMapping("/fuzzy/journal")
@GlobalInterceptor(checkAppUserLogin = true) @GlobalInterceptor
public Result<PageResult<JournalRespDTO>> fuzzySearchJournal( public Result<PageResult<JournalRespDTO>> fuzzySearchJournal(
@RequestHeader(value = "device_type", required = false) String deviceType,
@RequestHeader(value = "Authorization", required = false) String authorization, @RequestHeader(value = "Authorization", required = false) String authorization,
@VerifyParam(required = true) FuzzySearchReq query) throws InterruptedException, ExecutionException { @VerifyParam(required = true) FuzzySearchReq query) throws InterruptedException, ExecutionException {
UserLoginDto user = jwtUtil.getUserLoginDto(authorization);
if (!DeviceTypeUtil.isWeb(deviceType) && null == user) {
return Result.unauthorized(null);
}
PageRequest pageRequest = PageRequest.of(getPageNum(query.getPageNum()), getPageSize(query.getPageSize())); PageRequest pageRequest = PageRequest.of(getPageNum(query.getPageNum()), getPageSize(query.getPageSize()));
List<Journal> pageResults=journalService.fuzzySearch(query.getKeyword(),pageRequest); List<Journal> pageResults=journalService.fuzzySearch(query.getKeyword(),pageRequest);
List<JournalRespDTO> list = pageResults.stream().map(journalMapper::getJournalRespDTO) List<JournalRespDTO> list = pageResults.stream().map(journalMapper::getJournalRespDTO)
@ -99,10 +117,15 @@ public class SearchController {
@ApiOperation(value = "3.搜索自动补全", notes = "limit 默认查10条") @ApiOperation(value = "3.搜索自动补全", notes = "limit 默认查10条")
@GetMapping("/autoComplete") @GetMapping("/autoComplete")
@GlobalInterceptor(checkAppUserLogin = true) @GlobalInterceptor
public Result<List<String>> autoComplete( public Result<List<String>> autoComplete(
@RequestHeader(value = "Authorization", required = true) String authorization, @RequestHeader(value = "device_type", required = false) String deviceType,
@RequestHeader(value = "Authorization", required = false) String authorization,
@VerifyParam(required = true) AutoCompleteReq query) { @VerifyParam(required = true) AutoCompleteReq query) {
UserLoginDto user = jwtUtil.getUserLoginDto(authorization);
if (!DeviceTypeUtil.isWeb(deviceType) && null == user) {
return Result.unauthorized(null);
}
int limit = getLimit(query.getLimit()); int limit = getLimit(query.getLimit());
return Result.success(searchService.autoComplete(query.getQuery(), limit)); return Result.success(searchService.autoComplete(query.getQuery(), limit));
} }

Loading…
Cancel
Save