Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[#23] Feat: WebClient 외부 API 호출 메소드 작성 #24

Merged
merged 4 commits into from
May 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ dependencies {
testImplementation 'org.springframework.boot:spring-boot-starter-test'
testImplementation 'org.springframework.security:spring-security-test'
testRuntimeOnly 'org.junit.platform:junit-platform-launcher'
implementation 'org.springframework.boot:spring-boot-starter-webflux'

// Swagger API
implementation("org.springdoc:springdoc-openapi-starter-webmvc-ui:2.0.2")
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.sajang.devracebackend.dto.user;

import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;

@Getter
@NoArgsConstructor
public class SolvedResponseDto {

private Integer solvedCount;

@Builder
public SolvedResponseDto(Integer solvedCount){
this.solvedCount = solvedCount;
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
package com.sajang.devracebackend.service;

import com.sajang.devracebackend.dto.user.SolvedResponseDto;

public interface UserService {
SolvedResponseDto checkUserSolvedCount(String bojId);
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,39 @@
package com.sajang.devracebackend.service.impl;

import com.sajang.devracebackend.dto.user.SolvedResponseDto;
import com.sajang.devracebackend.repository.UserRepository;
import com.sajang.devracebackend.response.exception.exception404.NoSuchBojIdException;
import com.sajang.devracebackend.service.UserService;
import jakarta.transaction.Transactional;
import lombok.RequiredArgsConstructor;
import org.springframework.http.HttpHeaders;
import org.springframework.http.MediaType;
import org.springframework.stereotype.Service;
import org.springframework.web.reactive.function.client.WebClient;

@Service
@RequiredArgsConstructor
public class UserServiceImpl implements UserService {

private final UserRepository userRepository;
}

@Transactional
@Override
public SolvedResponseDto checkUserSolvedCount(String bojId){

try {
WebClient webClient = WebClient.builder()
.baseUrl("https://solved.ac/api/v3")
.defaultHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE)
.build();

return webClient.get()
.uri("/user/show?handle=" + bojId)
.retrieve()
.bodyToMono(SolvedResponseDto.class)
.block();
}catch (Exception e){
throw new NoSuchBojIdException(bojId);
}
}
}
Loading