1.add find all tag interface

main
Gary 5 months ago
parent 83d70a3e2e
commit 5ad3d47065

@ -11,6 +11,7 @@ import com.luoo.music.dto.request.FuzzySearchReq;
import com.luoo.music.dto.response.JournalRespDTO;
import com.luoo.music.dto.response.SearchCategoryDTO;
import com.luoo.music.dto.response.SongRespDTO;
import com.luoo.music.dto.response.TagDTO;
import io.swagger.annotations.*;
import util.JwtUtil;
@ -133,4 +134,11 @@ public class SearchController {
private int getLimit(Integer limit) {
return null == limit || 0 == limit ? DEFAULT_AUTO_COMPLETE_LIMIT : limit;
}
@ApiOperation(value = "4.获取所有标签")
@GetMapping("/tag")
@GlobalInterceptor
public Result<List<TagDTO>> tag() {
return Result.success(tagService.findAllTags());
}
}

@ -36,4 +36,7 @@ public interface TagDao extends JpaRepository<Tag, String>, JpaSpecificationExec
@Query(value = "select * from tb_tag_info where name_ch=?1 limit 1", nativeQuery = true)
Tag findByTagName(String tagName);
@Query(value = "select * from tb_tag_info where state=1 order by create_time", nativeQuery = true)
List<Tag> getAllValidTags();
}

@ -2,14 +2,19 @@ package com.luoo.music.dto.response;
import java.io.Serializable;
import com.fasterxml.jackson.annotation.JsonInclude;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
@Data
@JsonInclude(com.fasterxml.jackson.annotation.JsonInclude.Include.NON_NULL)
public class TagDTO implements Serializable {
private static final long serialVersionUID = 1L;
@ApiModelProperty(value = "ID")
private String id;
@ApiModelProperty(value = "中文名")
private String name;
@ApiModelProperty(value = "英文名")
private String engName;
}

@ -58,4 +58,20 @@ public class TagService {
searchCategoryDTO.setThumbnail(Constants.TAG_RESOURCE_PREFIX + tag.getThumbnail());
return searchCategoryDTO;
}
@SuppressWarnings("unchecked")
public List<TagDTO> findAllTags() {
return (List<TagDTO>) this.cacheChannel.get("default", "tags", key -> getAllTags(), false).getValue();
}
private List<TagDTO> getAllTags() {
return tagDao.getAllValidTags().stream().map(this::getTagDTO).collect(Collectors.toList());
}
private TagDTO getTagDTO(Tag tag) {
TagDTO tagDTO=new TagDTO();
tagDTO.setName(tag.getNameCh());
tagDTO.setId(tag.getId());
tagDTO.setEngName(tag.getNameEn());
return tagDTO;
}
}

Loading…
Cancel
Save