1.uniform response status code for comment component

main
Gary 1 year ago
parent c7414e18e7
commit 67b26776b5

@ -3,9 +3,12 @@ package com.luoo.comment.controller;
import com.luoo.comment.pojo.Comment;
import com.luoo.comment.service.CommentService;
import entity.PageResult;
import entity.Result;
import entity.StatusCode;
import api.PageResult;
import api.Result;
import api.StatusCode;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.redis.core.RedisTemplate;
@ -22,64 +25,62 @@ public class CommentController {
@Autowired
private RedisTemplate redisTemplate;
@RequestMapping(method = RequestMethod.GET)
public Result findAll(){
return new Result(true, StatusCode.OK,"",commentService.findAll());
@GetMapping
public Result<List<Comment>> findAll(){
return Result.success(commentService.findAll());
}
@RequestMapping(value = "/findByVolid/{volid}",method = RequestMethod.GET)
public Result findByVolid(@PathVariable String volid){
return new Result(true,StatusCode.OK,"查询成功",commentService.findByVolid(volid));
@GetMapping("/findByVolid/{volid}")
public Result<List<Comment>> findByVolid(@PathVariable String volid){
return Result.success(commentService.findByVolid(volid));
}
@RequestMapping(value = "/{commentId}",method = RequestMethod.GET)
public Result findById(@PathVariable String commentId) {
return new Result(true, StatusCode.OK,"",commentService.findById(commentId));
@GetMapping("/{commentId}")
public Result<Comment> findById(@PathVariable String commentId) {
return Result.success(commentService.findById(commentId));
}
@RequestMapping(method = RequestMethod.POST)
public Result save(@RequestBody Comment comment){
@PostMapping
public Result<Void> save(@RequestBody Comment comment){
commentService.save(comment);
return new Result(true,StatusCode.OK,"保存成功");
return Result.success();
}
@RequestMapping(value = "/{commentId}",method = RequestMethod.PUT)
public Result update(@PathVariable String commentId,@RequestBody Comment comment){
@PutMapping("/{commentId}")
public Result<Void> update(@PathVariable String commentId,@RequestBody Comment comment){
comment.set_id(commentId);
commentService.update(comment);
return new Result(true,StatusCode.OK,"修改成功");
return Result.success();
}
@RequestMapping(value = "/{commentId}",method = RequestMethod.DELETE)
public Result delete(@PathVariable String commentId){
@DeleteMapping("/{commentId}")
public Result<Void> delete(@PathVariable String commentId){
commentService.deleteById(commentId);
return new Result(true,StatusCode.OK,"删除成功");
return Result.success();
}
@RequestMapping(value = "/{parentid}/{page}/{size}",method = RequestMethod.GET)
public Result findByParentid(@PathVariable String parentid,@PathVariable int page,@PathVariable int size){
@GetMapping("/{parentid}/{page}/{size}")
public Result<PageResult<Comment>> findByParentid(@PathVariable String parentid,@PathVariable int page,@PathVariable int size){
Page<Comment> pageData = commentService.findByParentId(parentid,page,size);
return new Result(true,StatusCode.OK,"查询成功",new PageResult<Comment>(pageData.getTotalElements(),pageData.getContent()));
return Result.success(new PageResult<Comment>(pageData.getTotalElements(),pageData.getContent()));
}
@RequestMapping(value = "/thumbup/{commentId}",method = RequestMethod.PUT)
@PutMapping("/thumbup/{commentId}")
public Result thumbup(@PathVariable String commentId){
String userid="111";
if (redisTemplate.opsForValue().get("thumbup_"+userid)!=null){
return new Result(true,StatusCode.REPERROR,"重复提交");
return Result.failed(StatusCode.COMMENT_REPEAT_SUBMIT);
}
commentService.thumbup(commentId);
redisTemplate.opsForValue().set("thumbup_"+userid,1);
return new Result(true,StatusCode.OK,"点赞成功");
return Result.success();
}
}

@ -17,6 +17,7 @@ public enum StatusCode implements IErrorCode {
MUSIC_COMMON_FAILED(20000, "歌曲模块失败"),
// comment 模块错误码以30XXX不足5位补0;
COMMENT_COMMON_FAILED(30000, "评论模块失败"),
COMMENT_REPEAT_SUBMIT(30001, "评论重复提交"),
// friend 模块错误码以40XXX不足5位补0;
FRIEND_COMMON_FAILED(40000, "交友模块失败"),
// tag 模块错误码以50XXX不足5位补0;

Loading…
Cancel
Save