api 검색 옵션 추가
This commit is contained in:
@@ -1,9 +1,28 @@
|
|||||||
package com.eactive.httpmockserver;
|
package com.eactive.httpmockserver;
|
||||||
|
|
||||||
|
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.JpaRepository;
|
||||||
|
import org.springframework.data.jpa.repository.Query;
|
||||||
|
import org.springframework.data.repository.query.Param;
|
||||||
import org.springframework.stereotype.Repository;
|
import org.springframework.stereotype.Repository;
|
||||||
|
|
||||||
@Repository
|
@Repository
|
||||||
public interface ApiDao extends JpaRepository<ApiInfo, Long> {
|
public interface ApiDao extends JpaRepository<ApiInfo, Long> {
|
||||||
ApiInfo findByUrlAndServiceValue(String url, String serviceValue);
|
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);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -70,23 +70,28 @@ public class ApiManageRestController {
|
|||||||
public DataTablesResponse<ApiInfo> getAllApisForDatatables(@RequestBody DataTablesRequest req) {
|
public DataTablesResponse<ApiInfo> getAllApisForDatatables(@RequestBody DataTablesRequest req) {
|
||||||
Pageable pageable = assignJpaPageable(req);
|
Pageable pageable = assignJpaPageable(req);
|
||||||
|
|
||||||
// search option
|
// // search option
|
||||||
Example<ApiInfo> example = null;
|
// Example<ApiInfo> example = null;
|
||||||
if (StringUtils.isNotBlank(req.getSearch().getValue())) {
|
// if (StringUtils.isNotBlank(req.getSearch().getValue())) {
|
||||||
ApiInfo apiInfo = new ApiInfo();
|
// ApiInfo apiInfo = new ApiInfo();
|
||||||
apiInfo.setApiGroupName(req.getSearch().getValue());
|
// apiInfo.setApiGroupName(req.getSearch().getValue());
|
||||||
apiInfo.setApiName(req.getSearch().getValue());
|
// apiInfo.setApiName(req.getSearch().getValue());
|
||||||
apiInfo.setServiceValue(req.getSearch().getValue());
|
// apiInfo.setServiceValue(req.getSearch().getValue());
|
||||||
|
//
|
||||||
ExampleMatcher matcher = ExampleMatcher.matchingAny()
|
// ExampleMatcher matcher = ExampleMatcher.matchingAny()
|
||||||
.withMatcher("apiGroupName", new GenericPropertyMatcher().contains().ignoreCase())
|
// .withMatcher("apiGroupName", new GenericPropertyMatcher().contains().ignoreCase())
|
||||||
.withMatcher("apiName", new GenericPropertyMatcher().contains().ignoreCase())
|
// .withMatcher("apiName", new GenericPropertyMatcher().contains().ignoreCase())
|
||||||
.withMatcher("serviceValue", new GenericPropertyMatcher().startsWith().ignoreCase());
|
// .withMatcher("serviceValue", new GenericPropertyMatcher().startsWith().ignoreCase());
|
||||||
example = Example.of(apiInfo, matcher);
|
// example = Example.of(apiInfo, matcher);
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
DataTablesResponse<ApiInfo> res = new DataTablesResponse<ApiInfo>(apiService.findApis(example, pageable));
|
// DataTablesResponse<ApiInfo> res = new DataTablesResponse<ApiInfo>(apiService.findApis(example, pageable));
|
||||||
res.setRecordsFiltered(apiService.getRecordsCount(example));
|
// 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.setRecordsTotal(apiService.getRecordsCount(null));
|
||||||
res.setDraw(req.getDraw());
|
res.setDraw(req.getDraw());
|
||||||
return res;
|
return res;
|
||||||
|
|||||||
@@ -15,6 +15,10 @@ public interface ApiService {
|
|||||||
|
|
||||||
public List<ApiInfo> findApis(Example<ApiInfo> example, Pageable pageable);
|
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 update(ApiInfo apiInfo);
|
||||||
|
|
||||||
public ApiInfo findByUrlAndServiceValue(String url, String serviceValue);
|
public ApiInfo findByUrlAndServiceValue(String url, String serviceValue);
|
||||||
|
|||||||
@@ -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
|
@Override
|
||||||
@Transactional(propagation = Propagation.REQUIRED, readOnly = false)
|
@Transactional(propagation = Propagation.REQUIRED, readOnly = false)
|
||||||
public ApiInfo update(ApiInfo apiInfo) {
|
public ApiInfo update(ApiInfo apiInfo) {
|
||||||
@@ -77,4 +88,13 @@ public class ApiServiceImpl implements ApiService {
|
|||||||
return apiDao.count(example);
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,6 +11,12 @@
|
|||||||
th:href="@{/plugins/datatables-responsive/css/responsive.bootstrap4.min.css}">
|
th:href="@{/plugins/datatables-responsive/css/responsive.bootstrap4.min.css}">
|
||||||
<link rel="stylesheet"
|
<link rel="stylesheet"
|
||||||
th:href="@{/plugins/datatables-buttons/css/buttons.bootstrap4.min.css}">
|
th:href="@{/plugins/datatables-buttons/css/buttons.bootstrap4.min.css}">
|
||||||
|
|
||||||
|
<style type="text/css" class="init">
|
||||||
|
.search-ext {
|
||||||
|
float:right;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
</th:block>
|
</th:block>
|
||||||
|
|
||||||
<div class="content-wrapper" layout:fragment="content">
|
<div class="content-wrapper" layout:fragment="content">
|
||||||
@@ -66,6 +72,17 @@
|
|||||||
<!-- /.row -->
|
<!-- /.row -->
|
||||||
</div>
|
</div>
|
||||||
<!-- /.container-fluid -->
|
<!-- /.container-fluid -->
|
||||||
|
|
||||||
|
<div id="api_search" style="display:none">
|
||||||
|
<label>
|
||||||
|
API그룹:
|
||||||
|
<select id="searchApiGroupName" style="margin-left: 0.5em; height: calc(1.8125rem + 2px); border: 1px solid #ced4da; border-radius: 0.2rem;">
|
||||||
|
<option value="">-- 선택 --</option>
|
||||||
|
<option value="저축은행중앙회">저축은행중앙회</option>
|
||||||
|
<option value="Finnq">Finnq</option>
|
||||||
|
</select>
|
||||||
|
</label>
|
||||||
|
</div>
|
||||||
</section>
|
</section>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@@ -103,6 +120,7 @@
|
|||||||
"serverSide": true,
|
"serverSide": true,
|
||||||
"pageLength": 50,
|
"pageLength": 50,
|
||||||
"searchDelay": 1200,
|
"searchDelay": 1200,
|
||||||
|
"dom": '<"row"<"col-sm-12 col-md-6"B><"col-sm-12 col-md-6"<"search-ext">f>>rt<"row"<"col-sm-12 col-md-6"i><"col-sm-12 col-md-6"p>>',
|
||||||
"ajax": {
|
"ajax": {
|
||||||
"url": "/manage/rest/apis",
|
"url": "/manage/rest/apis",
|
||||||
"type": "POST",
|
"type": "POST",
|
||||||
@@ -144,9 +162,15 @@
|
|||||||
],
|
],
|
||||||
"buttons": ["new", "excel", "colvis"],
|
"buttons": ["new", "excel", "colvis"],
|
||||||
"initComplete": function() {
|
"initComplete": function() {
|
||||||
listApiTable.buttons().container().appendTo('#listApiTable_wrapper .col-md-6:eq(0)');
|
//listApiTable.buttons().container().appendTo('#listApiTable_wrapper .col-md-6:eq(0)');
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
$('.search-ext').html($('#api_search').html());
|
||||||
|
|
||||||
|
$("#searchApiGroupName").change(function(){
|
||||||
|
listApiTable.columns(0).search(this.value).draw(); // apiGroupName
|
||||||
|
});
|
||||||
|
|
||||||
/*
|
/*
|
||||||
$(".dataTables_filter input").unbind().bind("input", function(e) { // Bind our desired behavior
|
$(".dataTables_filter input").unbind().bind("input", function(e) { // Bind our desired behavior
|
||||||
|
|||||||
Reference in New Issue
Block a user