-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' of https://github.com/KUIT-Couphone/Couphone-Server
- Loading branch information
Showing
25 changed files
with
586 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
version: 0.0 | ||
os: linux | ||
|
||
files: | ||
- source: / | ||
destination: /home/ubuntu/couphone | ||
permissions: | ||
- object: /home/ubuntu/couphone/ | ||
owner: ubuntu | ||
group: ubuntu | ||
hooks: | ||
AfterInstall: | ||
- location: scripts/deploy.sh | ||
timeout: 60 | ||
runas: ubuntu |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
|
||
REPOSITORY=/home/ubuntu/couphone | ||
cd $REPOSITORY | ||
|
||
APP_NAME=couphone | ||
JAR_NAME=$(ls $REPOSITORY/build/libs/ | grep 'SNAPSHOT.jar' | tail -n 1) | ||
JAR_PATH=$REPOSITORY/build/libs/$JAR_NAME | ||
|
||
CURRENT_PID=$(pgrep -f $APP_NAME) | ||
|
||
if [ -z $CURRENT_PID ] | ||
then | ||
echo "> 종료할 애플리케이션이 없습니다." | ||
else | ||
echo "> kill -9 $CURRENT_PID" | ||
kill -15 $CURRENT_PID | ||
sleep 5 | ||
fi | ||
|
||
echo "> Deploy - $JAR_PATH " | ||
nohup java -jar $JAR_PATH > /dev/null 2> /dev/null < /dev/null & |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
rootProject.name = 'Couphone-Server' | ||
rootProject.name = 'couphone-server' |
16 changes: 16 additions & 0 deletions
16
src/main/java/com/example/couphoneserver/common/datatype/Coordinate.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package com.example.couphoneserver.common.datatype; | ||
|
||
import lombok.Builder; | ||
import lombok.Data; | ||
|
||
@Data | ||
public class Coordinate { | ||
private double longitude; | ||
private double latitude; | ||
|
||
@Builder | ||
public Coordinate(double longitude, double latitude) { | ||
this.longitude = longitude; | ||
this.latitude = latitude; | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
src/main/java/com/example/couphoneserver/common/exception/StoreException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package com.example.couphoneserver.common.exception; | ||
|
||
import com.example.couphoneserver.common.response.status.ResponseStatus; | ||
import lombok.Getter; | ||
|
||
@Getter | ||
public class StoreException extends RuntimeException { | ||
private final ResponseStatus exceptionStatus; | ||
|
||
public StoreException(ResponseStatus exceptionStatus) { | ||
super(exceptionStatus.getMessage()); | ||
this.exceptionStatus = exceptionStatus; | ||
} | ||
|
||
public StoreException(ResponseStatus exceptionStatus, String message) { | ||
super(message); | ||
this.exceptionStatus = exceptionStatus; | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
...a/com/example/couphoneserver/common/exception_handler/StoreExceptionControllerAdvice.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package com.example.couphoneserver.common.exception_handler; | ||
|
||
import com.example.couphoneserver.common.exception.StoreException; | ||
import com.example.couphoneserver.common.response.BaseErrorResponse; | ||
import jakarta.annotation.Priority; | ||
import org.springframework.http.HttpStatus; | ||
import org.springframework.web.bind.annotation.ExceptionHandler; | ||
import org.springframework.web.bind.annotation.ResponseStatus; | ||
import org.springframework.web.bind.annotation.RestControllerAdvice; | ||
|
||
@Priority(0) | ||
@RestControllerAdvice | ||
public class StoreExceptionControllerAdvice { | ||
|
||
@ResponseStatus(HttpStatus.BAD_REQUEST) | ||
@ExceptionHandler(StoreException.class) | ||
public BaseErrorResponse handle_StoreException(StoreException e) { | ||
return new BaseErrorResponse(e.getExceptionStatus(), e.getMessage()); | ||
} | ||
|
||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
67 changes: 67 additions & 0 deletions
67
src/main/java/com/example/couphoneserver/controller/StoreController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
package com.example.couphoneserver.controller; | ||
|
||
import com.example.couphoneserver.common.annotation.NoAuth; | ||
import com.example.couphoneserver.common.datatype.Coordinate; | ||
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.tags.Tag; | ||
import lombok.RequiredArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.validation.BindingResult; | ||
import org.springframework.validation.annotation.Validated; | ||
import org.springframework.web.bind.annotation.*; | ||
|
||
import java.security.Principal; | ||
import java.util.List; | ||
|
||
import static com.example.couphoneserver.common.response.status.BaseExceptionResponseStatus.INVALID_STORE_VALUE; | ||
import static com.example.couphoneserver.utils.BindingResultUtils.getErrorMessages; | ||
|
||
@Tag(name = "store", description = "가게 관련 API 입니다.") | ||
@Slf4j | ||
@RestController | ||
@RequiredArgsConstructor | ||
@RequestMapping("/stores") | ||
public class StoreController { | ||
private final StoreService storeService; | ||
private final CoordinateConverter coordinateConverter; | ||
|
||
@NoAuth | ||
@PostMapping("") | ||
@Operation(summary = "가게 등록", description = "Request Body에 브랜드 아이디, 매장명, 위도, 경도, 주소를 담아서 보내주세요!") | ||
public BaseResponse<PostStoreResponse> postBrand(@Validated @RequestBody PostStoreRequest request, | ||
BindingResult bindingResult){ | ||
if (bindingResult.hasErrors()){ | ||
throw new StoreException(INVALID_STORE_VALUE,getErrorMessages(bindingResult)); | ||
} | ||
return new BaseResponse<>(storeService.save(request)); | ||
} | ||
|
||
@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())); | ||
} | ||
|
||
@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)); | ||
} | ||
|
||
} |
21 changes: 0 additions & 21 deletions
21
src/main/java/com/example/couphoneserver/domain/Address.java
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 14 additions & 0 deletions
14
src/main/java/com/example/couphoneserver/dto/store/PostCoordinateRequest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
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; | ||
} |
34 changes: 34 additions & 0 deletions
34
src/main/java/com/example/couphoneserver/dto/store/PostNearbyStoreRequest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
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.Data; | ||
import lombok.NoArgsConstructor; | ||
|
||
@Data | ||
@NoArgsConstructor | ||
public class PostNearbyStoreRequest { | ||
private static final int radius = 500; | ||
/* | ||
**버튼 있을 경우 ⇒ 지름 1km** | ||
**버튼 없을 경우 ⇒ 반지름 1km** | ||
*/ | ||
@NotNull(message = "longitude: {NotNull}") | ||
@Schema(example = "207005.189144674") | ||
private double longitude; | ||
@NotNull(message = "latitude: {NotNull}") | ||
@Schema(example = "449492.810069438") | ||
private double latitude; | ||
@NotNull(message = "is1km: {NotNull}") | ||
@Schema(example="true",description = "반지름이 1km인 경우 true를 넣어주세요") | ||
private Boolean is1km; | ||
@Nullable | ||
@Schema(description = "값을 넣어 보내지 마세요!") | ||
private double distance; | ||
|
||
public void setDistance() { | ||
this.distance = is1km?radius*2:radius; | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
src/main/java/com/example/couphoneserver/dto/store/PostNearbyStoreResponse.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package com.example.couphoneserver.dto.store; | ||
|
||
import com.example.couphoneserver.domain.entity.Brand; | ||
import com.example.couphoneserver.dto.brand.GetBrandResponse; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Builder; | ||
import lombok.Data; | ||
import lombok.NoArgsConstructor; | ||
|
||
@Data | ||
@NoArgsConstructor | ||
public class PostNearbyStoreResponse { | ||
private Long store_id; | ||
private String name; | ||
private Long brand_id; | ||
private GetBrandResponse getBrandResponse; | ||
private double distance; | ||
|
||
@Builder | ||
public PostNearbyStoreResponse(Long store_id, String name, Long brand_id) { | ||
this.store_id = store_id; | ||
this.name = name; | ||
this.brand_id = brand_id; | ||
} | ||
} |
Oops, something went wrong.