diff --git a/EnjoyTripBackend/src/main/java/com/example/EnjoyTripBackend/controller/AirplaneController.java b/EnjoyTripBackend/src/main/java/com/example/EnjoyTripBackend/controller/AirplaneController.java index 34a86f8..736da37 100644 --- a/EnjoyTripBackend/src/main/java/com/example/EnjoyTripBackend/controller/AirplaneController.java +++ b/EnjoyTripBackend/src/main/java/com/example/EnjoyTripBackend/controller/AirplaneController.java @@ -5,7 +5,7 @@ import com.example.EnjoyTripBackend.dto.airplane.AirplaneRequestDto; import com.example.EnjoyTripBackend.dto.airplane.AirplaneResponseDto; import com.example.EnjoyTripBackend.service.AirplaneService; -import com.example.EnjoyTripBackend.util.LimitedSizePagination; +import com.example.EnjoyTripBackend.util.argumentresolver.LimitedSizePagination; import lombok.RequiredArgsConstructor; import org.springframework.data.domain.Pageable; import org.springframework.data.web.PageableDefault; diff --git a/EnjoyTripBackend/src/main/java/com/example/EnjoyTripBackend/controller/CampingController.java b/EnjoyTripBackend/src/main/java/com/example/EnjoyTripBackend/controller/CampingController.java new file mode 100644 index 0000000..ca33ba2 --- /dev/null +++ b/EnjoyTripBackend/src/main/java/com/example/EnjoyTripBackend/controller/CampingController.java @@ -0,0 +1,29 @@ +package com.example.EnjoyTripBackend.controller; + +import com.example.EnjoyTripBackend.dto.ResponseResult; +import com.example.EnjoyTripBackend.dto.camping.CampingResponseDto; +import com.example.EnjoyTripBackend.service.CampingService; +import com.example.EnjoyTripBackend.util.argumentresolver.LimitedSizePagination; +import lombok.RequiredArgsConstructor; +import org.springframework.data.domain.Pageable; +import org.springframework.data.web.PageableDefault; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +import java.util.List; + +@RestController +@RequestMapping("/api") +@RequiredArgsConstructor +public class CampingController { + + private final CampingService campingService; + + @GetMapping("/camping") + @LimitedSizePagination(maxSize = 20) + public ResponseEntity>> findAll(@PageableDefault(size = 6) Pageable pageable) { + return ResponseEntity.ok().body(campingService.findAll(pageable)); + } +} \ No newline at end of file diff --git a/EnjoyTripBackend/src/main/java/com/example/EnjoyTripBackend/controller/GolfController.java b/EnjoyTripBackend/src/main/java/com/example/EnjoyTripBackend/controller/GolfController.java index 74b3d81..2f4e534 100644 --- a/EnjoyTripBackend/src/main/java/com/example/EnjoyTripBackend/controller/GolfController.java +++ b/EnjoyTripBackend/src/main/java/com/example/EnjoyTripBackend/controller/GolfController.java @@ -5,7 +5,7 @@ import com.example.EnjoyTripBackend.dto.golf.GolfRequestDto; import com.example.EnjoyTripBackend.dto.golf.GolfResponseDto; import com.example.EnjoyTripBackend.service.GolfService; -import com.example.EnjoyTripBackend.util.LimitedSizePagination; +import com.example.EnjoyTripBackend.util.argumentresolver.LimitedSizePagination; import lombok.RequiredArgsConstructor; import org.springframework.data.domain.Pageable; import org.springframework.data.web.PageableDefault; @@ -32,9 +32,9 @@ public ResponseEntity> golfDetail(@Path return ResponseEntity.ok().body(golfService.findById(id)); } - @GetMapping("/golf/search") + @PostMapping("/golf/search") @LimitedSizePagination(maxSize = 20) - public ResponseEntity>> golfSearchList(@PageableDefault(size = 20) Pageable pageable, @RequestBody GolfRequestDto golfRequestDto){ + public ResponseEntity>> golfSearchList(@PageableDefault(size = 6) Pageable pageable, @RequestBody GolfRequestDto golfRequestDto){ return ResponseEntity.ok().body(golfService.golfSearchList(pageable, golfRequestDto)); } diff --git a/EnjoyTripBackend/src/main/java/com/example/EnjoyTripBackend/controller/MemberController.java b/EnjoyTripBackend/src/main/java/com/example/EnjoyTripBackend/controller/MemberController.java index 167c22f..1dba751 100644 --- a/EnjoyTripBackend/src/main/java/com/example/EnjoyTripBackend/controller/MemberController.java +++ b/EnjoyTripBackend/src/main/java/com/example/EnjoyTripBackend/controller/MemberController.java @@ -3,7 +3,7 @@ import com.example.EnjoyTripBackend.dto.member.LoginRequestDto; import com.example.EnjoyTripBackend.dto.member.SignUpRequestDto; import com.example.EnjoyTripBackend.service.MemberService; -import com.example.EnjoyTripBackend.util.SessionConst; +import com.example.EnjoyTripBackend.util.argumentresolver.SessionConst; import jakarta.servlet.http.HttpServletRequest; import jakarta.servlet.http.HttpSession; import jakarta.validation.Valid; diff --git a/EnjoyTripBackend/src/main/java/com/example/EnjoyTripBackend/controller/PaymentController.java b/EnjoyTripBackend/src/main/java/com/example/EnjoyTripBackend/controller/PaymentController.java index b48ba0a..0470788 100644 --- a/EnjoyTripBackend/src/main/java/com/example/EnjoyTripBackend/controller/PaymentController.java +++ b/EnjoyTripBackend/src/main/java/com/example/EnjoyTripBackend/controller/PaymentController.java @@ -1,7 +1,7 @@ package com.example.EnjoyTripBackend.controller; import com.example.EnjoyTripBackend.service.PaymentService; -import com.example.EnjoyTripBackend.util.SessionUser; +import com.example.EnjoyTripBackend.util.argumentresolver.SessionUser; import lombok.RequiredArgsConstructor; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.GetMapping; diff --git a/EnjoyTripBackend/src/main/java/com/example/EnjoyTripBackend/controller/PlaceController.java b/EnjoyTripBackend/src/main/java/com/example/EnjoyTripBackend/controller/PlaceController.java index 8b67411..bff6a91 100644 --- a/EnjoyTripBackend/src/main/java/com/example/EnjoyTripBackend/controller/PlaceController.java +++ b/EnjoyTripBackend/src/main/java/com/example/EnjoyTripBackend/controller/PlaceController.java @@ -7,7 +7,7 @@ import com.example.EnjoyTripBackend.dto.place.PlaceSearchwordRequestDto; import com.example.EnjoyTripBackend.service.PlaceService; import com.example.EnjoyTripBackend.service.S3Service; -import com.example.EnjoyTripBackend.util.SessionUser; +import com.example.EnjoyTripBackend.util.argumentresolver.SessionUser; import lombok.RequiredArgsConstructor; import org.springframework.data.domain.Pageable; import org.springframework.data.web.PageableDefault; diff --git a/EnjoyTripBackend/src/main/java/com/example/EnjoyTripBackend/domain/Camping.java b/EnjoyTripBackend/src/main/java/com/example/EnjoyTripBackend/domain/Camping.java new file mode 100644 index 0000000..3527c90 --- /dev/null +++ b/EnjoyTripBackend/src/main/java/com/example/EnjoyTripBackend/domain/Camping.java @@ -0,0 +1,25 @@ +package com.example.EnjoyTripBackend.domain; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Getter; +import lombok.NoArgsConstructor; + +@Getter +@Builder +@NoArgsConstructor +@AllArgsConstructor +public class Camping extends BaseTimeDomain{ + + private Long id; + private String name; + private String shortIntro; + private String Intro; + private String zipcode; + private String address; + private double latitude; + private double longitude; + private String imageUrl; + private String homepage; + private String tel; +} \ No newline at end of file diff --git a/EnjoyTripBackend/src/main/java/com/example/EnjoyTripBackend/dto/camping/CampItemDto.java b/EnjoyTripBackend/src/main/java/com/example/EnjoyTripBackend/dto/camping/CampItemDto.java new file mode 100644 index 0000000..ecca392 --- /dev/null +++ b/EnjoyTripBackend/src/main/java/com/example/EnjoyTripBackend/dto/camping/CampItemDto.java @@ -0,0 +1,22 @@ +package com.example.EnjoyTripBackend.dto.camping; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import lombok.*; + +@Getter +@Builder +@NoArgsConstructor +@AllArgsConstructor +@JsonIgnoreProperties(ignoreUnknown = true) +public class CampItemDto { + private String facltNm; + private String intro; + private String tel; + private String zipcode; + private double mapY; + private double mapX; + private String lineIntro; + private String firstImageUrl; + private String addr1; + private String homepage; +} \ No newline at end of file diff --git a/EnjoyTripBackend/src/main/java/com/example/EnjoyTripBackend/dto/camping/CampingResponse.java b/EnjoyTripBackend/src/main/java/com/example/EnjoyTripBackend/dto/camping/CampingResponse.java new file mode 100644 index 0000000..1ca58c5 --- /dev/null +++ b/EnjoyTripBackend/src/main/java/com/example/EnjoyTripBackend/dto/camping/CampingResponse.java @@ -0,0 +1,37 @@ +package com.example.EnjoyTripBackend.dto.camping; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import lombok.*; +import java.util.List; + +@Getter +@NoArgsConstructor +@AllArgsConstructor +@JsonIgnoreProperties(ignoreUnknown = true) +public class CampingResponse { + private Response response; + + @Getter + @NoArgsConstructor + @AllArgsConstructor + @JsonIgnoreProperties(ignoreUnknown = true) + public static class Response { + private BodyDto body; + + @Getter + @NoArgsConstructor + @AllArgsConstructor + @JsonIgnoreProperties(ignoreUnknown = true) + public static class BodyDto { + private ItemsDto items; + } + + @Getter + @NoArgsConstructor + @AllArgsConstructor + @JsonIgnoreProperties(ignoreUnknown = true) + public static class ItemsDto { + private List item; + } + } +} \ No newline at end of file diff --git a/EnjoyTripBackend/src/main/java/com/example/EnjoyTripBackend/dto/camping/CampingResponseDto.java b/EnjoyTripBackend/src/main/java/com/example/EnjoyTripBackend/dto/camping/CampingResponseDto.java new file mode 100644 index 0000000..4989f78 --- /dev/null +++ b/EnjoyTripBackend/src/main/java/com/example/EnjoyTripBackend/dto/camping/CampingResponseDto.java @@ -0,0 +1,21 @@ +package com.example.EnjoyTripBackend.dto.camping; + +import lombok.AllArgsConstructor; +import lombok.Getter; +import lombok.NoArgsConstructor; + +@Getter +@NoArgsConstructor +@AllArgsConstructor +public class CampingResponseDto { + + private String name; + private String Intro; + private String zipcode; + private String address; + private double latitude; + private double longitude; + private String imageUrl; + private String homepage; + +} \ No newline at end of file diff --git a/EnjoyTripBackend/src/main/java/com/example/EnjoyTripBackend/dto/golf/GolfResponseDto.java b/EnjoyTripBackend/src/main/java/com/example/EnjoyTripBackend/dto/golf/GolfResponseDto.java index 762866b..c4796ce 100644 --- a/EnjoyTripBackend/src/main/java/com/example/EnjoyTripBackend/dto/golf/GolfResponseDto.java +++ b/EnjoyTripBackend/src/main/java/com/example/EnjoyTripBackend/dto/golf/GolfResponseDto.java @@ -11,13 +11,13 @@ @AllArgsConstructor public class GolfResponseDto { - private Long golf_id; - private String golfclub_name; + private Long golfId; + private String golfclubName; private String location; private String date; - private String golf_imageUrl; - private String green_fee_week; - private String green_fee_weekend; + private String golfImageUrl; + private String greenFeeWeek; + private String greenFeeWeekend; private double latitude; private double longitude; } \ No newline at end of file diff --git a/EnjoyTripBackend/src/main/java/com/example/EnjoyTripBackend/exception/ErrorCode.java b/EnjoyTripBackend/src/main/java/com/example/EnjoyTripBackend/exception/ErrorCode.java index 833780b..45268f4 100644 --- a/EnjoyTripBackend/src/main/java/com/example/EnjoyTripBackend/exception/ErrorCode.java +++ b/EnjoyTripBackend/src/main/java/com/example/EnjoyTripBackend/exception/ErrorCode.java @@ -22,7 +22,8 @@ public enum ErrorCode { FAIL_COMMUNICATE_TOSSPAYMENT_API(HttpStatus.INTERNAL_SERVER_ERROR,"토스페이먼트 API와의 통신에 실패하였습니다."), FAIL_COMMUNICATE_EXTERNAL_API(HttpStatus.INTERNAL_SERVER_ERROR,"외부 API와의 통신에 실패하였습니다."), Limited_Size_Pagination(HttpStatus.INTERNAL_SERVER_ERROR,"최대 페이징 사이지를 초과하였습니다."), - FAIL_INSERT_AIRPLANE_DATA(HttpStatus.INTERNAL_SERVER_ERROR, "데이터베이스에 항공권 데이터 저장에 실패하였습니다"); + FAIL_INSERT_AIRPLANE_DATA(HttpStatus.INTERNAL_SERVER_ERROR, "데이터베이스에 항공권 데이터 저장에 실패하였습니다"), + FAIL_INSERT_CAMPING_DATA(HttpStatus.INTERNAL_SERVER_ERROR, "데이터베이스에 캠핑 데이터 저장에 실패하였습니다"); private final HttpStatus httpstatus; private final String message; diff --git a/EnjoyTripBackend/src/main/java/com/example/EnjoyTripBackend/filter/LoginCheckFilter.java b/EnjoyTripBackend/src/main/java/com/example/EnjoyTripBackend/filter/LoginCheckFilter.java index 0ad0a3f..586765a 100644 --- a/EnjoyTripBackend/src/main/java/com/example/EnjoyTripBackend/filter/LoginCheckFilter.java +++ b/EnjoyTripBackend/src/main/java/com/example/EnjoyTripBackend/filter/LoginCheckFilter.java @@ -2,7 +2,7 @@ import com.example.EnjoyTripBackend.exception.EnjoyTripException; import com.example.EnjoyTripBackend.exception.ErrorCode; -import com.example.EnjoyTripBackend.util.SessionConst; +import com.example.EnjoyTripBackend.util.argumentresolver.SessionConst; import com.fasterxml.jackson.databind.ObjectMapper; import jakarta.servlet.*; import jakarta.servlet.http.HttpServletRequest; diff --git a/EnjoyTripBackend/src/main/java/com/example/EnjoyTripBackend/filter/WebConfig.java b/EnjoyTripBackend/src/main/java/com/example/EnjoyTripBackend/filter/WebConfig.java index 91cc61e..48cb647 100644 --- a/EnjoyTripBackend/src/main/java/com/example/EnjoyTripBackend/filter/WebConfig.java +++ b/EnjoyTripBackend/src/main/java/com/example/EnjoyTripBackend/filter/WebConfig.java @@ -1,7 +1,7 @@ package com.example.EnjoyTripBackend.filter; -import com.example.EnjoyTripBackend.util.LimitedPageableArgumentResolver; -import com.example.EnjoyTripBackend.util.SessionUserArgumentResolver; +import com.example.EnjoyTripBackend.util.argumentresolver.LimitedPageableArgumentResolver; +import com.example.EnjoyTripBackend.util.argumentresolver.SessionUserArgumentResolver; import com.fasterxml.jackson.databind.ObjectMapper; import jakarta.servlet.Filter; import lombok.extern.slf4j.Slf4j; diff --git a/EnjoyTripBackend/src/main/java/com/example/EnjoyTripBackend/repository/CampingRepository.java b/EnjoyTripBackend/src/main/java/com/example/EnjoyTripBackend/repository/CampingRepository.java new file mode 100644 index 0000000..b4c55a2 --- /dev/null +++ b/EnjoyTripBackend/src/main/java/com/example/EnjoyTripBackend/repository/CampingRepository.java @@ -0,0 +1,15 @@ +package com.example.EnjoyTripBackend.repository; + +import com.example.EnjoyTripBackend.domain.Camping; +import com.example.EnjoyTripBackend.dto.PageRequestList; +import com.example.EnjoyTripBackend.dto.camping.CampingResponseDto; +import org.apache.ibatis.annotations.Mapper; + +import java.util.List; + +@Mapper +public interface CampingRepository { + Long save(Camping camping); + Long findTotalCount(); + List findAll(PageRequestList requestList); +} \ No newline at end of file diff --git a/EnjoyTripBackend/src/main/java/com/example/EnjoyTripBackend/service/CampingService.java b/EnjoyTripBackend/src/main/java/com/example/EnjoyTripBackend/service/CampingService.java new file mode 100644 index 0000000..be0f5ff --- /dev/null +++ b/EnjoyTripBackend/src/main/java/com/example/EnjoyTripBackend/service/CampingService.java @@ -0,0 +1,36 @@ +package com.example.EnjoyTripBackend.service; + +import com.example.EnjoyTripBackend.domain.Camping; +import com.example.EnjoyTripBackend.dto.PageRequestList; +import com.example.EnjoyTripBackend.dto.ResponseResult; +import com.example.EnjoyTripBackend.dto.camping.CampingResponseDto; +import com.example.EnjoyTripBackend.repository.CampingRepository; +import lombok.RequiredArgsConstructor; +import org.springframework.data.domain.Pageable; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import java.util.List; + +@Service +@RequiredArgsConstructor +@Transactional(readOnly = true) +public class CampingService { + + private final CampingRepository campingRepository; + + @Transactional + public Long save(Camping camping) { + return campingRepository.save(camping); + } + + public ResponseResult> findAll(Pageable pageable) { + PageRequestList requestList = PageRequestList.builder() + .pageable(pageable) + .build(); + + long totalCount = campingRepository.findTotalCount(); + int totalPages = (int) Math.ceil((double) totalCount / pageable.getPageSize()); + return ResponseResult.of("캠핑 정보 게시글 목록입니다.", campingRepository.findAll(requestList),totalPages); + } +} \ No newline at end of file diff --git a/EnjoyTripBackend/src/main/java/com/example/EnjoyTripBackend/util/DataUpdater.java b/EnjoyTripBackend/src/main/java/com/example/EnjoyTripBackend/util/DataUpdater.java index e526b88..e243c8c 100644 --- a/EnjoyTripBackend/src/main/java/com/example/EnjoyTripBackend/util/DataUpdater.java +++ b/EnjoyTripBackend/src/main/java/com/example/EnjoyTripBackend/util/DataUpdater.java @@ -1,5 +1,6 @@ package com.example.EnjoyTripBackend.util; +import com.example.EnjoyTripBackend.util.collector.AirplaneInfoCollector; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.CommandLineRunner; import org.springframework.stereotype.Component; diff --git a/EnjoyTripBackend/src/main/java/com/example/EnjoyTripBackend/util/LimitedPageableArgumentResolver.java b/EnjoyTripBackend/src/main/java/com/example/EnjoyTripBackend/util/argumentresolver/LimitedPageableArgumentResolver.java similarity index 95% rename from EnjoyTripBackend/src/main/java/com/example/EnjoyTripBackend/util/LimitedPageableArgumentResolver.java rename to EnjoyTripBackend/src/main/java/com/example/EnjoyTripBackend/util/argumentresolver/LimitedPageableArgumentResolver.java index a4dc251..969d2a2 100644 --- a/EnjoyTripBackend/src/main/java/com/example/EnjoyTripBackend/util/LimitedPageableArgumentResolver.java +++ b/EnjoyTripBackend/src/main/java/com/example/EnjoyTripBackend/util/argumentresolver/LimitedPageableArgumentResolver.java @@ -1,4 +1,4 @@ -package com.example.EnjoyTripBackend.util; +package com.example.EnjoyTripBackend.util.argumentresolver; import com.example.EnjoyTripBackend.exception.EnjoyTripException; import com.example.EnjoyTripBackend.exception.ErrorCode; diff --git a/EnjoyTripBackend/src/main/java/com/example/EnjoyTripBackend/util/LimitedSizePagination.java b/EnjoyTripBackend/src/main/java/com/example/EnjoyTripBackend/util/argumentresolver/LimitedSizePagination.java similarity index 75% rename from EnjoyTripBackend/src/main/java/com/example/EnjoyTripBackend/util/LimitedSizePagination.java rename to EnjoyTripBackend/src/main/java/com/example/EnjoyTripBackend/util/argumentresolver/LimitedSizePagination.java index 6d96fd8..fb15678 100644 --- a/EnjoyTripBackend/src/main/java/com/example/EnjoyTripBackend/util/LimitedSizePagination.java +++ b/EnjoyTripBackend/src/main/java/com/example/EnjoyTripBackend/util/argumentresolver/LimitedSizePagination.java @@ -1,4 +1,4 @@ -package com.example.EnjoyTripBackend.util; +package com.example.EnjoyTripBackend.util.argumentresolver; import java.lang.annotation.*; diff --git a/EnjoyTripBackend/src/main/java/com/example/EnjoyTripBackend/util/SessionConst.java b/EnjoyTripBackend/src/main/java/com/example/EnjoyTripBackend/util/argumentresolver/SessionConst.java similarity index 60% rename from EnjoyTripBackend/src/main/java/com/example/EnjoyTripBackend/util/SessionConst.java rename to EnjoyTripBackend/src/main/java/com/example/EnjoyTripBackend/util/argumentresolver/SessionConst.java index a1ca2d9..589a647 100644 --- a/EnjoyTripBackend/src/main/java/com/example/EnjoyTripBackend/util/SessionConst.java +++ b/EnjoyTripBackend/src/main/java/com/example/EnjoyTripBackend/util/argumentresolver/SessionConst.java @@ -1,4 +1,4 @@ -package com.example.EnjoyTripBackend.util; +package com.example.EnjoyTripBackend.util.argumentresolver; public class SessionConst { public static final String LOGIN_MEMBER = "loginMember"; diff --git a/EnjoyTripBackend/src/main/java/com/example/EnjoyTripBackend/util/SessionUser.java b/EnjoyTripBackend/src/main/java/com/example/EnjoyTripBackend/util/argumentresolver/SessionUser.java similarity index 81% rename from EnjoyTripBackend/src/main/java/com/example/EnjoyTripBackend/util/SessionUser.java rename to EnjoyTripBackend/src/main/java/com/example/EnjoyTripBackend/util/argumentresolver/SessionUser.java index 5f67c13..1c67106 100644 --- a/EnjoyTripBackend/src/main/java/com/example/EnjoyTripBackend/util/SessionUser.java +++ b/EnjoyTripBackend/src/main/java/com/example/EnjoyTripBackend/util/argumentresolver/SessionUser.java @@ -1,4 +1,4 @@ -package com.example.EnjoyTripBackend.util; +package com.example.EnjoyTripBackend.util.argumentresolver; import java.lang.annotation.ElementType; import java.lang.annotation.Retention; diff --git a/EnjoyTripBackend/src/main/java/com/example/EnjoyTripBackend/util/SessionUserArgumentResolver.java b/EnjoyTripBackend/src/main/java/com/example/EnjoyTripBackend/util/argumentresolver/SessionUserArgumentResolver.java similarity index 88% rename from EnjoyTripBackend/src/main/java/com/example/EnjoyTripBackend/util/SessionUserArgumentResolver.java rename to EnjoyTripBackend/src/main/java/com/example/EnjoyTripBackend/util/argumentresolver/SessionUserArgumentResolver.java index 64953ab..559cd12 100644 --- a/EnjoyTripBackend/src/main/java/com/example/EnjoyTripBackend/util/SessionUserArgumentResolver.java +++ b/EnjoyTripBackend/src/main/java/com/example/EnjoyTripBackend/util/argumentresolver/SessionUserArgumentResolver.java @@ -1,4 +1,4 @@ -package com.example.EnjoyTripBackend.util; +package com.example.EnjoyTripBackend.util.argumentresolver; import jakarta.servlet.http.HttpServletRequest; import lombok.extern.slf4j.Slf4j; @@ -8,7 +8,7 @@ import org.springframework.web.method.support.HandlerMethodArgumentResolver; import org.springframework.web.method.support.ModelAndViewContainer; -import static com.example.EnjoyTripBackend.util.SessionConst.LOGIN_MEMBER; +import static com.example.EnjoyTripBackend.util.argumentresolver.SessionConst.LOGIN_MEMBER; @Slf4j public class SessionUserArgumentResolver implements HandlerMethodArgumentResolver { diff --git a/EnjoyTripBackend/src/main/java/com/example/EnjoyTripBackend/util/AirplaneInfoCollector.java b/EnjoyTripBackend/src/main/java/com/example/EnjoyTripBackend/util/collector/AirplaneInfoCollector.java similarity index 99% rename from EnjoyTripBackend/src/main/java/com/example/EnjoyTripBackend/util/AirplaneInfoCollector.java rename to EnjoyTripBackend/src/main/java/com/example/EnjoyTripBackend/util/collector/AirplaneInfoCollector.java index c403e05..e39e3c3 100644 --- a/EnjoyTripBackend/src/main/java/com/example/EnjoyTripBackend/util/AirplaneInfoCollector.java +++ b/EnjoyTripBackend/src/main/java/com/example/EnjoyTripBackend/util/collector/AirplaneInfoCollector.java @@ -1,4 +1,4 @@ -package com.example.EnjoyTripBackend.util; +package com.example.EnjoyTripBackend.util.collector; import com.example.EnjoyTripBackend.domain.Airplane; import com.example.EnjoyTripBackend.dto.airplane.AirplaneResponseDto; diff --git a/EnjoyTripBackend/src/main/java/com/example/EnjoyTripBackend/util/collector/CampingInfoCollector.java b/EnjoyTripBackend/src/main/java/com/example/EnjoyTripBackend/util/collector/CampingInfoCollector.java new file mode 100644 index 0000000..9a2ab42 --- /dev/null +++ b/EnjoyTripBackend/src/main/java/com/example/EnjoyTripBackend/util/collector/CampingInfoCollector.java @@ -0,0 +1,63 @@ +package com.example.EnjoyTripBackend.util.collector; + +import com.example.EnjoyTripBackend.domain.Camping; +import com.example.EnjoyTripBackend.dto.camping.CampingResponse; +import com.example.EnjoyTripBackend.exception.EnjoyTripException; +import com.example.EnjoyTripBackend.exception.ErrorCode; +import com.example.EnjoyTripBackend.service.CampingService; +import com.fasterxml.jackson.databind.ObjectMapper; +import lombok.RequiredArgsConstructor; +import org.json.XML; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.http.HttpMethod; +import org.springframework.http.ResponseEntity; +import org.springframework.scheduling.annotation.Scheduled; +import org.springframework.stereotype.Component; +import org.springframework.web.client.RestTemplate; +import org.springframework.web.util.UriComponentsBuilder; + +@Component +@RequiredArgsConstructor +public class CampingInfoCollector { + + @Value("${camping.url}") + private String targetUrl; + + private final RestTemplate restTemplate; + private final ObjectMapper objectMapper; + private final CampingService campingService; + + @Scheduled(cron = "0 0 9 1 * ?") + public void CampingInfoCollector1() { + try { + CampingResponse campingResponse = objectMapper.readValue(XML.toJSONObject(getCampingData()).toString(), CampingResponse.class); + insertCampingData(campingResponse); + } catch (Exception e) { + throw new EnjoyTripException(ErrorCode.FAIL_INSERT_CAMPING_DATA, e.getMessage()); + } + } + + private void insertCampingData(CampingResponse campingResponse) { + int totalDataSize = campingResponse.getResponse().getBody().getItems().getItem().size(); + for (int i=0; i< totalDataSize; i++){ + Camping camping = Camping.builder() + .name(campingResponse.getResponse().getBody().getItems().getItem().get(i).getFacltNm()) + .shortIntro(campingResponse.getResponse().getBody().getItems().getItem().get(i).getLineIntro()) + .Intro(campingResponse.getResponse().getBody().getItems().getItem().get(i).getIntro()) + .zipcode(campingResponse.getResponse().getBody().getItems().getItem().get(i).getZipcode()) + .address(campingResponse.getResponse().getBody().getItems().getItem().get(i).getAddr1()) + .latitude(campingResponse.getResponse().getBody().getItems().getItem().get(i).getMapX()) + .longitude(campingResponse.getResponse().getBody().getItems().getItem().get(i).getMapY()) + .imageUrl(campingResponse.getResponse().getBody().getItems().getItem().get(i).getFirstImageUrl()) + .homepage(campingResponse.getResponse().getBody().getItems().getItem().get(i).getHomepage()) + .build(); + campingService.save(camping); + } + } + + public String getCampingData() { + String url = UriComponentsBuilder.fromHttpUrl(targetUrl).toUriString(); + ResponseEntity responseEntity = restTemplate.exchange(url, HttpMethod.GET, null, String.class); + return responseEntity.getBody(); + } +} \ No newline at end of file diff --git a/EnjoyTripBackend/src/main/java/com/example/EnjoyTripBackend/util/GolfInfoCollector.java b/EnjoyTripBackend/src/main/java/com/example/EnjoyTripBackend/util/collector/GolfInfoCollector.java similarity index 97% rename from EnjoyTripBackend/src/main/java/com/example/EnjoyTripBackend/util/GolfInfoCollector.java rename to EnjoyTripBackend/src/main/java/com/example/EnjoyTripBackend/util/collector/GolfInfoCollector.java index ca30bb9..7af4859 100644 --- a/EnjoyTripBackend/src/main/java/com/example/EnjoyTripBackend/util/GolfInfoCollector.java +++ b/EnjoyTripBackend/src/main/java/com/example/EnjoyTripBackend/util/collector/GolfInfoCollector.java @@ -1,4 +1,4 @@ -package com.example.EnjoyTripBackend.util; +package com.example.EnjoyTripBackend.util.collector; import com.example.EnjoyTripBackend.dto.golf.GolfClubDto; import com.example.EnjoyTripBackend.dto.golf.GolfClubListDto; diff --git a/EnjoyTripBackend/src/main/resources/config/mybatis-config.xml b/EnjoyTripBackend/src/main/resources/config/mybatis-config.xml index 4c5ae3a..3889fe5 100644 --- a/EnjoyTripBackend/src/main/resources/config/mybatis-config.xml +++ b/EnjoyTripBackend/src/main/resources/config/mybatis-config.xml @@ -14,5 +14,6 @@ + \ No newline at end of file diff --git a/EnjoyTripBackend/src/main/resources/mapper/camping-query.xml b/EnjoyTripBackend/src/main/resources/mapper/camping-query.xml new file mode 100644 index 0000000..8f5beef --- /dev/null +++ b/EnjoyTripBackend/src/main/resources/mapper/camping-query.xml @@ -0,0 +1,25 @@ + + + + + + + insert + into camping + values (#{id}, #{name}, #{shortIntro}, #{Intro}, #{zipcode}, #{address}, #{latitude}, #{longitude}, #{imageUrl}, #{homepage}, #{tel}) + + + + + + diff --git a/EnjoyTripBackend/src/main/resources/mapper/golf-query.xml b/EnjoyTripBackend/src/main/resources/mapper/golf-query.xml index 6a8381d..e1ac34f 100644 --- a/EnjoyTripBackend/src/main/resources/mapper/golf-query.xml +++ b/EnjoyTripBackend/src/main/resources/mapper/golf-query.xml @@ -12,6 +12,7 @@ @@ -27,10 +28,10 @@ from golf - and location LIKE CONCAT('%', #{data.location}, '%') + and location LIKE CONCAT('%', #{data.location}, '%') AND green_fee_week IS NOT NULL AND green_fee_week != '' - and date = #{data.date} + and date = #{data.date} AND green_fee_week IS NOT NULL AND green_fee_week != '' limit #{pageable.pageSize}