Commit d32d449c by 段启岩

2020.2.1第一次合并

parent 435834d9
......@@ -28,7 +28,7 @@ public class BlogCommentApi {
this.blogCommentService = blogCommentService;
}
@ApiOperation("创建评论")
@ApiOperation("发表评论")
@PostMapping("/blog/{blogId}/comment")
public Response createComment (@PathVariable("blogId") String blogId, @RequestBody @Valid BlogCommentForm blogCommentForm, @CurrentSubject Subject subject){
......
......@@ -3,14 +3,11 @@ package cn.meteor.beyondclouds.modules.blog.service.impl;
import cn.meteor.beyondclouds.modules.blog.entity.Blog;
import cn.meteor.beyondclouds.modules.blog.entity.BlogComment;
import cn.meteor.beyondclouds.modules.blog.enums.BlogCommentErrorCode;
import cn.meteor.beyondclouds.modules.blog.enums.BlogErrorCode;
import cn.meteor.beyondclouds.modules.blog.exception.BlogCommentServiceException;
import cn.meteor.beyondclouds.modules.blog.mapper.BlogCommentMapper;
import cn.meteor.beyondclouds.modules.blog.service.IBlogCommentService;
import cn.meteor.beyondclouds.modules.blog.service.IBlogService;
import cn.meteor.beyondclouds.modules.project.entity.ProjectComment;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
......@@ -43,14 +40,14 @@ public class BlogCommentServiceImpl extends ServiceImpl<BlogCommentMapper, BlogC
int depth;
//1.判断为第几级评论
if(parentId == null){
if (parentId == null) {
depth = 0;
}else {
} else {
QueryWrapper<BlogComment> queryWrapper = new QueryWrapper<>();
queryWrapper.eq("comment_id", parentId);
BlogComment blogCommentParent = getOne(queryWrapper);
depth = blogCommentParent.getDepth()+1;
depth = blogCommentParent.getDepth() + 1;
}
//2.创建评论
......@@ -62,14 +59,14 @@ public class BlogCommentServiceImpl extends ServiceImpl<BlogCommentMapper, BlogC
blogComment.setUserId(userId);
save(blogComment);
//3.查找上一层目录
if(blogComment.getParentId() == null) {
thread = "/"+ blogComment.getCommentId();
}else {
if (blogComment.getParentId() == null) {
thread = "/" + blogComment.getCommentId();
} else {
QueryWrapper<BlogComment> queryWrapper = new QueryWrapper<>();
queryWrapper.eq("comment_id", blogComment.getParentId());
//重新创建对象 存储上一级目录
BlogComment blogCommentPatent = getOne(queryWrapper);
thread = blogCommentPatent.getThread()+"/"+blogComment.getCommentId();
thread = blogCommentPatent.getThread() + "/" + blogComment.getCommentId();
}
blogComment.setThread(thread);
//4.更新路径信息
......@@ -78,7 +75,6 @@ public class BlogCommentServiceImpl extends ServiceImpl<BlogCommentMapper, BlogC
}
@Override
public void deleteComment(Integer commentId, String userId) throws BlogCommentServiceException {
Assert.notNull(commentId, "commentId must not be null");
......
......@@ -15,8 +15,8 @@ import cn.meteor.beyondclouds.modules.question.service.IQuestionService;
import cn.meteor.beyondclouds.modules.question.service.IQuestionTagService;
import cn.meteor.beyondclouds.modules.question.util.QuestionUtils;
import cn.meteor.beyondclouds.modules.question.vo.PageVO;
import cn.meteor.beyondclouds.modules.tag.entity.Tag;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.BeanUtils;
......@@ -26,6 +26,7 @@ import org.springframework.web.bind.annotation.*;
import javax.validation.Valid;
import java.util.HashSet;
import java.util.List;
/**
* @author 胡学良
......@@ -165,9 +166,9 @@ public class QuestionApi {
@Anonymous
@ApiOperation(("得到问题的引用标签"))
@GetMapping("/question/{questionId}/tags")
public Response<String> questionTags(@PathVariable("questionId") String questionId) {
public Response<List<Tag>> questionTags(@PathVariable("questionId") String questionId) {
try {
String tags = questionTagService.getQuestionTags(questionId);
List<Tag> tags = questionTagService.getQuestionTags(questionId);
return Response.success(tags);
} catch (QuestionTagServiceException e) {
e.printStackTrace();
......
package cn.meteor.beyondclouds.modules.question.bean;
import cn.meteor.beyondclouds.modules.question.entity.Question;
import cn.meteor.beyondclouds.modules.tag.entity.Tag;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.util.List;
/**
* @author 胡学良
* @since 2020/1/31
......@@ -20,6 +23,6 @@ public class QuestionDetails extends Question {
private String questionDetail;
@ApiModelProperty("标签")
private String tags;
private List<Tag> tags;
}
package cn.meteor.beyondclouds.modules.question.service;
import cn.meteor.beyondclouds.modules.question.entity.QuestionTag;
import cn.meteor.beyondclouds.modules.question.exception.QuestionServiceException;
import cn.meteor.beyondclouds.modules.question.exception.QuestionTagServiceException;
import cn.meteor.beyondclouds.modules.tag.entity.Tag;
import com.baomidou.mybatisplus.extension.service.IService;
import java.util.HashSet;
import java.util.List;
/**
* <p>
......@@ -31,5 +32,5 @@ public interface IQuestionTagService extends IService<QuestionTag> {
* @return 问题引用标签
* @throws QuestionTagServiceException 问题业务异常
*/
String getQuestionTags(String questionId) throws QuestionTagServiceException;
List<Tag> getQuestionTags(String questionId) throws QuestionTagServiceException;
}
package cn.meteor.beyondclouds.modules.question.service.impl;
import cn.meteor.beyondclouds.modules.question.bean.QuestionDetails;
import cn.meteor.beyondclouds.modules.question.entity.*;
import cn.meteor.beyondclouds.modules.question.entity.Question;
import cn.meteor.beyondclouds.modules.question.entity.QuestionCategory;
import cn.meteor.beyondclouds.modules.question.entity.QuestionExt;
import cn.meteor.beyondclouds.modules.question.entity.QuestionReply;
import cn.meteor.beyondclouds.modules.question.enums.QuestionErrorCode;
import cn.meteor.beyondclouds.modules.question.exception.QuestionServiceException;
import cn.meteor.beyondclouds.modules.question.exception.QuestionTagServiceException;
import cn.meteor.beyondclouds.modules.question.mapper.QuestionMapper;
import cn.meteor.beyondclouds.modules.question.service.*;
import cn.meteor.beyondclouds.modules.question.util.QuestionUtils;
import cn.meteor.beyondclouds.modules.tag.service.ITagService;
import cn.meteor.beyondclouds.modules.tag.entity.Tag;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
......@@ -180,7 +183,7 @@ public class QuestionServiceImpl extends ServiceImpl<QuestionMapper, Question> i
QuestionExt questionExt = questionExtService.getOne(QuestionUtils.getWrapper("question_id", questionId));
//4.获取问题标签
String tags = questionTagService.getQuestionTags(questionId);
List<Tag> tags = questionTagService.getQuestionTags(questionId);
//5.生成问题详情对象
QuestionDetails questionDetails = new QuestionDetails();
......
......@@ -3,7 +3,6 @@ package cn.meteor.beyondclouds.modules.question.service.impl;
import cn.meteor.beyondclouds.modules.question.entity.Question;
import cn.meteor.beyondclouds.modules.question.entity.QuestionTag;
import cn.meteor.beyondclouds.modules.question.enums.QuestionErrorCode;
import cn.meteor.beyondclouds.modules.question.exception.QuestionServiceException;
import cn.meteor.beyondclouds.modules.question.exception.QuestionTagServiceException;
import cn.meteor.beyondclouds.modules.question.mapper.QuestionTagMapper;
import cn.meteor.beyondclouds.modules.question.service.IQuestionService;
......@@ -18,6 +17,7 @@ import org.springframework.stereotype.Service;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.stream.Collectors;
/**
* <p>
......@@ -61,7 +61,7 @@ public class QuestionTagServiceImpl extends ServiceImpl<QuestionTagMapper, Quest
}
@Override
public String getQuestionTags(String questionId) throws QuestionTagServiceException {
public List<Tag> getQuestionTags(String questionId) throws QuestionTagServiceException {
//1.获取问题信息
Question question = questionService.getById(questionId);
......@@ -70,15 +70,13 @@ public class QuestionTagServiceImpl extends ServiceImpl<QuestionTagMapper, Quest
throw new QuestionTagServiceException(QuestionErrorCode.QUESTION_NOT_FOUND);
}
//2.得到问题引用标签
//2.得到问题引用的所有标签的ID
List<QuestionTag> questionTags = list(QuestionUtils.getWrapper("question_id", questionId));
StringBuilder stringBuilder = new StringBuilder();
stringBuilder.append("[");
for (QuestionTag questionTag : questionTags){
stringBuilder.append(tagService.getById(questionTag.getTagId()).getTagName()+",");
}
stringBuilder.deleteCharAt(stringBuilder.length()-1);
stringBuilder.append("]");
return stringBuilder.toString();
List<String> tagIds = questionTags.stream()
.map(QuestionTag::getTagId)
.collect(Collectors.toList());
// 3.根据tagIds查询出标签并返回
return tagService.listByIds(tagIds);
}
}
......@@ -139,7 +139,7 @@ public class UserApi {
@PostMapping("/my/blacklist/{userId}")
public Response blacklist(@PathVariable(name = "userId") String userId, @CurrentSubject Subject subject){
userBlacklistService.blacklist(userId,String.valueOf(subject.getId()));
userBlacklistService.blacklist(userId, (String) subject.getId());
return Response.success();
}
......@@ -148,7 +148,7 @@ public class UserApi {
@PostMapping("/user/{userId}/follower")
public Response follower(@PathVariable(name = "userId") String userId, @CurrentSubject Subject subject){
userFollowService.follower(userId, String.valueOf(subject.getId()));
userFollowService.follow(userId, (String) subject.getId());
return Response.success();
}
......@@ -157,7 +157,7 @@ public class UserApi {
@DeleteMapping("/user/{userId}/follower")
public Response delFollower(@PathVariable(name = "userId") String userId, @CurrentSubject Subject subject){
userFollowService.delFollower(userId, String.valueOf(subject.getId()));
userFollowService.delFollow(userId, String.valueOf(subject.getId()));
return Response.success();
}
......@@ -167,7 +167,7 @@ public class UserApi {
public Response myFans(@Valid PageForm pageForm, @CurrentSubject Subject subject){
// 根据userId获取粉丝并返回
IPage<UserFollow> fansPage = userFollowService.getFansPage(pageForm.getPage(), pageForm.getSize(), String.valueOf(subject.getId()));
IPage<UserFollow> fansPage = userFollowService.getFansPage(pageForm.getPage(), pageForm.getSize(), (String) subject.getId());
PageVO<UserFollow> fansPageVo = new PageVO<>();
fansPageVo.setTotalPage(fansPage.getPages());
fansPageVo.setDataList(fansPage.getRecords());
......
......@@ -15,8 +15,8 @@ public interface IUserBlacklistService extends IService<UserBlacklist> {
/**
* 拉黑
* @param blackId
* @param blackeId
* @param userId
*/
void blacklist(String blackId, String userId);
void blacklist(String blackeId, String userId);
}
......@@ -14,18 +14,18 @@ public interface IUserFollowService extends IService<UserFollow> {
/**
* 关注
* @param userId
* @param myUserId
* @param followedId 关注者的ID
* @param followerId 被关注者的ID
*/
void follower(String userId, String myUserId);
void follow(String followedId, String followerId);
/**
* 取消关注
* @param userId
* @param myUserId
* @param followedId
* @param followerId
*/
void delFollower(String userId, String myUserId);
void delFollow(String followedId, String followerId);
......
......@@ -19,13 +19,13 @@ public class UserBlacklistServiceImpl extends ServiceImpl<UserBlacklistMapper, U
/**
* 拉黑
* @param blackId 拉黑用户的id
* @param blackedId 被拉黑用户的id
* @param userId
*/
@Override
public void blacklist(String blackId, String userId) {
public void blacklist(String blackedId, String userId) {
UserBlacklist userBlacklist = new UserBlacklist();
userBlacklist.setBlackedId(blackId);
userBlacklist.setBlackedId(blackedId);
userBlacklist.setUserId(userId);
save(userBlacklist);
}
......
......@@ -30,25 +30,25 @@ public class UserFollowServiceImpl extends ServiceImpl<IUserFollowMapper, UserFo
/**
* 关注
* @param userId 被关注用户的userId
* @param myUserId 当前用户的userId
* @param followedId 被关注用户的userId
* @param followerId 关注者的userId
*/
@Override
public void follower(String userId, String myUserId) {
public void follow(String followedId, String followerId) {
UserFollow userFollow = new UserFollow();
//1.查询被关注用户的基本信息
User user = userService.getById(userId);
userFollow.setFollowedId(userId);
userFollow.setFollowedNick(user.getNickName());
userFollow.setFollowedAvatar(user.getUserAvatar());
User followedUser = userService.getById(followedId);
userFollow.setFollowedId(followedId);
userFollow.setFollowedNick(followedUser.getNickName());
userFollow.setFollowedAvatar(followedUser.getUserAvatar());
//2.查询我的基本信息
User myUser = userService.getById(myUserId);
userFollow.setFollowerId(myUserId);
userFollow.setFollowerNick(myUser.getNickName());
userFollow.setFollowerAvatar(myUser.getUserAvatar());
User followerUser = userService.getById(followerId);
userFollow.setFollowerId(followerId);
userFollow.setFollowerNick(followerUser.getNickName());
userFollow.setFollowerAvatar(followerUser.getUserAvatar());
userFollow.setFollowStatus(0);
save(userFollow);
......@@ -57,19 +57,19 @@ public class UserFollowServiceImpl extends ServiceImpl<IUserFollowMapper, UserFo
/**
* 取消关注
* @param userId 被关注用户的userId
* @param myUserId 当前用户的userId
* @param followedId 被关注用户的userId
* @param followerId 关注者户的userId
*/
@Override
public void delFollower(String userId, String myUserId) {
public void delFollow(String followedId, String followerId) {
//1.查找符合条件的关注信息
UpdateWrapper updateWrapper = new UpdateWrapper();
updateWrapper.eq("follower_id", myUserId);
updateWrapper.eq("followed_id", userId);
updateWrapper.eq("followed_id", followedId);
updateWrapper.eq("follower_id", followerId);
//2.将关注状态设置为-1并保存
updateWrapper.set("follow_status",-1);
updateWrapper.set("follow_status", -1);
update(updateWrapper);
}
......@@ -83,9 +83,9 @@ public class UserFollowServiceImpl extends ServiceImpl<IUserFollowMapper, UserFo
@Override
public IPage<UserFollow> getFansPage(Integer pageNumber, Integer pageSize, String userId) {
IPage<UserFollow> page = new Page<>(pageNumber, pageSize);
QueryWrapper<UserFollow> projectQueryWrapper = new QueryWrapper<>();
projectQueryWrapper.eq("followed_id", userId);
return page(page, projectQueryWrapper);
QueryWrapper<UserFollow> userFollowQueryWrapper = new QueryWrapper<>();
userFollowQueryWrapper.eq("followed_id", userId);
return page(page, userFollowQueryWrapper);
}
/**
......@@ -98,9 +98,9 @@ public class UserFollowServiceImpl extends ServiceImpl<IUserFollowMapper, UserFo
@Override
public IPage<UserFollow> getFollowersPage(Integer pageNumber, Integer pageSize, String userId) {
IPage<UserFollow> page = new Page<>(pageNumber, pageSize);
QueryWrapper<UserFollow> projectQueryWrapper = new QueryWrapper<>();
projectQueryWrapper.eq("follower_id", userId);
return page(page, projectQueryWrapper);
QueryWrapper<UserFollow> userFollowQueryWrapper = new QueryWrapper<>();
userFollowQueryWrapper.eq("follower_id", userId);
return page(page, userFollowQueryWrapper);
}
}
......
......@@ -3,7 +3,7 @@ spring:
driver-class-name: com.mysql.cj.jdbc.Driver
url: jdbc:mysql://127.0.0.1:3306/beyond_clouds?useUnicode=true&characterEncoding=UTF-8&useSSL=false&allowPublicKeyRetrieval=true
username: root
password: 197442
password: 100Centa30821%mysql
swagger:
enable: true
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment