diff --git a/src/main/java/com/example/couphoneserver/controller/StoreController.java b/src/main/java/com/example/couphoneserver/controller/StoreController.java index 784860e..06210e9 100644 --- a/src/main/java/com/example/couphoneserver/controller/StoreController.java +++ b/src/main/java/com/example/couphoneserver/controller/StoreController.java @@ -5,10 +5,11 @@ import com.example.couphoneserver.common.exception.StoreException; import com.example.couphoneserver.common.response.BaseResponse; import com.example.couphoneserver.dto.store.*; -import com.example.couphoneserver.repository.mappingInterface.StoreInfoMapping; import com.example.couphoneserver.service.StoreService; import com.example.couphoneserver.utils.CoordinateConverter; import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.Parameter; +import io.swagger.v3.oas.annotations.enums.ParameterIn; import io.swagger.v3.oas.annotations.tags.Tag; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; @@ -43,25 +44,26 @@ public BaseResponse postBrand(@Validated @RequestBody PostSto } @NoAuth - @PostMapping("/coordinate") - @Operation(summary = "좌표 변환", description = "Request Body에 주소를 담아 보내면 좌표를 반환합니다.") - public BaseResponse translateCoordinate(@Validated @RequestBody PostCoordinateRequest request, - BindingResult bindingResult){ - if (bindingResult.hasErrors()){ - throw new StoreException(INVALID_STORE_VALUE,getErrorMessages(bindingResult)); - } - return new BaseResponse<>(coordinateConverter.getCoordinate(request.getAddress())); + @GetMapping("/coordinate") + @Operation(summary = "좌표 변환", description = "query string에 주소를 담아 보내면 좌표를 반환합니다.") + public BaseResponse translateCoordinate(@Parameter(name = "query", description = "도로명주소",example = "서울특별시 광진구 능동로 111",in = ParameterIn.QUERY) + @RequestParam(required = true) String query){ + return new BaseResponse<>(coordinateConverter.getCoordinate(query)); } - @PostMapping("/nearby") - @Operation(summary = "좌표 중심 가게 반환", description = "Request Body에 좌표를 담아 보내면 주변 가게 리스트를 반환합니다.") - public BaseResponse> translateCoordinate(@Validated @RequestBody PostNearbyStoreRequest request, - Principal principal, - BindingResult bindingResult){ - if (bindingResult.hasErrors()){ - throw new StoreException(INVALID_STORE_VALUE,getErrorMessages(bindingResult)); - } - return new BaseResponse<>(storeService.findNearbyStores(principal,request)); + @GetMapping("/nearby") + @Operation(summary = "좌표 중심 가게 반환", description = "query string에 위도, 경도, 버튼 여부를 보내면 주변 가게 리스트를 반환합니다. 좌표게: epsg:5181") + public BaseResponse> translateCoordinate( + @Parameter(name = "longitude", description = "경도", example = "207005.189144674",in = ParameterIn.QUERY) @RequestParam Double longitude, + @Parameter(name = "latitude", description = "위도", example = "449492.810069438", in = ParameterIn.QUERY) @RequestParam Double latitude, + @Parameter(name = "is1km", description = "버튼 누른 경우 true", in = ParameterIn.QUERY)@RequestParam Boolean is1km, + Principal principal){ + return new BaseResponse<>(storeService.findNearbyStores(principal, + LocationInfo.builder() + .longitude(longitude) + .latitude(latitude) + .is1km(is1km) + .build())); } } diff --git a/src/main/java/com/example/couphoneserver/controller/UploadController.java b/src/main/java/com/example/couphoneserver/controller/UploadController.java deleted file mode 100644 index 4a01585..0000000 --- a/src/main/java/com/example/couphoneserver/controller/UploadController.java +++ /dev/null @@ -1,28 +0,0 @@ -package com.example.couphoneserver.controller; - -import com.example.couphoneserver.common.annotation.NoAuth; -import com.example.couphoneserver.utils.S3Uploader; -import lombok.RequiredArgsConstructor; -import lombok.extern.slf4j.Slf4j; -import org.springframework.http.MediaType; -import org.springframework.web.bind.annotation.PostMapping; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RequestPart; -import org.springframework.web.bind.annotation.RestController; -import org.springframework.web.multipart.MultipartFile; - -@RestController -@Slf4j -@RequestMapping(value = "/upload") -@RequiredArgsConstructor -public class UploadController { - private final S3Uploader s3Uploader; - - @NoAuth - @PostMapping(value="",consumes = MediaType.MULTIPART_FORM_DATA_VALUE) - public String postImage( - @RequestPart("file") MultipartFile multipartFile) { - log.error("[UploadController.upload]"); - return s3Uploader.upload(multipartFile); - } -} \ No newline at end of file diff --git a/src/main/java/com/example/couphoneserver/dto/store/PostNearbyStoreRequest.java b/src/main/java/com/example/couphoneserver/dto/store/LocationInfo.java similarity index 78% rename from src/main/java/com/example/couphoneserver/dto/store/PostNearbyStoreRequest.java rename to src/main/java/com/example/couphoneserver/dto/store/LocationInfo.java index b14eda2..77c18fe 100644 --- a/src/main/java/com/example/couphoneserver/dto/store/PostNearbyStoreRequest.java +++ b/src/main/java/com/example/couphoneserver/dto/store/LocationInfo.java @@ -1,14 +1,14 @@ package com.example.couphoneserver.dto.store; import io.swagger.v3.oas.annotations.media.Schema; -import jakarta.annotation.Nullable; import jakarta.validation.constraints.NotNull; +import lombok.Builder; import lombok.Data; import lombok.NoArgsConstructor; @Data @NoArgsConstructor -public class PostNearbyStoreRequest { +public class LocationInfo { private static final int radius = 500; /* **버튼 있을 경우 ⇒ 지름 1km** @@ -24,10 +24,15 @@ public class PostNearbyStoreRequest { @NotNull(message = "is1km: {NotNull}") @Schema(example="true",description = "반지름이 1km인 경우 true를 넣어주세요") private Boolean is1km; - @Nullable - @Schema(description = "값을 넣어 보내지 마세요!") private double distance; + @Builder + public LocationInfo(double longitude, double latitude, Boolean is1km) { + this.longitude = longitude; + this.latitude = latitude; + this.is1km = is1km; + } + public void setDistance() { this.distance = is1km?radius*2:radius; } diff --git a/src/main/java/com/example/couphoneserver/dto/store/PostCoordinateRequest.java b/src/main/java/com/example/couphoneserver/dto/store/PostCoordinateRequest.java deleted file mode 100644 index 465da1e..0000000 --- a/src/main/java/com/example/couphoneserver/dto/store/PostCoordinateRequest.java +++ /dev/null @@ -1,14 +0,0 @@ -package com.example.couphoneserver.dto.store; - -import io.swagger.v3.oas.annotations.media.Schema; -import jakarta.validation.constraints.NotBlank; -import lombok.Data; -import lombok.NoArgsConstructor; - -@Data -@NoArgsConstructor -public class PostCoordinateRequest { - @NotBlank(message = "address: {NotBlank}") - @Schema(example = "서울특별시 광진구 능동로 120") - private String address; -} diff --git a/src/main/java/com/example/couphoneserver/service/StoreService.java b/src/main/java/com/example/couphoneserver/service/StoreService.java index cae4793..cf52cc4 100644 --- a/src/main/java/com/example/couphoneserver/service/StoreService.java +++ b/src/main/java/com/example/couphoneserver/service/StoreService.java @@ -8,7 +8,7 @@ import com.example.couphoneserver.domain.entity.CouponItem; import com.example.couphoneserver.domain.entity.Store; import com.example.couphoneserver.dto.brand.GetBrandResponse; -import com.example.couphoneserver.dto.store.PostNearbyStoreRequest; +import com.example.couphoneserver.dto.store.LocationInfo; import com.example.couphoneserver.dto.store.PostNearbyStoreResponse; import com.example.couphoneserver.dto.store.PostStoreRequest; import com.example.couphoneserver.dto.store.PostStoreResponse; @@ -55,7 +55,7 @@ public PostStoreResponse save(PostStoreRequest request) { /* 가게 조회 */ - public List findNearbyStores(Principal principal,PostNearbyStoreRequest request){ + public List findNearbyStores(Principal principal, LocationInfo request){ List storeList = getCandidateStoreList(request); Collections.sort(storeList, new Comparator() { @Override @@ -75,7 +75,7 @@ public int compare(PostNearbyStoreResponse o1, PostNearbyStoreResponse o2) { return resultList; } - private List getCandidateStoreList(PostNearbyStoreRequest request) { + private List getCandidateStoreList(LocationInfo request) { request.setDistance(); double x = request.getLongitude(); double y = request.getLatitude(); diff --git a/src/main/resources/import.sql b/src/main/resources/import.sql index 0294759..eabf173 100644 --- a/src/main/resources/import.sql +++ b/src/main/resources/import.sql @@ -14,9 +14,9 @@ INSERT INTO brand (brand_id, category_id, created_date, modified_date, brand_ima INSERT INTO brand (brand_id, category_id, created_date, modified_date, brand_image_url, name, reward_description, status) VALUES (3, 1, '2023-07-30 10:00:00', '2023-07-30 10:05:00', 'https://example.com/images/brand2.jpg', '컴포즈 커피', '아이스 아메리카노 한 잔 무료 증정', 'ACTIVE'); -- 샘플 데이터 생성: store 테이블 -INSERT INTO store (store_id, latitude, longitude, brand_id, created_date, modified_date, city, name, status, street, zipcode) VALUES (1, 37.12345, -122.67890, 1, '2023-07-31 13:00:00', '2023-07-31 13:00:00', '서울특별시', '메가커피 건대입구점', 'ACTIVE', '건대입구로', '1111'); -INSERT INTO store (store_id, latitude, longitude, brand_id, created_date, modified_date, city, name, status, street, zipcode) VALUES (2, 37.12345, -110.67890, 1, '2023-07-31 13:00:00', '2023-07-31 13:00:00', '서울특별시', '메가커피 세종대입구점', 'ACTIVE', '세종대입구로', '2222'); -INSERT INTO store (store_id, latitude, longitude, brand_id, created_date, modified_date, city, name, status, street, zipcode) VALUES (3, 37.12345, -100.67890, 2, '2023-07-31 13:00:00', '2023-07-31 13:00:00', '서울특별시', '컴포즈커피 건대입구점', 'ACTIVE', '건대입구로', '1111'); +INSERT INTO store (store_id, latitude, longitude, brand_id, created_date, modified_date, name, status, address) VALUES (1, 37.12345, -122.67890, 1, '2023-07-31 13:00:00', '2023-07-31 13:00:00', '메가커피 건대입구점', 'ACTIVE', '서울특별시 건대입구로 1111'); +INSERT INTO store (store_id, latitude, longitude, brand_id, created_date, modified_date, name, status, address) VALUES (2, 37.12345, -110.67890, 1, '2023-07-31 13:00:00', '2023-07-31 13:00:00', '메가커피 세종대입구점', 'ACTIVE', '서울특별시 세종대입구로 2222'); +INSERT INTO store (store_id, latitude, longitude, brand_id, created_date, modified_date, name, status, address) VALUES (3, 37.12345, -100.67890, 2, '2023-07-31 13:00:00', '2023-07-31 13:00:00', '컴포즈커피 건대입구점', 'ACTIVE', '서울특별시 건대입구로 1111'); -- 샘플 데이터 생성: coupon_item 테이블 INSERT INTO coupon_item (coupon_item_id, stamp_count, brand_id, created_date, member_id, modified_date, status) VALUES (1, 5, 1, '2023-07-31 12:45:00', 1, '2023-07-31 12:45:00', 'INACTIVE'); diff --git a/src/test/resources/application.yml b/src/test/resources/application.yml index 444b541..dd458d9 100644 --- a/src/test/resources/application.yml +++ b/src/test/resources/application.yml @@ -63,6 +63,7 @@ spring: database: mysql database-platform: org.hibernate.dialect.MySQLDialect hibernate: + database-platform: org.hibernate.dialect.MySQLDialect ddl-auto: create properties: hibernate: