Skip to content
Open
Changes from 1 commit
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
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,13 @@
import com.team.neorangloa.global.result.ResultCode;
import com.team.neorangloa.global.result.ResultResponse;
import lombok.RequiredArgsConstructor;
import org.springframework.http.ResponseEntity;
import org.springframework.http.*;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.client.RestTemplate;

import javax.validation.Valid;
import java.net.URI;
import java.net.URISyntaxException;

@RestController
@RequiredArgsConstructor
Expand Down Expand Up @@ -57,4 +60,25 @@ public ResponseEntity<ResultResponse> updatePassword(@LoginUser User loginUser,
userService.updatePassword(logInUserId, updatePasswordRequest);
return ResponseEntity.ok(ResultResponse.of(ResultCode.UPDATE_USER_PASSWORD_SUCCESS));
}
@GetMapping("/charactersInfo/{characterName}")
public ResponseEntity<String> getCharactersInfo(@RequestHeader("API-Key") String apiKey,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

헤더에 API-key 가 있는데 이거는 어떤 역할을 하는거야?

@PathVariable String characterName) {
RestTemplate restTemplate = new RestTemplate();
String apiUrl = "https://developer-lostark.game.onstove.com/characters/" + characterName + "/siblings";

HttpHeaders headers = new HttpHeaders();
headers.set(HttpHeaders.ACCEPT, MediaType.APPLICATION_JSON_VALUE);
headers.set(HttpHeaders.AUTHORIZATION, apiKey);

HttpEntity<?> httpEntity = new HttpEntity<>(headers);

ResponseEntity<String> response = restTemplate.exchange(apiUrl, HttpMethod.GET, httpEntity, String.class);
System.out.println(response);
System.out.println(response.getStatusCode());
System.out.println(response.getBody());

// 클라이언트에 반환할 때는 JSON 형식으로 변환하여 반환
// response.getBody()는 API에서 받은 데이터를 문자열로 반환
return ResponseEntity.ok(response.getBody());
}
}