Skip to content

Commit

Permalink
优化标签功能和文章搜索功能
Browse files Browse the repository at this point in the history
  • Loading branch information
TreasureJade committed Dec 18, 2019
1 parent 222481d commit 492fab4
Show file tree
Hide file tree
Showing 17 changed files with 282 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@

import com.swpu.uchain.blog.entity.Article;
import com.swpu.uchain.blog.enums.ResultEnum;
import com.swpu.uchain.blog.form.CreatArticleForm;
import com.swpu.uchain.blog.form.PageForm;
import com.swpu.uchain.blog.form.UpdateArticleForm;
import com.swpu.uchain.blog.form.*;
import com.swpu.uchain.blog.service.ArticleService;
import com.swpu.uchain.blog.util.IpUtil;
import com.swpu.uchain.blog.util.RandomUtil;
Expand Down Expand Up @@ -41,7 +39,7 @@ public class ArticleController {
private static String uploadPath = "/home/hobo/blog/blog-pic/";

@ApiOperation("获取文章详情")
@PostMapping(name = "获取文章详情", value = "/getDetail")
@GetMapping(name = "获取文章详情", value = "/getDetail")
public Object getDetail(Long blogId) {
return articleService.selectArticleDetail(blogId);
}
Expand Down Expand Up @@ -85,20 +83,26 @@ public Object updateArticle(@Valid UpdateArticleForm form) {
}

@ApiOperation("获取所有文章")
@PostMapping(name = "获得所有文章", value = "/selectAll")
@GetMapping(name = "获得所有文章", value = "/selectAll")
public Object selectAllArticle(PageForm form) {
return articleService.selectAll(form.getPageNum(), form.getPageSize());
}

@ApiOperation("根据标签查询文章")
@PostMapping(name = "根据标签查询文章", value = "/selectArticleByTags")
public Object selectArticleByTags(Integer tagId) {
return articleService.selectArticleByTags(tagId);
@GetMapping(name = "根据标签查询文章", value = "/selectArticleByTags")
public Object selectArticleByTags(SelectByTagForm form) {
return articleService.selectArticleByTags(form);
}

@ApiOperation("根据种类查询文章")
@PostMapping(name = "根据种类查询文章", value = "/selectArticleByTypes")
public Object selectArticleByTypes(Integer typeId) {
return articleService.selectArticleByTypes(typeId);
@GetMapping(name = "根据种类查询文章", value = "/selectArticleByTypes")
public Object selectArticleByTypes(SelectByTypeForm form) {
return articleService.selectArticleByTypes(form);
}

@ApiOperation("点赞或取消点赞文章")
@GetMapping(name = "点赞或取消点赞文章",value = "/giveLike")
public Object giveLike(GiveLikeForm form){
return articleService.likeArticle(form.getBlogId(),form.getIsLike());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,19 @@
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.Api;
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;
import org.springframework.web.bind.annotation.*;

/**
* @author hobo
* @description
*/
@RestController
@RequestMapping("/tags")
@Api(tags = "文章标签接口")
@CrossOrigin
public class TagsController {

@Autowired
Expand Down
50 changes: 50 additions & 0 deletions src/main/java/com/swpu/uchain/blog/controller/TypesController.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package com.swpu.uchain.blog.controller;

import com.swpu.uchain.blog.form.InsertTypesForm;
import com.swpu.uchain.blog.form.UpdateTypesForm;
import com.swpu.uchain.blog.service.TypesService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
* @author hobo
* @description
*/
@RestController
@RequestMapping("/types")
@Api(tags = "文章分类接口")
@CrossOrigin
public class TypesController {

@Autowired
private TypesService typesService;

@ApiOperation("添加分类")
@PostMapping(name = "添加分类",value = "/insert")
public Object insertType(InsertTypesForm form) {
return typesService.insertTypes(form);
}

@ApiOperation("更新分类")
@PostMapping(name = "更新分类",value = "/update")
public Object updateType(UpdateTypesForm form) {
return typesService.updateTypes(form);
}

@ApiOperation("删除分类")
@GetMapping(name = "删除分类",value = "/delete")
public Object deleteType(Integer id) {
return typesService.deleteTypes(id);
}

@ApiOperation("查询所有分类")
@GetMapping(name = "查询所有分类",value = "/all")
public Object selectAllType(){
return typesService.selectAllTypes();
}


}
9 changes: 7 additions & 2 deletions src/main/java/com/swpu/uchain/blog/dao/ArticleMapper.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.swpu.uchain.blog.entity.Article;
import com.swpu.uchain.blog.vo.ArticleListVO;
import com.swpu.uchain.blog.vo.ArticleVO;

import java.util.List;

Expand All @@ -18,11 +19,15 @@ public interface ArticleMapper {

Article selectByArticleTitle(String title);

ArticleVO selectByArticleId(Long id);

List<Article> selectByTagsId(Integer tagsId);

List<Article> selectByTypeId(Integer typeId);

List<ArticleListVO> getArticleList();

ArticleListVO selectArticlesByTagId(Integer tagId);
List<ArticleListVO> selectArticlesByTagId(Integer tagId);

ArticleListVO selectByArticlesByTypeId(Integer typeId);
List<ArticleListVO> selectByArticlesByTypeId(Integer typeId);
}
2 changes: 1 addition & 1 deletion src/main/java/com/swpu/uchain/blog/dao/TagsMapper.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,5 @@ public interface TagsMapper {

int updateByPrimaryKey(Tags record);

Tags selectByTag(String tagsMsg);
Tags selectByTagMsg(String tagsMsg);
}
4 changes: 0 additions & 4 deletions src/main/java/com/swpu/uchain/blog/dto/ArticleDTO.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,6 @@
public class ArticleDTO {

private Long id;
/**
* 概要
*/
private String digest;

/**
* 作者
Expand Down
8 changes: 7 additions & 1 deletion src/main/java/com/swpu/uchain/blog/enums/DefaultEnum.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.swpu.uchain.blog.enums;

import com.swpu.uchain.blog.entity.Types;
import lombok.Getter;

/**
Expand All @@ -11,7 +12,12 @@ public enum DefaultEnum {
/**
* 标签默认分组
*/
TAGS_DEFAULT_ENUM(1);;
TAGS_DEFAULT_ENUM(1),
/**
* 分类默认分组
*/
TYPE_DEFAULT_ENUM (1) ;
;
private Integer value;

DefaultEnum(Integer value) {
Expand Down
15 changes: 15 additions & 0 deletions src/main/java/com/swpu/uchain/blog/form/InsertTypesForm.java
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 InsertTypesForm {

@ApiModelProperty("分类")
private String typeMsg;
}
22 changes: 22 additions & 0 deletions src/main/java/com/swpu/uchain/blog/form/SelectByTagForm.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package com.swpu.uchain.blog.form;

import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

/**
* @author hobo
* @description
*/
@Data
public class SelectByTagForm {

@ApiModelProperty("页数")
private int pageNum;

@ApiModelProperty("一页展示的个数")
private int pageSize;

@ApiModelProperty("标签id")
private Integer tagId;

}
22 changes: 22 additions & 0 deletions src/main/java/com/swpu/uchain/blog/form/SelectByTypeForm.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package com.swpu.uchain.blog.form;

import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

/**
* @author hobo
* @description
*/
@Data
public class SelectByTypeForm {

@ApiModelProperty("页数")
private int pageNum;

@ApiModelProperty("一页展示的个数")
private int pageSize;

@ApiModelProperty("标签id")
private Integer typeId;

}
3 changes: 3 additions & 0 deletions src/main/java/com/swpu/uchain/blog/form/UpdateTagsForm.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.swpu.uchain.blog.form;

import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

/**
Expand All @@ -9,8 +10,10 @@
@Data
public class UpdateTagsForm {

@ApiModelProperty("标签id")
private Integer id;

@ApiModelProperty("标签")
private String tagsMsg;

}
19 changes: 19 additions & 0 deletions src/main/java/com/swpu/uchain/blog/form/UpdateTypesForm.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package com.swpu.uchain.blog.form;

import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

/**
* @author hobo
* @description
*/
@Data
public class UpdateTypesForm {

@ApiModelProperty("分类id")
private Integer id;

@ApiModelProperty("分类")
private String typeMsg;

}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
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.ArticleService;
import com.swpu.uchain.blog.service.TagsService;
import com.swpu.uchain.blog.util.ResultVOUtil;
import com.swpu.uchain.blog.util.TimeUtil;
Expand All @@ -33,10 +34,13 @@ public class TagsServiceImpl implements TagsService {
@Autowired
private ArticleMapper articleMapper;

@Autowired
private ArticleService articleService;


@Override
public ResultVO insertTags(InsertTagsForm form) {
if (tagsMapper.selectByTag(form.getTagsMsg()) != null) {
if (tagsMapper.selectByTagMsg(form.getTagsMsg()) != null) {
return ResultVOUtil.error(ResultEnum.TAG_IS_ALREADY_EXIST);
}
Tags tags = new Tags();
Expand Down Expand Up @@ -73,6 +77,7 @@ public ResultVO deleteTags(Integer id) {
// 将要删除的标签下的所有文章放入默认分组
for (Article article : articles) {
article.setTagsId(DefaultEnum.TAGS_DEFAULT_ENUM.getValue());
articleService.update(article);
}
if (tagsMapper.deleteByPrimaryKey(id) == 1) {
return ResultVOUtil.success();
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/com/swpu/uchain/blog/vo/ArticleListVO.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,12 @@ public class ArticleListVO {

private String creatTime;

private Integer tagsId;

private String tagsMsg;

private Integer typeId;

private String typeMsg;

private Integer commentSum;
Expand Down
Loading

0 comments on commit 492fab4

Please sign in to comment.