Skip to content

Commit

Permalink
fixed error show api use case in seller api server module
Browse files Browse the repository at this point in the history
  • Loading branch information
kuangxiang20240501 committed Nov 15, 2024
1 parent 39a6bc2 commit cb5d021
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
import com.fasterxml.jackson.core.type.TypeReference;
import java.time.ZonedDateTime;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.CollectionUtils;
Expand Down Expand Up @@ -38,30 +40,31 @@ public HttpResponse<Void> onEvent(String envId, String userId, ClientEvent event
if (CollectionUtils.isEmpty(serverAPIDtos)) {
return HttpResponse.ok(null);
}
serverAPIDtos.forEach(
serverAPIDto -> {
EnvironmentClientEntity environmentClientEntity =
environmentClientRepository
.findOneByEnvIdAndClientKeyAndKind(
envId,
serverAPIDto.getServerKey(),
ClientReportTypeEnum.CLIENT_SERVER_API.name())
.orElseGet(
() -> {
EnvironmentClientEntity entity = new EnvironmentClientEntity();
entity.setEnvId(envId);
entity.setKind(ClientReportTypeEnum.CLIENT_SERVER_API.name());
entity.setClientKey(serverAPIDto.getServerKey());
entity.setCreatedAt(ZonedDateTime.now());
entity.setCreatedBy(userId);
return entity;
});
environmentClientEntity.setUpdatedAt(ZonedDateTime.now());
environmentClientEntity.setUpdatedBy(userId);
environmentClientEntity.setPayload(serverAPIDto);
environmentClientRepository.save(environmentClientEntity);
});

Map<String, List<ServerAPIDto>> serverKeyMap =
serverAPIDtos.stream().collect(Collectors.groupingBy(ServerAPIDto::getServerKey));
serverKeyMap
.entrySet()
.forEach(
entry -> {
EnvironmentClientEntity environmentClientEntity =
environmentClientRepository
.findOneByEnvIdAndClientKeyAndKind(
envId, entry.getKey(), ClientReportTypeEnum.CLIENT_SERVER_API.name())
.orElseGet(
() -> {
EnvironmentClientEntity entity = new EnvironmentClientEntity();
entity.setEnvId(envId);
entity.setKind(ClientReportTypeEnum.CLIENT_SERVER_API.name());
entity.setClientKey(entry.getKey());
entity.setCreatedAt(ZonedDateTime.now());
entity.setCreatedBy(userId);
return entity;
});
environmentClientEntity.setUpdatedAt(ZonedDateTime.now());
environmentClientEntity.setUpdatedBy(userId);
environmentClientEntity.setPayload(entry.getValue());
environmentClientRepository.save(environmentClientEntity);
});
return HttpResponse.ok(null);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,10 @@ default void calculateDataPlane(
return;
}
String json = JsonToolkit.toJson(environmentClientEntity.getPayload());
ServerAPIDto serverAPIDto =
JsonToolkit.fromJson(json, new TypeReference<ServerAPIDto>() {});
List<String> mapperKeys = List.of(serverAPIDto.getMapperKey());
List<ServerAPIDto> serverAPIDtos =
JsonToolkit.fromJson(json, new TypeReference<List<ServerAPIDto>>() {});
List<String> mapperKeys =
serverAPIDtos.stream().map(ServerAPIDto::getMapperKey).toList();
List<UnifiedAssetDto> list =
getUnifiedAssetService().findByAllKeysIn(mapperKeys, true);
list.forEach(this::hiddenMappers);
Expand Down

0 comments on commit cb5d021

Please sign in to comment.