Skip to content

Commit

Permalink
[#4 webFlux] fix webFlux Cube logic
Browse files Browse the repository at this point in the history
  • Loading branch information
leemj123 committed Jan 14, 2024
1 parent 661c99f commit 1fb938d
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 19 deletions.
2 changes: 1 addition & 1 deletion src/main/java/com/example/demo/config/WebClientConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public class WebClientConfig {
@Bean
public WebClient APIClient(WebClient.Builder builder) {
return builder
.baseUrl("https://heneinbackapi.shop/") // 기본 URL 설정
.baseUrl("https://heneinbackapi.shop") // 기본 URL 설정
.defaultHeader(HttpHeaders.CONTENT_TYPE, "application/json; charset=UTF-8") // 기본 헤더 설정
.build();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import javax.servlet.http.HttpServletRequest;
import java.io.IOException;
import java.util.List;
import java.util.Set;


@RestController
Expand Down Expand Up @@ -81,9 +82,9 @@ public Mono<List<UserCharacterResponse>> updateMultiCharacter(@RequestBody CharR

@Operation(summary = "유저가 가지고있는 캐릭터 큐브 내역으로 불러오기" )
@PostMapping("/character/auth")
public Mono<Void> requestNexon(@RequestBody UserMapleApi userMapleApi,HttpServletRequest request){
userService.requestToAPIServer(request,userMapleApi);
return Mono.empty();
public Mono<String> requestNexon(@RequestBody UserMapleApi userMapleApi, HttpServletRequest request){
return userService.requestToAPIServer(request,userMapleApi);

}


Expand Down
30 changes: 15 additions & 15 deletions src/main/java/com/example/demo/service/UserService.java
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ public List<UserCharacterResponse> getAllUserCharacterInfo(HttpServletRequest re

@Transactional
//인증 받아오기
public Mono<Void> requestToAPIServer(HttpServletRequest request,UserMapleApi userMapleApi){
public Mono<String> requestToAPIServer(HttpServletRequest request,UserMapleApi userMapleApi){
//날짜가 오늘일시 에러.
if (userMapleApi.getRecentDay().equals(LocalDate.now())) {
throw new BadRequestException("Today's date cannot be requested", ErrorCode.BAD_REQUEST);
Expand All @@ -198,32 +198,32 @@ else if (ChronoUnit.DAYS.between(userMapleApi.getRecentDay(),userMapleApi.getPas
UserEntity userEntity = userRepository.findByUserEmail(userEmail).orElseThrow(()->{throw new NotFoundException(ErrorCode.NOT_FOUND_EXCEPTION.getMessage(), ErrorCode.NOT_FOUND_EXCEPTION);});

userEntity.UpdateApiKey(userMapleApi.getUserApi());
String api = "cube?key="+apiKey;
String api = "/cube?key="+apiKey;

this.APIClient.post()
.uri(api)
return this.APIClient.post()
.uri(api)
.body(BodyInserters.fromValue(userMapleApi))
.retrieve()
.bodyToMono(new ParameterizedTypeReference<List<String>>() {})
.bodyToMono(new ParameterizedTypeReference<Set<String>>() {})
.flatMap(result -> {

List<UserCharEntity> userCharEntityList = userCharRepository.findAllByUserEntity(userEntity);

for ( UserCharEntity u : userCharEntityList) {
for (String r : result) {
for ( String r : result) {
for (UserCharEntity u : userCharEntityList) {
if (r.equals(u.getCharName())) {
continue;
result.remove(r);
break;
}
userCharEntityList.add(new UserCharEntity(userEntity, r));
}
}

if (!userCharEntityList.isEmpty()) {
List<UserCharEntity> newCharEntityList = new ArrayList<>();
for (String r : result) {
newCharEntityList.add(new UserCharEntity(userEntity, r));
}
if (!newCharEntityList.isEmpty()) {
userCharRepository.saveAll(userCharEntityList);
}
return Mono.empty();
return Mono.just("200ok");
});
return Mono.empty();
}

//단일 조희
Expand Down

0 comments on commit 1fb938d

Please sign in to comment.