package com.tanpu.community.controller; import com.tanpu.common.api.CommonResp; import com.tanpu.common.auth.AuthLogin; import com.tanpu.common.auth.UserHolder; import com.tanpu.community.api.beans.qo.ThemeQo; import com.tanpu.community.api.beans.req.theme.*; import com.tanpu.community.api.beans.resp.CreateThemeResp; import com.tanpu.community.api.beans.resp.ThemeListResp; import com.tanpu.community.manager.ThemeManager; import io.swagger.annotations.ApiOperation; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.*; import javax.annotation.Resource; @RestController @Slf4j @RequestMapping(value = "/api/theme") public class ThemeController { @Autowired private ThemeManager themeManager; @Resource private UserHolder userHolder; @AuthLogin @ApiOperation("发表主题") @PostMapping(value = "/publish") @ResponseBody public CommonResp<CreateThemeResp> publishTheme(@Validated @RequestBody CreateThemeReq req) { String userId = userHolder.getUserId(); return CommonResp.success(themeManager.publishTheme(req, userId)); } @AuthLogin @ApiOperation("主题列表-推荐/关注/热门/最新") @PostMapping(value = "/list") @ResponseBody public CommonResp<ThemeListResp> selectInterestList(@Validated @RequestBody ThemeListReq req) { String userId = userHolder.getUserId(); ThemeListResp result = themeManager.queryList(req, userId); return CommonResp.success(result); } @AuthLogin @ApiOperation("主题正文") @GetMapping(value = "/detail") @ResponseBody public CommonResp<ThemeQo> getDetail(@RequestParam(value = "themeId") String themeId) { String userId = userHolder.getUserId(); return themeManager.getThemeDetail(themeId, userId); } @AuthLogin @ApiOperation("转发主题") @PostMapping(value = "/forward") @ResponseBody public CommonResp<CreateThemeResp> forwardTheme(@Validated @RequestBody ForwardThemeReq forwardThemeReq) { String userId = userHolder.getUserId(); return CommonResp.success(themeManager.forward(forwardThemeReq, userId)); } @AuthLogin @ApiOperation("点赞/取消点赞主题") @PostMapping(value = "/like") @ResponseBody public CommonResp<Void> likeOnTheme(@RequestBody LikeThemeReq req) { String userId = userHolder.getUserId(); themeManager.like(req, userId); return CommonResp.success(); } @AuthLogin @ApiOperation("用户删除主题") @GetMapping(value = "/delete") @ResponseBody public CommonResp<Void> delete(@RequestParam(value = "themeId") String themeId) { String userId = userHolder.getUserId(); themeManager.delete(themeId, userId); return CommonResp.success(); } @AuthLogin @ApiOperation("收藏/取消收藏主题") @PostMapping(value = "/collect") @ResponseBody public CommonResp<Void> bookTheme(@RequestBody CollectThemeReq req) { String userId = userHolder.getUserId(); themeManager.collect(req, userId); return CommonResp.success(); } @AuthLogin @ApiOperation("举报主题") @PostMapping(value = "/report") @ResponseBody public CommonResp<Void> complaintTheme(@RequestBody ReportThemeReq req) { String userId = userHolder.getUserId(); themeManager.report(req, userId); return CommonResp.success(); } @AuthLogin @ApiOperation("关注主题更新数量") @GetMapping(value = "/updateCount") @ResponseBody public CommonResp<Integer> updateCount() { String userId = userHolder.getUserId(); return CommonResp.success(themeManager.getFollowUpdateCount(userId)); } }