api 검색 옵션 추가
This commit is contained in:
@@ -1,9 +1,33 @@
|
||||
package com.eactive.httpmockserver;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.data.jpa.repository.Query;
|
||||
import org.springframework.data.repository.query.Param;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
@Repository
|
||||
public interface ApiDao extends JpaRepository<ApiInfo, Long> {
|
||||
ApiInfo findByUrlAndServiceValue(String url, String serviceValue);
|
||||
|
||||
@Query(value = "SELECT ai FROM ApiInfo ai WHERE (:apiGroupName is null or ai.apiGroupName = :apiGroupName)"
|
||||
+ "AND ((:searchStr1 is null or ai.apiGroupName LIKE %:searchStr1%)"
|
||||
+ "OR (:searchStr2 is null or ai.apiName LIKE %:searchStr2%)"
|
||||
+ "OR (:searchStr3 is null or ai.serviceValue LIKE :searchStr3%))")
|
||||
Page<ApiInfo> findApisByParameters(@Param("apiGroupName") String apiGroupName,
|
||||
@Param("searchStr1") String searchStr1, @Param("searchStr2") String searchStr2,
|
||||
@Param("searchStr3") String searchStr3, Pageable pageable);
|
||||
|
||||
@Query(value = "SELECT COUNT(*) FROM ApiInfo ai WHERE (:apiGroupName is null or ai.apiGroupName = :apiGroupName)"
|
||||
+ "AND ((:searchStr1 is null or ai.apiGroupName LIKE %:searchStr1%)"
|
||||
+ "OR (:searchStr2 is null or ai.apiName LIKE %:searchStr2%)"
|
||||
+ "OR (:searchStr3 is null or ai.serviceValue LIKE :searchStr3%))")
|
||||
long countApisByParameters(@Param("apiGroupName") String apiGroupName, @Param("searchStr1") String searchStr1,
|
||||
@Param("searchStr2") String searchStr2, @Param("searchStr3") String searchStr3);
|
||||
|
||||
@Query(value = "SELECT ai.apiGroupName FROM ApiInfo ai GROUP BY ai.apiGroupName")
|
||||
List<String> findAllApiGroupName();
|
||||
}
|
||||
|
||||
@@ -4,7 +4,6 @@ import java.util.Optional;
|
||||
|
||||
import javax.validation.Valid;
|
||||
|
||||
import com.eactive.httpmockserver.script.ScriptInfoService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.http.HttpMethod;
|
||||
@@ -17,6 +16,8 @@ import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
|
||||
import com.eactive.httpmockserver.script.ScriptInfoService;
|
||||
|
||||
@Controller
|
||||
public class ApiManageController {
|
||||
@Autowired
|
||||
@@ -30,7 +31,7 @@ public class ApiManageController {
|
||||
|
||||
@GetMapping("/manage/findAllApis")
|
||||
public String getAllApis(Pageable pageable, Model model) {
|
||||
//model.addAttribute("apiInfoList", apiService.findAllApis(pageable));
|
||||
model.addAttribute("apiGroupNameList", apiService.findAllApiGroupName());
|
||||
return "page/list-api";
|
||||
}
|
||||
|
||||
|
||||
@@ -70,23 +70,28 @@ public class ApiManageRestController {
|
||||
public DataTablesResponse<ApiInfo> getAllApisForDatatables(@RequestBody DataTablesRequest req) {
|
||||
Pageable pageable = assignJpaPageable(req);
|
||||
|
||||
// search option
|
||||
Example<ApiInfo> example = null;
|
||||
if (StringUtils.isNotBlank(req.getSearch().getValue())) {
|
||||
ApiInfo apiInfo = new ApiInfo();
|
||||
apiInfo.setApiGroupName(req.getSearch().getValue());
|
||||
apiInfo.setApiName(req.getSearch().getValue());
|
||||
apiInfo.setServiceValue(req.getSearch().getValue());
|
||||
|
||||
ExampleMatcher matcher = ExampleMatcher.matchingAny()
|
||||
.withMatcher("apiGroupName", new GenericPropertyMatcher().contains().ignoreCase())
|
||||
.withMatcher("apiName", new GenericPropertyMatcher().contains().ignoreCase())
|
||||
.withMatcher("serviceValue", new GenericPropertyMatcher().startsWith().ignoreCase());
|
||||
example = Example.of(apiInfo, matcher);
|
||||
}
|
||||
|
||||
DataTablesResponse<ApiInfo> res = new DataTablesResponse<ApiInfo>(apiService.findApis(example, pageable));
|
||||
res.setRecordsFiltered(apiService.getRecordsCount(example));
|
||||
// // search option
|
||||
// Example<ApiInfo> example = null;
|
||||
// if (StringUtils.isNotBlank(req.getSearch().getValue())) {
|
||||
// ApiInfo apiInfo = new ApiInfo();
|
||||
// apiInfo.setApiGroupName(req.getSearch().getValue());
|
||||
// apiInfo.setApiName(req.getSearch().getValue());
|
||||
// apiInfo.setServiceValue(req.getSearch().getValue());
|
||||
//
|
||||
// ExampleMatcher matcher = ExampleMatcher.matchingAny()
|
||||
// .withMatcher("apiGroupName", new GenericPropertyMatcher().contains().ignoreCase())
|
||||
// .withMatcher("apiName", new GenericPropertyMatcher().contains().ignoreCase())
|
||||
// .withMatcher("serviceValue", new GenericPropertyMatcher().startsWith().ignoreCase());
|
||||
// example = Example.of(apiInfo, matcher);
|
||||
// }
|
||||
//
|
||||
// DataTablesResponse<ApiInfo> res = new DataTablesResponse<ApiInfo>(apiService.findApis(example, pageable));
|
||||
// res.setRecordsFiltered(apiService.getRecordsCount(example));
|
||||
String apiGroupName = StringUtils.defaultIfBlank(req.getColumns().get(0).getSearch().getValue(), null);
|
||||
String searchStr = StringUtils.defaultIfBlank(req.getSearch().getValue(), null);
|
||||
DataTablesResponse<ApiInfo> res = new DataTablesResponse<ApiInfo>(
|
||||
apiService.findApis(apiGroupName, searchStr, pageable));
|
||||
res.setRecordsFiltered(apiService.countApis(apiGroupName, searchStr));
|
||||
res.setRecordsTotal(apiService.getRecordsCount(null));
|
||||
res.setDraw(req.getDraw());
|
||||
return res;
|
||||
|
||||
@@ -15,6 +15,10 @@ public interface ApiService {
|
||||
|
||||
public List<ApiInfo> findApis(Example<ApiInfo> example, Pageable pageable);
|
||||
|
||||
public List<ApiInfo> findApis(String apiGroupName, String searchStr, Pageable pageable);
|
||||
|
||||
public long countApis(String apiGroupName, String searchStr);
|
||||
|
||||
public ApiInfo update(ApiInfo apiInfo);
|
||||
|
||||
public ApiInfo findByUrlAndServiceValue(String url, String serviceValue);
|
||||
@@ -22,4 +26,6 @@ public interface ApiService {
|
||||
public void delete(Long id);
|
||||
|
||||
public long getRecordsCount(Example<ApiInfo> example);
|
||||
|
||||
public List<String> findAllApiGroupName();
|
||||
}
|
||||
|
||||
@@ -52,6 +52,17 @@ public class ApiServiceImpl implements ApiService {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ApiInfo> findApis(String apiGroupName, String searchStr, Pageable pageable) {
|
||||
Page<ApiInfo> pagedResult = apiDao.findApisByParameters(apiGroupName, searchStr, searchStr, searchStr,
|
||||
pageable);
|
||||
if (pagedResult.hasContent()) {
|
||||
return pagedResult.getContent();
|
||||
} else {
|
||||
return new ArrayList<ApiInfo>();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(propagation = Propagation.REQUIRED, readOnly = false)
|
||||
public ApiInfo update(ApiInfo apiInfo) {
|
||||
@@ -77,4 +88,18 @@ public class ApiServiceImpl implements ApiService {
|
||||
return apiDao.count(example);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public long countApis(String apiGroupName, String searchStr) {
|
||||
if (apiGroupName == null && searchStr == null) {
|
||||
return apiDao.count();
|
||||
} else {
|
||||
return apiDao.countApisByParameters(apiGroupName, searchStr, searchStr, searchStr);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> findAllApiGroupName() {
|
||||
return apiDao.findAllApiGroupName();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user