package com.nav.controller; import com.nav.common.api.CommonResult; import com.nav.pojo.Comment; import com.nav.service.PostService; import com.nav.vo.result.CommentResult; import com.nav.vo.result.LifePostResult; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.CrossOrigin; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.RestController; import java.util.HashMap; import java.util.List; import java.util.Map; /** * 类说明 * post的controller层 * @author zyx * @date 2022/4/28 20:43 */ @RestController @CrossOrigin(origins = "*") public class PostController { @Autowired PostService postService; @GetMapping("/lifePost") public CommonResult getLifePostList(){ return postService.getLifePostList(); } @GetMapping("/lifePost/{id}") public CommonResult getLifePostById(@PathVariable long id) { return postService.getLifePostById(id); } @GetMapping("/post/likeCount/{id}") public CommonResult updateLikeCountById(@PathVariable long id) { return postService.updateLikeCountById(id); } @GetMapping("/post/viewCount/{id}") public CommonResult updateViewCountById(@PathVariable long id) { return postService.updateViewCountById(id); } @GetMapping("lifePost/search/{Keyword}") public CommonResult getLifePostByKeyword(@PathVariable String Keyword) { return postService.getLifePostByKeyword(Keyword); } @GetMapping("comment/{id}") public Map getCommentByPostId(@PathVariable long id) { Map map=new HashMap<>(); CommonResult commonResult=postService.getCommentByPostId(id); List commentResult = (List) commonResult.getData(); map.put(commentResult.size(),commonResult); return map; } }