From 37c27ddbce2c4fab5cf70ac18d64d19254903e20 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=84=9C=EC=A7=80=ED=98=84?= <79920930+ji-hyeon97@users.noreply.github.com> Date: Mon, 20 May 2024 23:52:07 +0900 Subject: [PATCH 1/5] =?UTF-8?q?feat(#25)=20:=20=EC=BA=A0=ED=95=91=20?= =?UTF-8?q?=EA=B3=B5=EA=B3=B5=EB=8D=B0=EC=9D=B4=ED=84=B0=20api=20=EC=88=98?= =?UTF-8?q?=EC=A7=91=20collector=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../EnjoyTripBackend/domain/Camping.java | 25 ++++++++ .../dto/camping/CampItemDto.java | 22 +++++++ .../dto/camping/CampingResponse.java | 37 +++++++++++ .../EnjoyTripBackend/exception/ErrorCode.java | 3 +- .../repository/CampingRepository.java | 9 +++ .../service/CampingService.java | 20 ++++++ .../util/CampingInfoCollector.java | 63 +++++++++++++++++++ .../main/resources/config/mybatis-config.xml | 1 + .../main/resources/mapper/camping-query.xml | 12 ++++ 9 files changed, 191 insertions(+), 1 deletion(-) create mode 100644 EnjoyTripBackend/src/main/java/com/example/EnjoyTripBackend/domain/Camping.java create mode 100644 EnjoyTripBackend/src/main/java/com/example/EnjoyTripBackend/dto/camping/CampItemDto.java create mode 100644 EnjoyTripBackend/src/main/java/com/example/EnjoyTripBackend/dto/camping/CampingResponse.java create mode 100644 EnjoyTripBackend/src/main/java/com/example/EnjoyTripBackend/repository/CampingRepository.java create mode 100644 EnjoyTripBackend/src/main/java/com/example/EnjoyTripBackend/service/CampingService.java create mode 100644 EnjoyTripBackend/src/main/java/com/example/EnjoyTripBackend/util/CampingInfoCollector.java create mode 100644 EnjoyTripBackend/src/main/resources/mapper/camping-query.xml 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/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/repository/CampingRepository.java b/EnjoyTripBackend/src/main/java/com/example/EnjoyTripBackend/repository/CampingRepository.java new file mode 100644 index 0000000..51b61be --- /dev/null +++ b/EnjoyTripBackend/src/main/java/com/example/EnjoyTripBackend/repository/CampingRepository.java @@ -0,0 +1,9 @@ +package com.example.EnjoyTripBackend.repository; + +import com.example.EnjoyTripBackend.domain.Camping; +import org.apache.ibatis.annotations.Mapper; + +@Mapper +public interface CampingRepository { + Long save(Camping camping); +} \ 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..f91109a --- /dev/null +++ b/EnjoyTripBackend/src/main/java/com/example/EnjoyTripBackend/service/CampingService.java @@ -0,0 +1,20 @@ +package com.example.EnjoyTripBackend.service; + +import com.example.EnjoyTripBackend.domain.Camping; +import com.example.EnjoyTripBackend.repository.CampingRepository; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +@Service +@RequiredArgsConstructor +@Transactional(readOnly = true) +public class CampingService { + + private final CampingRepository campingRepository; + + @Transactional + public Long save(Camping camping) { + return campingRepository.save(camping); + } +} \ No newline at end of file diff --git a/EnjoyTripBackend/src/main/java/com/example/EnjoyTripBackend/util/CampingInfoCollector.java b/EnjoyTripBackend/src/main/java/com/example/EnjoyTripBackend/util/CampingInfoCollector.java new file mode 100644 index 0000000..2505195 --- /dev/null +++ b/EnjoyTripBackend/src/main/java/com/example/EnjoyTripBackend/util/CampingInfoCollector.java @@ -0,0 +1,63 @@ +package com.example.EnjoyTripBackend.util; + +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/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..4d0613f --- /dev/null +++ b/EnjoyTripBackend/src/main/resources/mapper/camping-query.xml @@ -0,0 +1,12 @@ + + + + + + + insert + into camping + values (#{id}, #{name}, #{shortIntro}, #{Intro}, #{zipcode}, #{address}, #{latitude}, #{longitude}, #{imageUrl}, #{homepage}, #{tel}) + + From a0d0c6aad04d115ea75f9b216ca762e27b0f919b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=84=9C=EC=A7=80=ED=98=84?= <79920930+ji-hyeon97@users.noreply.github.com> Date: Tue, 21 May 2024 00:07:57 +0900 Subject: [PATCH 2/5] =?UTF-8?q?refactor(#25)=20:=20=EC=BD=94=EB=93=9C=20?= =?UTF-8?q?=ED=8C=A8=ED=82=A4=EC=A7=80=20=EC=A0=95=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../EnjoyTripBackend/controller/AirplaneController.java | 2 +- .../example/EnjoyTripBackend/controller/GolfController.java | 2 +- .../example/EnjoyTripBackend/controller/MemberController.java | 2 +- .../EnjoyTripBackend/controller/PaymentController.java | 2 +- .../example/EnjoyTripBackend/controller/PlaceController.java | 2 +- .../com/example/EnjoyTripBackend/filter/LoginCheckFilter.java | 2 +- .../java/com/example/EnjoyTripBackend/filter/WebConfig.java | 4 ++-- .../java/com/example/EnjoyTripBackend/util/DataUpdater.java | 1 + .../LimitedPageableArgumentResolver.java | 2 +- .../util/{ => argumentresolver}/LimitedSizePagination.java | 2 +- .../util/{ => argumentresolver}/SessionConst.java | 2 +- .../util/{ => argumentresolver}/SessionUser.java | 2 +- .../{ => argumentresolver}/SessionUserArgumentResolver.java | 4 ++-- .../util/{ => collector}/AirplaneInfoCollector.java | 2 +- .../util/{ => collector}/CampingInfoCollector.java | 2 +- .../util/{ => collector}/GolfInfoCollector.java | 2 +- 16 files changed, 18 insertions(+), 17 deletions(-) rename EnjoyTripBackend/src/main/java/com/example/EnjoyTripBackend/util/{ => argumentresolver}/LimitedPageableArgumentResolver.java (95%) rename EnjoyTripBackend/src/main/java/com/example/EnjoyTripBackend/util/{ => argumentresolver}/LimitedSizePagination.java (75%) rename EnjoyTripBackend/src/main/java/com/example/EnjoyTripBackend/util/{ => argumentresolver}/SessionConst.java (60%) rename EnjoyTripBackend/src/main/java/com/example/EnjoyTripBackend/util/{ => argumentresolver}/SessionUser.java (81%) rename EnjoyTripBackend/src/main/java/com/example/EnjoyTripBackend/util/{ => argumentresolver}/SessionUserArgumentResolver.java (88%) rename EnjoyTripBackend/src/main/java/com/example/EnjoyTripBackend/util/{ => collector}/AirplaneInfoCollector.java (99%) rename EnjoyTripBackend/src/main/java/com/example/EnjoyTripBackend/util/{ => collector}/CampingInfoCollector.java (98%) rename EnjoyTripBackend/src/main/java/com/example/EnjoyTripBackend/util/{ => collector}/GolfInfoCollector.java (97%) 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/GolfController.java b/EnjoyTripBackend/src/main/java/com/example/EnjoyTripBackend/controller/GolfController.java index 74b3d81..e4106d5 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; 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/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/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/CampingInfoCollector.java b/EnjoyTripBackend/src/main/java/com/example/EnjoyTripBackend/util/collector/CampingInfoCollector.java similarity index 98% rename from EnjoyTripBackend/src/main/java/com/example/EnjoyTripBackend/util/CampingInfoCollector.java rename to EnjoyTripBackend/src/main/java/com/example/EnjoyTripBackend/util/collector/CampingInfoCollector.java index 2505195..9a2ab42 100644 --- a/EnjoyTripBackend/src/main/java/com/example/EnjoyTripBackend/util/CampingInfoCollector.java +++ b/EnjoyTripBackend/src/main/java/com/example/EnjoyTripBackend/util/collector/CampingInfoCollector.java @@ -1,4 +1,4 @@ -package com.example.EnjoyTripBackend.util; +package com.example.EnjoyTripBackend.util.collector; import com.example.EnjoyTripBackend.domain.Camping; import com.example.EnjoyTripBackend.dto.camping.CampingResponse; 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; From 85e9b07c0da1dfd9dfe99f55887fe79bdd45bd94 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=84=9C=EC=A7=80=ED=98=84?= Date: Tue, 21 May 2024 09:07:51 +0900 Subject: [PATCH 3/5] =?UTF-8?q?refactor=20:=20=EA=B3=A8=ED=94=84=20?= =?UTF-8?q?=EC=84=9C=EB=B9=84=EC=8A=A4=20dto=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../EnjoyTripBackend/controller/GolfController.java | 4 ++-- .../EnjoyTripBackend/dto/golf/GolfResponseDto.java | 10 +++++----- 2 files changed, 7 insertions(+), 7 deletions(-) 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 e4106d5..2f4e534 100644 --- a/EnjoyTripBackend/src/main/java/com/example/EnjoyTripBackend/controller/GolfController.java +++ b/EnjoyTripBackend/src/main/java/com/example/EnjoyTripBackend/controller/GolfController.java @@ -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/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 From 6c3bf7fe560effb2c53a0ea020a53e1512654255 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=84=9C=EC=A7=80=ED=98=84?= Date: Tue, 21 May 2024 12:47:03 +0900 Subject: [PATCH 4/5] =?UTF-8?q?feat(#25)=20:=20=EC=BA=A0=ED=95=91=20?= =?UTF-8?q?=EB=8D=B0=EC=9D=B4=ED=84=B0=20=EB=AA=A9=EB=A1=9D=20=EA=B5=AC?= =?UTF-8?q?=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/CampingController.java | 29 +++++++++++++++++++ .../dto/camping/CampingResponseDto.java | 21 ++++++++++++++ .../repository/CampingRepository.java | 6 ++++ .../service/CampingService.java | 16 ++++++++++ .../main/resources/mapper/camping-query.xml | 13 +++++++++ 5 files changed, 85 insertions(+) create mode 100644 EnjoyTripBackend/src/main/java/com/example/EnjoyTripBackend/controller/CampingController.java create mode 100644 EnjoyTripBackend/src/main/java/com/example/EnjoyTripBackend/dto/camping/CampingResponseDto.java 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/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/repository/CampingRepository.java b/EnjoyTripBackend/src/main/java/com/example/EnjoyTripBackend/repository/CampingRepository.java index 51b61be..b4c55a2 100644 --- a/EnjoyTripBackend/src/main/java/com/example/EnjoyTripBackend/repository/CampingRepository.java +++ b/EnjoyTripBackend/src/main/java/com/example/EnjoyTripBackend/repository/CampingRepository.java @@ -1,9 +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 index f91109a..be0f5ff 100644 --- a/EnjoyTripBackend/src/main/java/com/example/EnjoyTripBackend/service/CampingService.java +++ b/EnjoyTripBackend/src/main/java/com/example/EnjoyTripBackend/service/CampingService.java @@ -1,11 +1,17 @@ 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) @@ -17,4 +23,14 @@ public class CampingService { 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/resources/mapper/camping-query.xml b/EnjoyTripBackend/src/main/resources/mapper/camping-query.xml index 4d0613f..8f5beef 100644 --- a/EnjoyTripBackend/src/main/resources/mapper/camping-query.xml +++ b/EnjoyTripBackend/src/main/resources/mapper/camping-query.xml @@ -9,4 +9,17 @@ into camping values (#{id}, #{name}, #{shortIntro}, #{Intro}, #{zipcode}, #{address}, #{latitude}, #{longitude}, #{imageUrl}, #{homepage}, #{tel}) + + + + From e6945d750839b19adff1dd004171f8b67b850251 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=84=9C=EC=A7=80=ED=98=84?= Date: Tue, 21 May 2024 14:10:02 +0900 Subject: [PATCH 5/5] =?UTF-8?q?feat(#13)=20:=20=EA=B0=80=EA=B2=A9=EC=9D=B4?= =?UTF-8?q?=20=EB=AA=85=EC=8B=9C=EB=90=98=EC=96=B4=20=EC=9E=88=EB=8A=94=20?= =?UTF-8?q?=EA=B3=A8=ED=94=84=EB=8D=B0=EC=9D=B4=ED=84=B0=EB=A7=8C=20?= =?UTF-8?q?=EC=B6=94=EC=B6=9C=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- EnjoyTripBackend/src/main/resources/mapper/golf-query.xml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) 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}