SearchController.java 2.77 KB
Newer Older
张辰's avatar
张辰 committed
1 2 3 4
package com.tanpu.community.controller;

import com.tanpu.common.api.CommonResp;
import com.tanpu.common.auth.UserHolder;
刘基明's avatar
刘基明 committed
5
import com.tanpu.community.api.beans.qo.FollowQo;
张辰's avatar
张辰 committed
6
import com.tanpu.community.api.beans.req.search.ThemeFullSearchReq;
刘基明's avatar
刘基明 committed
7
import com.tanpu.community.api.beans.resp.ThemeAndUserSearchResp;
张辰's avatar
张辰 committed
8
import com.tanpu.community.api.beans.resp.ThemeFullSearchResp;
刘基明's avatar
刘基明 committed
9 10
import com.tanpu.community.api.beans.resp.UserSearchResp;
import com.tanpu.community.manager.HomePageManager;
张辰's avatar
张辰 committed
11 12 13 14
import com.tanpu.community.manager.ThemeManager;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
刘基明's avatar
刘基明 committed
15 16 17 18 19
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
张辰's avatar
张辰 committed
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34

import javax.annotation.Resource;
import java.util.List;

@RestController
@Slf4j
@RequestMapping(value = "/api/search")
public class SearchController {

    @Resource
    private UserHolder userHolder;

    @Autowired
    private ThemeManager themeManager;

刘基明's avatar
刘基明 committed
35 36 37
    @Autowired
    private HomePageManager homePageManager;

张辰's avatar
张辰 committed
38
    // 内容全文搜索
张辰's avatar
张辰 committed
39 40 41 42
    @ApiOperation("全文搜索主题")
    @PostMapping(value = "/themeFullText")
    @ResponseBody
    public CommonResp<ThemeFullSearchResp> themeFullText(@RequestBody ThemeFullSearchReq req) {
张辰's avatar
张辰 committed
43
        ThemeFullSearchResp resp = themeManager.themeFullSearch(req.keyword, req.page.pageNumber, req.page.pageSize, req.ident, userHolder.getUserId());
张辰's avatar
张辰 committed
44
        return CommonResp.success(resp);
张辰's avatar
张辰 committed
45 46
    }

刘基明's avatar
刘基明 committed
47
    // 用户+内容全文搜索
刘基明's avatar
刘基明 committed
48 49
    @ApiOperation("综合搜索")
    @PostMapping(value = "/muLtipuleSearch")
刘基明's avatar
刘基明 committed
50 51 52
    @ResponseBody
    public CommonResp<ThemeAndUserSearchResp> themeFullTextAndUserSearch(@RequestBody ThemeFullSearchReq req) {
        ThemeFullSearchResp themeFullSearch = themeManager.themeFullSearch(req.keyword, req.page.pageNumber, req.page.pageSize, req.ident, userHolder.getUserId());
刘基明's avatar
刘基明 committed
53
        List<FollowQo> users = homePageManager.userNameSerach(req.keyword, 1, 3, req.ident, userHolder.getUserId());
刘基明's avatar
刘基明 committed
54 55 56 57 58 59 60 61 62 63 64 65 66

        return CommonResp.success(ThemeAndUserSearchResp.builder().themes(themeFullSearch.getThemes()).users(users).build());
    }

    // 用户搜索
    @ApiOperation("用户姓名模糊查询")
    @PostMapping(value = "/userNameFuzzy")
    @ResponseBody
    public CommonResp<UserSearchResp> userNameSerach(@RequestBody ThemeFullSearchReq req) {
        List<FollowQo> users = homePageManager.userNameSerach(req.keyword, req.page.pageNumber, req.page.pageSize, req.ident, userHolder.getUserId());
        return CommonResp.success(UserSearchResp.builder().users(users).build());
    }

张辰's avatar
张辰 committed
67
}