package com.izouma.zhirongip.web;

import com.izouma.zhirongip.dto.SearchDTO;
import com.izouma.zhirongip.exception.BusinessException;
import com.izouma.zhirongip.service.AllService;
import jodd.util.StringUtil;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/all")
@AllArgsConstructor
public class AllController {
    private AllService allService;

    @GetMapping("/search")
    public List<SearchDTO> search(String search) {
        if (StringUtil.isEmpty(search)) {
            throw new BusinessException("请输入关键词");
        }
        return allService.search(search);
    }

    /**
     * 添加浏览记录
     *
     * @param id   主键
     * @param type "CopyrightDemand":
     *             "LogoDemand":
     *             "PatentDemand":
     *             "TechProductDemand":
     *             "Purchase":
     *             "SuccessCase":
     *             "Copyright":
     *             "Logo":
     *             "Patent":
     *             "TechnologyProduct":
     */
    @GetMapping("/addView")
    public void addView(Long id, String type) {
        allService.addView(id, type);
    }

}
