Skip to content

Commit

Permalink
Merge pull request #162 from lemonssoju/develop-v2
Browse files Browse the repository at this point in the history
[develop-v2] main merge
  • Loading branch information
JoongHyun-Kim authored Jun 3, 2024
2 parents ab818ca + 25f5119 commit 9e9bc5a
Showing 1 changed file with 17 additions and 15 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package com.lesso.neverland.puzzle.application;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.lesso.neverland.album.domain.Album;
import com.lesso.neverland.album.repository.AlbumRepository;
import com.lesso.neverland.common.base.BaseException;
Expand Down Expand Up @@ -31,7 +34,6 @@
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpMethod;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.client.RestTemplate;
Expand Down Expand Up @@ -131,7 +133,7 @@ public BaseResponse<String> createPuzzle(Long groupIdx, MultipartFile image, Cre
Team group = groupRepository.findById(groupIdx).orElseThrow(() -> new BaseException(INVALID_GROUP_IDX));
User writer = userRepository.findById(userService.getUserIdxWithValidation()).orElseThrow(() -> new BaseException(INVALID_USER_IDX));

String imagePath = imageService.uploadImage("group", image);
String imagePath = imageService.uploadImage("puzzle", image);
LocalDate puzzleDate = convertToLocalDate(createPuzzleRequest.puzzleDate());

Puzzle newPuzzle = createPuzzle(createPuzzleRequest, group, writer, imagePath, puzzleDate);
Expand Down Expand Up @@ -163,7 +165,7 @@ private static LocalDate convertToLocalDate(String date) {
}

// puzzle entity 생성
private Puzzle createPuzzle(CreatePuzzleRequest createPuzzleRequest, Team group, User writer, String imagePath, LocalDate puzzleDate) {
private Puzzle createPuzzle(CreatePuzzleRequest createPuzzleRequest, Team group, User writer, String imagePath, LocalDate puzzleDate) throws JsonProcessingException {
Puzzle puzzle = Puzzle.builder()
.user(writer)
.team(group)
Expand All @@ -176,24 +178,24 @@ private Puzzle createPuzzle(CreatePuzzleRequest createPuzzleRequest, Team group,
return puzzle;
}

private PuzzleLocation convertAddressToCoordinates(String address) {
// String address값을 KakaoMap API를 활용해 x,y 좌표로 변환
private PuzzleLocation convertAddressToCoordinates(String address) throws JsonProcessingException {
RestTemplate restTemplate = new RestTemplate();

HttpHeaders headers = new HttpHeaders();
headers.set("Authorization", "KakaoAK " + API_KEY);
HttpEntity<String> entity = new HttpEntity<>("parameters", headers);
HttpEntity<String> entity = new HttpEntity<>(headers);

String url = API_URL + address;
ResponseEntity<KakaoApiResponse> response = restTemplate.exchange(url, HttpMethod.GET, entity, KakaoApiResponse.class);
KakaoApiResponse responseBody = response.getBody();

PuzzleLocation puzzleLocation = null;
if (responseBody != null && responseBody.documents().length > 0) {
String x = responseBody.documents()[0].x();
String y = responseBody.documents()[0].y();
puzzleLocation = new PuzzleLocation(address, x, y);
}
return puzzleLocation;
String responseBody = restTemplate.exchange(url, HttpMethod.GET, entity, String.class).getBody();

ObjectMapper objectMapper = new ObjectMapper();
JsonNode jsonNode = objectMapper.readTree(responseBody);
JsonNode firstDocument = jsonNode.path("documents").get(0);
String x = firstDocument.path("x").asText();
String y = firstDocument.path("y").asText();

return new PuzzleLocation(address, x, y);
}

// [작성자] 퍼즐 수정
Expand Down

0 comments on commit 9e9bc5a

Please sign in to comment.