mirror of https://github.com/halo-dev/halo
Complete tag list api
parent
338dbd623e
commit
f73d6c4342
|
@ -3,6 +3,8 @@ package cc.ryanc.halo.service;
|
|||
import cc.ryanc.halo.model.dto.TagOutputDTO;
|
||||
import cc.ryanc.halo.model.entity.Tag;
|
||||
import cc.ryanc.halo.service.base.CrudService;
|
||||
import org.springframework.data.domain.Sort;
|
||||
import org.springframework.lang.NonNull;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
|
@ -21,4 +23,13 @@ public interface TagService extends CrudService<Tag, Integer> {
|
|||
*/
|
||||
void remove(Integer id);
|
||||
|
||||
/**
|
||||
* Lists all tag dtos.
|
||||
*
|
||||
* @param sort sort info must not be null
|
||||
* @return a list of tag dto
|
||||
*/
|
||||
@NonNull
|
||||
List<TagOutputDTO> listDtos(@NonNull Sort sort);
|
||||
|
||||
}
|
||||
|
|
|
@ -1,12 +1,18 @@
|
|||
package cc.ryanc.halo.service.impl;
|
||||
|
||||
import cc.ryanc.halo.exception.AlreadyExistsException;
|
||||
import cc.ryanc.halo.model.dto.TagOutputDTO;
|
||||
import cc.ryanc.halo.model.entity.Tag;
|
||||
import cc.ryanc.halo.repository.TagRepository;
|
||||
import cc.ryanc.halo.service.TagService;
|
||||
import cc.ryanc.halo.service.base.AbstractCrudService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.data.domain.Sort;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* TagService implementation class
|
||||
|
@ -35,6 +41,13 @@ public class TagServiceImpl extends AbstractCrudService<Tag, Integer> implements
|
|||
// TODO 删除标签,以及对应的文章关系
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<TagOutputDTO> listDtos(Sort sort) {
|
||||
Assert.notNull(sort, "Sort info must not be null");
|
||||
|
||||
return listAll(sort).stream().map(tag -> (TagOutputDTO) new TagOutputDTO().convertFrom(tag)).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Tag create(Tag tag) {
|
||||
// Check if the tag is exist
|
||||
|
|
|
@ -13,6 +13,7 @@ import org.springframework.web.bind.annotation.*;
|
|||
|
||||
import javax.validation.Valid;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* Tag controller.
|
||||
|
@ -35,11 +36,16 @@ public class TagController {
|
|||
this.postTagService = postTagService;
|
||||
}
|
||||
|
||||
@GetMapping
|
||||
public List<TagWithCountOutputDTO> listTags(@SortDefault(sort = "updateTime", direction = Sort.Direction.DESC) Sort sort) {
|
||||
@GetMapping("/addition")
|
||||
public List<TagWithCountOutputDTO> listTagsWithCount(@SortDefault(sort = "updateTime", direction = Sort.Direction.DESC) Sort sort) {
|
||||
return postTagService.listTagWithCountDtos(sort);
|
||||
}
|
||||
|
||||
@GetMapping
|
||||
public List<TagOutputDTO> listTags(@SortDefault(sort = "updateTime", direction = Sort.Direction.DESC) Sort sort) {
|
||||
return tagService.listDtos(sort);
|
||||
}
|
||||
|
||||
@PostMapping
|
||||
public TagOutputDTO createTag(@Valid @RequestBody TagParam tagParam) {
|
||||
// Convert to tag
|
||||
|
|
Loading…
Reference in New Issue