Complete tag update api

pull/137/head
johnniang 2019-03-25 22:14:34 +08:00
parent a8eb88956c
commit e8a9498ea4
3 changed files with 28 additions and 16 deletions

View File

@ -88,11 +88,11 @@ public class StartedListener implements ApplicationListener<ApplicationStartedEv
private void printStartInfo() {
String blogUrl = getBaseUrl();
log.info("Halo started at {}", blogUrl);
log.info("Halo started at {}", blogUrl);
// TODO admin may be changeable
log.info("Halo admin is at {}/admin", blogUrl);
log.info("Halo admin started at {}/admin", blogUrl);
if (!haloProperties.getDocDisabled()) {
log.debug("Halo doc enable at {}/swagger-ui.html", blogUrl);
log.debug("Halo doc was enable at {}/swagger-ui.html", blogUrl);
}
}

View File

@ -3,11 +3,9 @@ package cc.ryanc.halo.model.params;
import cc.ryanc.halo.model.dto.base.InputConverter;
import cc.ryanc.halo.model.entity.Tag;
import cc.ryanc.halo.utils.HaloUtils;
import cc.ryanc.halo.utils.SlugUtils;
import cn.hutool.core.util.URLUtil;
import lombok.Data;
import org.apache.commons.lang3.RandomUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.util.Assert;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.Size;
@ -32,7 +30,7 @@ public class TagParam implements InputConverter<Tag> {
public Tag convertTo() {
if (StringUtils.isBlank(slugName)) {
// Handle slug name
slugName = SlugUtils.slugify(name);
slugName = URLUtil.normalize(name);
}
slugName = HaloUtils.initializeUrlIfBlank(slugName);

View File

@ -58,24 +58,38 @@ public class TagController {
/**
* Get tag by id
*
* @param id id
* @param tagId tag id
* @return TagOutputDTO
*/
@GetMapping("{id:\\d+}")
@GetMapping("{tagId:\\d+}")
@ApiOperation("Get tag detail by id")
public TagOutputDTO getBy(@PathVariable("id") Integer id) {
return new TagOutputDTO().convertFrom(tagService.getById(id));
public TagOutputDTO getBy(@PathVariable("tagId") Integer tagId) {
return new TagOutputDTO().convertFrom(tagService.getById(tagId));
}
@PutMapping("{tagId:\\d+}")
@ApiOperation("Updates tag")
public TagOutputDTO updateBy(@PathVariable("tagId") Integer tagId,
@Valid @RequestBody TagParam tagParam) {
// Get old tag
Tag tag = tagService.getById(tagId);
// Update tag
tagParam.update(tag);
// Update tag
return new TagOutputDTO().convertFrom(tagService.update(tag));
}
/**
* Delete tag by id.
*
* @param id id
* @param tagId tag id
*/
@DeleteMapping("{id:\\d+}")
@DeleteMapping("{tagId:\\d+}")
@ApiOperation("Delete tag by id")
public void deletePermanently(@PathVariable("id") Integer id) {
tagService.removeById(id);
postTagService.removeByTagId(id);
public void deletePermanently(@PathVariable("tagId") Integer tagId) {
tagService.removeById(tagId);
postTagService.removeByTagId(tagId);
}
}