|
@@ -1,13 +1,15 @@
|
|
|
-package org.ssssssss.magicapi.config;
|
|
|
+package org.ssssssss.magicapi.provider.impl;
|
|
|
|
|
|
import org.springframework.jdbc.core.BeanPropertyRowMapper;
|
|
|
import org.springframework.jdbc.core.JdbcTemplate;
|
|
|
import org.springframework.jdbc.core.RowMapper;
|
|
|
+import org.ssssssss.magicapi.config.ApiInfo;
|
|
|
+import org.ssssssss.magicapi.provider.ApiServiceProvider;
|
|
|
|
|
|
import java.util.List;
|
|
|
import java.util.UUID;
|
|
|
|
|
|
-public class MagicApiService {
|
|
|
+public class DefaultApiServiceProvider implements ApiServiceProvider {
|
|
|
|
|
|
private final String deleteById = "delete from magic_api_info where id = ?";
|
|
|
private final String deleteByGroupName = "delete from magic_api_info where api_group_name = ?";
|
|
@@ -21,45 +23,55 @@ public class MagicApiService {
|
|
|
private RowMapper<ApiInfo> rowMapper = new BeanPropertyRowMapper<>(ApiInfo.class);
|
|
|
private JdbcTemplate template;
|
|
|
|
|
|
- public MagicApiService(JdbcTemplate template) {
|
|
|
+ public DefaultApiServiceProvider(JdbcTemplate template) {
|
|
|
this.template = template;
|
|
|
}
|
|
|
|
|
|
- protected boolean delete(String id) {
|
|
|
+ public boolean delete(String id) {
|
|
|
return template.update(deleteById, id) > 0;
|
|
|
}
|
|
|
|
|
|
- protected boolean deleteGroup(String groupName) {
|
|
|
+ public boolean deleteGroup(String groupName) {
|
|
|
return template.update(deleteByGroupName, groupName) > 0;
|
|
|
}
|
|
|
|
|
|
- protected List<ApiInfo> list() {
|
|
|
+ public List<ApiInfo> list() {
|
|
|
return template.query(selectList, rowMapper);
|
|
|
}
|
|
|
|
|
|
- protected List<ApiInfo> listWithScript() {
|
|
|
- return template.query(selectListWithScript, rowMapper);
|
|
|
+ public List<ApiInfo> listWithScript() {
|
|
|
+ List<ApiInfo> infos = template.query(selectListWithScript, rowMapper);
|
|
|
+ if(infos != null){
|
|
|
+ for (ApiInfo info : infos) {
|
|
|
+ unwrap(info);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return infos;
|
|
|
}
|
|
|
|
|
|
- protected ApiInfo get(String id) {
|
|
|
- return template.queryForObject(selectOne, rowMapper, id);
|
|
|
+ public ApiInfo get(String id) {
|
|
|
+ ApiInfo info = template.queryForObject(selectOne, rowMapper, id);
|
|
|
+ unwrap(info);
|
|
|
+ return info;
|
|
|
}
|
|
|
|
|
|
- protected boolean exists(String method, String path) {
|
|
|
+ public boolean exists(String method, String path) {
|
|
|
return template.queryForObject(exists, Integer.class, method, path) > 0;
|
|
|
}
|
|
|
|
|
|
- protected boolean existsWithoutId(String method, String path, String id) {
|
|
|
+ public boolean existsWithoutId(String method, String path, String id) {
|
|
|
return template.queryForObject(existsWithoutId, Integer.class, method, path, id) > 0;
|
|
|
}
|
|
|
|
|
|
- protected boolean insert(ApiInfo info) {
|
|
|
+ public boolean insert(ApiInfo info) {
|
|
|
info.setId(UUID.randomUUID().toString().replace("-", ""));
|
|
|
+ wrap(info);
|
|
|
long time = System.currentTimeMillis();
|
|
|
return template.update(insert, info.getId(), info.getMethod(), info.getPath(), info.getScript(), info.getName(), info.getGroupName(), info.getParameter(), info.getOption(), time, time) > 0;
|
|
|
}
|
|
|
|
|
|
- protected boolean update(ApiInfo info) {
|
|
|
+ public boolean update(ApiInfo info) {
|
|
|
+ wrap(info);
|
|
|
return template.update(update, info.getMethod(), info.getPath(), info.getScript(), info.getName(), info.getGroupName(), info.getParameter(), info.getOption(), System.currentTimeMillis(), info.getId()) > 0;
|
|
|
}
|
|
|
}
|