Skip to content

Commit 7d0c3e7

Browse files
committed
Fix a bug of updating spec api
1 parent 2fe7e52 commit 7d0c3e7

File tree

4 files changed

+15
-1
lines changed

4 files changed

+15
-1
lines changed

src/main/java/com/longcoding/moon/helpers/cluster/DBClusterRepository.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,12 @@ public boolean setApiInfo(ApiInfo apiInfo) {
4242
return true;
4343
}
4444

45+
@Override
46+
public boolean modifyApiInfo(ApiInfo apiInfo) {
47+
apiInfoRepository.saveAndFlush(apiInfo);
48+
return true;
49+
}
50+
4551
@Override
4652
public ApiInfo getApiInfo(int apiId) {
4753
Optional<ApiInfo> apiInfoOpt = apiInfoRepository.findById(apiId);

src/main/java/com/longcoding/moon/helpers/cluster/IClusterRepository.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ public interface IClusterRepository {
1010

1111
boolean setApiInfo(ApiInfo apiInfo);
1212

13+
boolean modifyApiInfo(ApiInfo apiInfo);
14+
1315
ApiInfo getApiInfo(int apiId);
1416

1517
List<ApiInfo> getAllApiInfo();

src/main/java/com/longcoding/moon/helpers/cluster/RedisClusterRepository.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,11 @@ public boolean setApiInfo(ApiInfo apiInfo) {
6161
return true;
6262
}
6363

64+
@Override
65+
public boolean modifyApiInfo(ApiInfo apiInfo) {
66+
return hset(Constant.REDIS_KEY_INTERNAL_API_INFO, String.valueOf(apiInfo.getApiId()), JsonUtil.fromJson(apiInfo)) == 0;
67+
}
68+
6469
@Override
6570
public ApiInfo getApiInfo(int apiId) {
6671
String apiInfoInString = hget(Constant.REDIS_KEY_INTERNAL_API_INFO, String.valueOf(apiId));

src/main/java/com/longcoding/moon/services/internal/ApiService.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,8 @@ public ApiInfo createOrModifyApi(SyncType syncType, EnrollApi enrollApi) {
4343
ApiInfo apiInfo = convertedEnrollApiToApiInfo(enrollApi);
4444
ApiSync apiSync = new ApiSync(syncType, apiInfo);
4545

46-
clusterRepository.setApiInfo(apiInfo);
46+
if (SyncType.CREATE == syncType) clusterRepository.setApiInfo(apiInfo);
47+
else if (SyncType.UPDATE == syncType) clusterRepository.modifyApiInfo(apiInfo);
4748
clusterSyncUtil.setexInfoToHealthyNode(Constant.REDIS_KEY_API_UPDATE, Constant.SECOND_OF_HOUR, JsonUtil.fromJson(apiSync));
4849

4950
return apiInfo;

0 commit comments

Comments
 (0)