package com.goomood.es.controller;

import com.goomood.common.core.domain.AjaxResult;
import com.goomood.es.dto.DelFIleIndexDto;
import com.goomood.es.service.FileService;
import com.goomood.es.service.SearchService;
import com.goomood.phm.domain.dto.CataiDTO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.io.IOException;
import java.util.List;
import java.util.Map;

/**
 * @author pawn
 * @version 1.0
 * @description: 文件搜索
 * @date 2024/11/19 16:07
 */
@RestController
@RequestMapping("/file/search")
public class FileSearchController {


    @Autowired
    private SearchService searchService;


    @Autowired
    private FileService fileService;


    @GetMapping("/search")
    public AjaxResult searchFiles(@RequestParam("keyword") String keyword) {
        try {
            List<Map<String, Object>> results = searchService.searchByKeyword(keyword);
            return AjaxResult.success(results);
        } catch (IOException e) {
            return AjaxResult.error("Error searching files: " + e.getMessage());
        }
    }

    @PostMapping("/deleteDocument")
    public AjaxResult deleteDocument(@RequestBody DelFIleIndexDto delFIleIndexDto){
        try {
            fileService.deleteDocument(delFIleIndexDto);
        } catch (IOException e) {
            return AjaxResult.error(e.getMessage());
        }
        return AjaxResult.success();
    }




}
