Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import org.springframework.stereotype.Repository;
import site.campingon.campingon.camp.entity.CampAddr;

import java.util.List;
import java.util.Optional;

@Repository
Expand Down Expand Up @@ -37,4 +38,7 @@ void updateWithPoint(@Param("campId") Long campId,
@Param("streetAddr") String streetAddr,
@Param("detailedAddr") String detailedAddr,
@Param("location") String location);

@Query("SELECT c.id FROM Camp c JOIN c.campAddr ad WHERE ad.city LIKE :city")
List<Long> findCampIdsByCity(@Param("city") String city);
}
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,10 @@ public enum ErrorCode {

GO_CAMPING_BAD_REQUEST(HttpStatus.BAD_REQUEST, "GOCAMPING-001", "잘못된 고캠핑 데이터 요청입니다."),
GO_CAMPING_IMAGE_BAD_REQUEST(HttpStatus.BAD_REQUEST, "GOCAMPING-002", "DB에 저장된 캠프가 없거나 잘못된 데이터 요청입니다."),
GO_CAMPING_DATA_NO_CONTENT(HttpStatus.NO_CONTENT,"GOCAMPING-003","요청하신 응답은 데이터가 없습니다.");
GO_CAMPING_DATA_NO_CONTENT(HttpStatus.NO_CONTENT,"GOCAMPING-003","요청하신 응답은 데이터가 없습니다."),
GO_CAMPING_SERVER_ERROR(HttpStatus.INTERNAL_SERVER_ERROR,"GOCAMPING-004","고캠핑서비스에서 서버오류가발생했습니다."),
GO_CAMPING_DATA_MAPPING_ERROR(HttpStatus.BAD_REQUEST,"GOCAMPING-005","데이터의 Json 매핑이 잘못됐습니다."),
GO_CAMPING_NETWORK_ERROR(HttpStatus.BAD_REQUEST, "GOCAMPING-006", "고캠핑 네트워크 오류입니다.");


private final HttpStatus httpStatus;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package site.campingon.campingon.common.public_data.controller;

import com.fasterxml.jackson.databind.exc.InvalidFormatException;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.*;
Expand Down Expand Up @@ -49,9 +50,11 @@ public ResponseEntity<List<GoCampingParsedResponseDto>> createCampByGoCampingBas
= goCampingService.upsertCampData(goCampingDataDto);

return ResponseEntity.status(HttpStatus.OK).body(goCampingParsedResponseDtos);
} catch (Exception e) { //
} catch (InvalidFormatException e) { //
log.error("고캠핑데이터 저장 실패, 고캠핑 API 파라미터나 서비스키를 다시 확인해주세요");
throw new GlobalException(GO_CAMPING_BAD_REQUEST);
} catch (URISyntaxException e) {
throw new RuntimeException(e);
}
}

Expand All @@ -77,6 +80,21 @@ public ResponseEntity<List<List<GoCampingImageParsedResponseDto>>> createCampIma
return ResponseEntity.status(HttpStatus.OK).body(goCampingParsedResponseDtos);
}

@PostMapping("/imageList/city")
public ResponseEntity<List<List<GoCampingImageParsedResponseDto>>> createCampImageByCityKeyword(
@RequestParam("imageCnt") long imageCnt,
@RequestParam("city") String city
) throws URISyntaxException {
List<Long> campIdList=goCampingService.findCampIdByCity(city);

List<GoCampingImageDto> goCampingImageDtos = goCampingService.fetchCampImageData(campIdList, imageCnt);

List<List<GoCampingImageParsedResponseDto>> campImageData
= goCampingService.upsertCampImageData(goCampingImageDtos);

return ResponseEntity.status(HttpStatus.OK).body(campImageData);
}

// //위치기반정보 목록 조회
// @GetMapping("/locationBasedList")
// public ResponseEntity<List<GoCampingParsedResponseDto>> GetGoCampingLocationBasedList(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package site.campingon.campingon.common.public_data.schedule;

import com.fasterxml.jackson.databind.exc.InvalidFormatException;
import lombok.extern.slf4j.Slf4j;
import lombok.RequiredArgsConstructor;
import org.springframework.scheduling.annotation.Scheduled;
Expand Down Expand Up @@ -92,6 +93,8 @@ public void scheduleCampCreation() {
}
} catch (URISyntaxException e) {
log.error("캠프 데이터 생성 실패: " + e.getMessage());
} catch (InvalidFormatException e) {
throw new RuntimeException(e);
}
}

Expand Down Expand Up @@ -144,6 +147,8 @@ public void scheduleCampUpdate() {
}
} catch (URISyntaxException e) {
log.error("캠프 데이터 업데이트 실패: " + e.getMessage());
} catch (InvalidFormatException e) {
throw new RuntimeException(e);
}

}
Expand Down Expand Up @@ -184,6 +189,8 @@ public void scheduleCampDelete() {
}
} catch (URISyntaxException e) {
log.error("캠프 데이터 삭제 실패: " + e.getMessage());
} catch (InvalidFormatException e) {
throw new RuntimeException(e);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
package site.campingon.campingon.common.public_data.service;

import com.fasterxml.jackson.databind.JsonMappingException;
import com.fasterxml.jackson.databind.exc.InvalidFormatException;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.client.HttpClientErrorException;
import org.springframework.web.client.HttpServerErrorException;
import org.springframework.web.client.RestClientException;
import org.springframework.web.client.RestTemplate;
import site.campingon.campingon.camp.entity.*;
import site.campingon.campingon.camp.repository.*;
Expand All @@ -24,7 +29,7 @@
import java.util.Optional;

import static site.campingon.campingon.camp.entity.Induty.*;
import static site.campingon.campingon.common.exception.ErrorCode.CAMP_NOT_FOUND_BY_ID;
import static site.campingon.campingon.common.exception.ErrorCode.*;

@Service
@RequiredArgsConstructor
Expand Down Expand Up @@ -181,13 +186,24 @@ public int deleteCamp(GoCampingDataDto goCampingDataDto) {
public GoCampingDataDto fetchCampData(
GoCampingPath goCampingPath,
String... params
) throws URISyntaxException {
) throws InvalidFormatException, URISyntaxException {
URI uri = goCampingProviderService.createUri(goCampingPath, params);

try {
return restTemplate.getForObject(uri, GoCampingDataDto.class); //API 호출
} catch (Exception e) {
return new GoCampingDataDto(); //json 데이터가 비어있거나, 올바르지 않다면 빈객체 리턴
return restTemplate.getForObject(uri, GoCampingDataDto.class); // API 호출
} catch (HttpClientErrorException e) {
log.error("HTTP 요청 오류: {}", e.getMessage(), e);
throw new GlobalException(GO_CAMPING_BAD_REQUEST); // 적절한 사용자 정의 예외 처리
} catch (HttpServerErrorException e) {
log.error("서버 오류: {}", e.getMessage(), e);
throw new GlobalException(GO_CAMPING_SERVER_ERROR); // 서버 오류에 대한 처리
} catch (RestClientException e) {
if (e.getCause() instanceof JsonMappingException) {
log.error("JSON 매핑 오류: {}", e.getMessage(), e);
throw new GlobalException(GO_CAMPING_DATA_MAPPING_ERROR); // 데이터 매핑 오류
}
log.error("RestTemplate 오류: {}", e.getMessage(), e);
throw new GlobalException(GO_CAMPING_NETWORK_ERROR); // 네트워크 오류
}
}

Expand Down Expand Up @@ -273,4 +289,8 @@ private List<GoCampingParsedResponseDto> parseGoCampingData(GoCampingDataDto goC
List<GoCampingDataDto.Item> items = goCampingDataDto.getResponse().getBody().getItems().getItem();
return goCampingMapper.toGoCampingParsedResponseDtoList(items);
}

public List<Long> findCampIdByCity(String city) {
return campAddrRepository.findCampIdsByCity(city);
}
}
Loading