Skip to content

Commit

Permalink
Merge pull request #20 from KUIT-Couphone/feature/store
Browse files Browse the repository at this point in the history
refactor: post메소드를 get 메소드로 변경
  • Loading branch information
limsubinn authored Aug 5, 2023
2 parents d40ff54 + 4e23447 commit 52b1c4e
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 70 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -43,25 +44,26 @@ public BaseResponse<PostStoreResponse> postBrand(@Validated @RequestBody PostSto
}

@NoAuth
@PostMapping("/coordinate")
@Operation(summary = "좌표 변환", description = "Request Body에 주소를 담아 보내면 좌표를 반환합니다.")
public BaseResponse<Coordinate> 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<Coordinate> 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<List<PostNearbyStoreResponse>> 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<List<PostNearbyStoreResponse>> 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()));
}

}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -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**
Expand All @@ -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;
}
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -55,7 +55,7 @@ public PostStoreResponse save(PostStoreRequest request) {
/*
가게 조회
*/
public List<PostNearbyStoreResponse> findNearbyStores(Principal principal,PostNearbyStoreRequest request){
public List<PostNearbyStoreResponse> findNearbyStores(Principal principal, LocationInfo request){
List<PostNearbyStoreResponse> storeList = getCandidateStoreList(request);
Collections.sort(storeList, new Comparator<PostNearbyStoreResponse>() {
@Override
Expand All @@ -75,7 +75,7 @@ public int compare(PostNearbyStoreResponse o1, PostNearbyStoreResponse o2) {
return resultList;
}

private List<PostNearbyStoreResponse> getCandidateStoreList(PostNearbyStoreRequest request) {
private List<PostNearbyStoreResponse> getCandidateStoreList(LocationInfo request) {
request.setDistance();
double x = request.getLongitude();
double y = request.getLatitude();
Expand Down
6 changes: 3 additions & 3 deletions src/main/resources/import.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down
1 change: 1 addition & 0 deletions src/test/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit 52b1c4e

Please sign in to comment.