|
|
|
@ -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();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|