-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
54893f6
commit 0c36059
Showing
12 changed files
with
250 additions
and
7 deletions.
There are no files selected for viewing
48 changes: 48 additions & 0 deletions
48
src/main/java/com/swpu/uchain/blog/controller/TagsController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package com.swpu.uchain.blog.controller; | ||
|
||
import com.swpu.uchain.blog.form.InsertTagsForm; | ||
import com.swpu.uchain.blog.form.UpdateTagsForm; | ||
import com.swpu.uchain.blog.service.TagsService; | ||
import io.swagger.annotations.ApiOperation; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.PostMapping; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
/** | ||
* @author hobo | ||
* @description | ||
*/ | ||
@RestController | ||
@RequestMapping("/tags") | ||
public class TagsController { | ||
|
||
@Autowired | ||
private TagsService tagsService; | ||
|
||
@ApiOperation("添加标签") | ||
@PostMapping(name = "添加标签", value = "/insert") | ||
public Object insertTags(InsertTagsForm form) { | ||
return tagsService.insertTags(form); | ||
} | ||
|
||
@ApiOperation("更新标签") | ||
@PostMapping(name = "更新标签", value = "/update") | ||
public Object updateTags(UpdateTagsForm form) { | ||
return tagsService.updateTags(form); | ||
} | ||
|
||
@ApiOperation("删除标签") | ||
@GetMapping(name = "删除标签",value = "/delete") | ||
public Object deleteTags(Integer id) { | ||
return tagsService.deleteTags(id); | ||
} | ||
|
||
@ApiOperation("查看所有标签") | ||
@GetMapping(name = "查看所有标签",value = "/all") | ||
public Object selectAllTags(){ | ||
return tagsService.selectAllTags(); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package com.swpu.uchain.blog.enums; | ||
|
||
import lombok.Getter; | ||
|
||
/** | ||
* @author hobo | ||
* @description | ||
*/ | ||
@Getter | ||
public enum DefaultEnum { | ||
/** | ||
* 标签默认分组 | ||
*/ | ||
TAGS_DEFAULT_ENUM(1);; | ||
private Integer value; | ||
|
||
DefaultEnum(Integer value) { | ||
this.value = value; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 15 additions & 0 deletions
15
src/main/java/com/swpu/uchain/blog/form/InsertTagsForm.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package com.swpu.uchain.blog.form; | ||
|
||
import io.swagger.annotations.ApiModelProperty; | ||
import lombok.Data; | ||
|
||
/** | ||
* @author hobo | ||
* @description | ||
*/ | ||
@Data | ||
public class InsertTagsForm { | ||
|
||
@ApiModelProperty("标签") | ||
private String tagsMsg; | ||
} |
16 changes: 16 additions & 0 deletions
16
src/main/java/com/swpu/uchain/blog/form/UpdateTagsForm.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package com.swpu.uchain.blog.form; | ||
|
||
import lombok.Data; | ||
|
||
/** | ||
* @author hobo | ||
* @description | ||
*/ | ||
@Data | ||
public class UpdateTagsForm { | ||
|
||
private Integer id; | ||
|
||
private String tagsMsg; | ||
|
||
} |
39 changes: 39 additions & 0 deletions
39
src/main/java/com/swpu/uchain/blog/service/TagsService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package com.swpu.uchain.blog.service; | ||
|
||
import com.swpu.uchain.blog.form.InsertTagsForm; | ||
import com.swpu.uchain.blog.form.UpdateTagsForm; | ||
import com.swpu.uchain.blog.vo.ResultVO; | ||
|
||
/** | ||
* @author hobo | ||
* @description | ||
*/ | ||
public interface TagsService { | ||
|
||
/** | ||
* 添加标签 | ||
* @param form 添加标签表单 | ||
* @return com.swpu.uchain.blog.vo.ResultVO | ||
*/ | ||
ResultVO insertTags(InsertTagsForm form); | ||
|
||
/** | ||
* 修改标签 | ||
* @param form 修改标签表单 | ||
* @return com.swpu.uchain.blog.vo.ResultVO | ||
*/ | ||
ResultVO updateTags(UpdateTagsForm form); | ||
|
||
/** | ||
* 删除标签 | ||
* @param id 标签id | ||
* @return com.swpu.uchain.blog.vo.ResultVO | ||
*/ | ||
ResultVO deleteTags(Integer id); | ||
|
||
/** | ||
* 查看所有标签 | ||
* @return com.swpu.uchain.blog.vo.ResultVO | ||
*/ | ||
ResultVO selectAllTags(); | ||
} |
88 changes: 88 additions & 0 deletions
88
src/main/java/com/swpu/uchain/blog/service/impl/TagsServiceImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
package com.swpu.uchain.blog.service.impl; | ||
|
||
import com.swpu.uchain.blog.dao.ArticleMapper; | ||
import com.swpu.uchain.blog.dao.TagsMapper; | ||
import com.swpu.uchain.blog.entity.Article; | ||
import com.swpu.uchain.blog.entity.Tags; | ||
import com.swpu.uchain.blog.enums.DefaultEnum; | ||
import com.swpu.uchain.blog.enums.ResultEnum; | ||
import com.swpu.uchain.blog.form.InsertTagsForm; | ||
import com.swpu.uchain.blog.form.UpdateTagsForm; | ||
import com.swpu.uchain.blog.service.TagsService; | ||
import com.swpu.uchain.blog.util.ResultVOUtil; | ||
import com.swpu.uchain.blog.util.TimeUtil; | ||
import com.swpu.uchain.blog.vo.ResultVO; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.beans.BeanUtils; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.stereotype.Service; | ||
|
||
import java.util.List; | ||
|
||
/** | ||
* @author hobo | ||
* @description | ||
*/ | ||
@Service | ||
@Slf4j | ||
public class TagsServiceImpl implements TagsService { | ||
|
||
@Autowired | ||
private TagsMapper tagsMapper; | ||
|
||
@Autowired | ||
private ArticleMapper articleMapper; | ||
|
||
|
||
@Override | ||
public ResultVO insertTags(InsertTagsForm form) { | ||
if (tagsMapper.selectByTag(form.getTagsMsg()) != null) { | ||
return ResultVOUtil.error(ResultEnum.TAG_IS_ALREADY_EXIST); | ||
} | ||
Tags tags = new Tags(); | ||
BeanUtils.copyProperties(form, tags); | ||
tags.setCreatTime(TimeUtil.getNowTime()); | ||
if (tagsMapper.insert(tags) == 1) { | ||
return ResultVOUtil.success(tags); | ||
} | ||
return ResultVOUtil.error(ResultEnum.SERVER_ERROR); | ||
} | ||
|
||
@Override | ||
public ResultVO updateTags(UpdateTagsForm form) { | ||
if (tagsMapper.selectByPrimaryKey(form.getId()) == null) { | ||
return ResultVOUtil.error(ResultEnum.TAG_NOT_EXIST); | ||
} | ||
Tags tags = new Tags(); | ||
BeanUtils.copyProperties(form, tags); | ||
if (tagsMapper.updateByPrimaryKey(tags) == 1) { | ||
return ResultVOUtil.success(tags); | ||
} | ||
return ResultVOUtil.error(ResultEnum.SERVER_ERROR); | ||
} | ||
|
||
@Override | ||
public ResultVO deleteTags(Integer id) { | ||
if (id.equals(DefaultEnum.TAGS_DEFAULT_ENUM.getValue())) { | ||
return ResultVOUtil.error(ResultEnum.DEFAULT_GROUP_CAN_NOT_DELETE); | ||
} | ||
if (tagsMapper.selectByPrimaryKey(id) == null) { | ||
return ResultVOUtil.error(ResultEnum.TAG_NOT_EXIST); | ||
} | ||
List<Article> articles = articleMapper.selectByTagsId(id); | ||
// 将要删除的标签下的所有文章放入默认分组 | ||
for (Article article : articles) { | ||
article.setTagsId(DefaultEnum.TAGS_DEFAULT_ENUM.getValue()); | ||
} | ||
if (tagsMapper.deleteByPrimaryKey(id) == 1) { | ||
return ResultVOUtil.success(); | ||
} | ||
return ResultVOUtil.error(ResultEnum.SERVER_ERROR); | ||
} | ||
|
||
@Override | ||
public ResultVO selectAllTags() { | ||
List<Tags> tags = tagsMapper.selectAll(); | ||
return ResultVOUtil.success(tags); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters