Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[MERGE] develop을 main에 반영 #167

Merged
merged 2 commits into from
Feb 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,10 @@ dependencies {
implementation 'org.springdoc:springdoc-openapi-starter-webmvc-ui:2.0.2'
// Spring Boot WebFlux
implementation 'org.springframework.boot:spring-boot-starter-webflux:3.1.8'
// Spring Boot Data MongoDB
implementation 'org.springframework.boot:spring-boot-starter-data-mongodb:3.1.8'
// Spring Boot WebSocket
implementation 'org.springframework.boot:spring-boot-starter-websocket:3.1.8'

// SpringBoot Test
testImplementation 'org.springframework.boot:spring-boot-starter-test:3.1.8'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@

import io.oeid.mogakgo.common.base.CursorPaginationInfoReq;
import io.oeid.mogakgo.common.base.CursorPaginationResult;
import io.oeid.mogakgo.core.properties.swagger.error.SwaggerProfileCardErrorExamples;
import io.oeid.mogakgo.core.properties.swagger.error.SwaggerProfileCardLikeErrorExamples;
import io.oeid.mogakgo.core.properties.swagger.error.SwaggerUserErrorExamples;
import io.oeid.mogakgo.domain.profile.presentation.dto.req.UserProfileLikeCancelAPIReq;
import io.oeid.mogakgo.domain.profile.presentation.dto.req.UserProfileLikeCreateAPIReq;
import io.oeid.mogakgo.domain.profile.presentation.dto.res.UserProfileLikeAPIRes;
import io.oeid.mogakgo.domain.profile.presentation.dto.res.UserProfileLikeCreateAPIRes;
Expand Down Expand Up @@ -125,4 +127,33 @@ ResponseEntity<CursorPaginationResult<UserProfileLikeInfoAPIRes>> getProfileLike
@Parameter(description = "'찔러보기' 요청을 조회하는 사용자 ID", required = true) Long id,
@Parameter(hidden = true) CursorPaginationInfoReq pageable
);

@Operation(summary = "사용자의 '찔러보기' 요청 취소", description = "사용자가 자신이 보낸 '찔러보기' 요청을 취소할 때 사용하는 API")
@ApiResponses(value = {
@ApiResponse(responseCode = "204", description = "'찔러보기' 요청 취소 성공"),
@ApiResponse(responseCode = "400", description = "요청한 데이터가 유효하지 않음",
content = @Content(
mediaType = "application/json",
schema = @Schema(implementation = ErrorResponse.class),
examples = {
@ExampleObject(name = "E040105", value = SwaggerProfileCardLikeErrorExamples.PROFILE_CARD_LIKE_NOT_EXIST),
@ExampleObject(name = "E040104", value = SwaggerProfileCardErrorExamples.PROFILE_CARD_LIKE_AMOUNT_IS_ZERO),
@ExampleObject(name = "E020107", value = SwaggerUserErrorExamples.USER_AVAILABLE_LIKE_COUNT_IS_ZERO),
@ExampleObject(name = "E020108", value = SwaggerUserErrorExamples.USER_AVAILABLE_LIKE_COUNT_IS_FULL)
}
)),
@ApiResponse(responseCode = "404", description = "요청한 데이터가 존재하지 않음",
content = @Content(
mediaType = "application/json",
schema = @Schema(implementation = ErrorResponse.class),
examples = {
@ExampleObject(name = "E020301", value = SwaggerUserErrorExamples.USER_NOT_FOUND),
@ExampleObject(name = "E040301", value = SwaggerProfileCardLikeErrorExamples.PROFILE_CARD_NOT_FOUND)
}
)),
})
ResponseEntity<Void> cancel(
@Parameter(hidden = true) Long userId,
UserProfileLikeCancelAPIReq request
);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package io.oeid.mogakgo.core.properties.swagger.error;

public class SwaggerProfileCardErrorExamples {

public static final String PROFILE_CARD_LIKE_AMOUNT_IS_ZERO = "{\"timestamp\":\"2024-02-17T10:07:31.404Z\",\"statusCode\":400,\"code\":\"E040104\",\"message\":\"해당 프로필 카드에 찔러보기 요청이 존재하지 않으므로 더 이상 차감할 수 없습니다.\"}";
private SwaggerProfileCardErrorExamples() {

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@
public class SwaggerProfileCardLikeErrorExamples {

public static final String PROFILE_CARD_LIKE_ALREADY_EXIST = "{\"timestamp\":\"2024-02-17T10:07:31.404Z\",\"statusCode\":400,\"code\":\"E040102\",\"message\":\"이미 찔러보기 요청을 전송한 프로필 카드에 찔러보기 요청을 전송할 수 없습니다.\"}";
public static final String PROFILE_CARD_LIKE_NOT_EXIST = "{\"timestamp\":\"2024-02-17T10:07:31.404Z\",\"statusCode\":400,\"code\":\"E040105\",\"message\":\"해당 프로필 카드에 찔러보기 요청이 존재하지 않아 요청을 취소할 수 없습니다.\"}";
public static final String INVALID_PROFILE_CARD_LIKE_RECEIVER_INFO = "{\"timestamp\":\"2024-02-17T10:07:31.404Z\",\"statusCode\":400,\"code\":\"E040103\",\"message\":\"찔러보기 요청의 사용자가 존재하지 않습니다.\"}";
public static final String PROFILE_CARD_LIKE_FORBIDDEN_OPERATION = "{\"timestamp\":\"2024-02-17T10:07:31.404Z\",\"statusCode\":403,\"code\":\"E040103\",\"message\":\"본인의 프로필 카드 외에 대해 찔러보기 요청 권한이 없습니다.\"}";
public static final String PROFILE_CARD_NOT_FOUND = "{\"timestamp\":\"2024-02-17T10:07:31.404Z\",\"statusCode\":404,\"code\":\"E040301\",\"message\":\"해당 프로필 카드가 존재하지 않습니다.\"}";

private SwaggerProfileCardLikeErrorExamples() {
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ public class SwaggerUserErrorExamples {
public static final String USER_NOT_FOUND = "{\"timestamp\":\"2024-02-17T10:07:31.404Z\",\"statusCode\":404,\"code\":\"E020301\",\"message\":\"해당 유저가 존재하지 않습니다.\"}";
public static final String USER_WANTED_JOB_DUPLICATE = "{\"timestamp\":\"2024-02-17T10:07:31.404Z\",\"statusCode\":400,\"code\":\"E020105\",\"message\":\"중복된 희망 직무가 있습니다.\"}";
public static final String INVALID_USER_NAME = "{\"timestamp\":\"2024-02-17T10:07:31.404Z\",\"statusCode\":400,\"code\":\"E020103\",\"message\":\"유저 이름은 비어있을 수 없습니다.\"}";
public static final String USER_AVAILABLE_LIKE_COUNT_IS_ZERO = "{\"timestamp\":\"2024-02-17T10:07:31.404Z\",\"statusCode\":400,\"code\":\"E020107\",\"message\":\"당일 사용 가능한 찔러보기 요청을 모두 소진했습니다.\"}";
public static final String USER_AVAILABLE_LIKE_COUNT_IS_FULL = "{\"timestamp\":\"2024-02-17T10:07:31.404Z\",\"statusCode\":400,\"code\":\"E020108\",\"message\":\"당일 사용 가능한 찔러보기 최대 요청 횟수를 초과활 수 없습니다.\"}";

private SwaggerUserErrorExamples() {
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ public class AuthController implements AuthSwagger {
@PostMapping("/reissue")
public ResponseEntity<AuthAccessTokenResponse> reissue(
@RequestHeader("Authorization") String accessToken, @RequestBody AuthReissueRequest request) {
accessToken = accessToken.substring(7);
var accessTokenDto = authService.reissue(accessToken, request.getRefreshToken());
return ResponseEntity.ok(AuthAccessTokenResponse.of(accessTokenDto.getAccessToken(), null));
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
package io.oeid.mogakgo.domain.auth.presentation.dto.req;

import io.swagger.v3.oas.annotations.media.Schema;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;

@Getter
@AllArgsConstructor
@NoArgsConstructor
@Schema(description = "토큰 재발급 요청")
public class AuthReissueRequest {

@Schema(description = "Refresh Token")
private final String refreshToken;
private String refreshToken;
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import io.oeid.mogakgo.domain.geo.domain.enums.Region;
import io.oeid.mogakgo.domain.geo.exception.GeoException;
import io.oeid.mogakgo.domain.user.application.UserCommonService;
import io.oeid.mogakgo.domain.user.application.UserGeoService;
import io.oeid.mogakgo.domain.user.domain.User;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
Expand All @@ -18,30 +17,22 @@
@RequiredArgsConstructor
public class CertService {

private final UserGeoService userGeoService;
private final UserCommonService userCommonService;

@Transactional
public Long certificate(Long tokenUserId, Long userId, int areaCode) {
User tokenUser = validateToken(tokenUserId);
validateCertificator(tokenUser, userId);
User user = validateToken(tokenUserId);
validateCertificator(user, userId);
Region region = validateAreaCodeCoverage(areaCode);
if (isPossibleCertification(userId, region)) {
userGeoService.updateUserGeo(userId, region);
}

user.updateRegion(region);
return userId;
}

private User validateToken(Long userId) {
return userCommonService.getUserById(userId);
}

// 사용자가 아직 동네 인증을 하지 않았거나, 새롭게 인증하려는 지역이 이미 인증된 지역과 다를 경우만 동네 인증 처리
private boolean isPossibleCertification(Long userId, Region region) {
Region userRegionInfo = userGeoService.getUserGeo(userId).getRegion();
return userRegionInfo == null || userRegionInfo != region;
}

private void validateCertificator(User tokenUser, Long userId) {
if (!tokenUser.getId().equals(userId)) {
throw new CertException(INVALID_CERT_INFORMATION);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,22 @@ public class GeoService {

public int getUserRegionInfoAboutCoordinates(Long tokenUserId, Double x, Double y) {
validateToken(tokenUserId);
validateCoordinates(x, y);
return validateCoordinatesCoverage(x, y);
return getRegionAboutCoordinates(x, y).getAreaCode();
}

public Region getRegionAboutCoordinates(Double x, Double y) {
// 해당 법정구역코드가 유효한 서비스 지역인지 검증
return validateAreaCodeCoverage(getAreaCodeAboutCoordinates(x, y));
}

public int getAreaCodeAboutCoordinates(Double x, Double y) {
// 해당 좌표가 유효한 서비스 지역 내 좌표인지 검증
validateAvailableCoordinates(x, y);
AddressDocument document = getAddressInfoAboutAreaCode(x, y);
return extractAreaCode(document);
}

public AddressDocument getAddressInfoAboutAreaCode(Double x, Double y) {
private AddressDocument getAddressInfoAboutAreaCode(Double x, Double y) {
String key = generateKey(kakaoProperties);
AddressInfoDto response = kakaoFeignClient.getAreaCodeAboutCoordinates(key, x, y);
return response.getDocuments()[0];
Expand All @@ -49,26 +55,22 @@ private int extractAreaCode(AddressDocument document) {
return Integer.parseInt(document.getCode().substring(0, 5));
}

private int validateCoordinatesCoverage(Double x, Double y) {
int areaCode = getAreaCodeAboutCoordinates(x, y);
validateCodeCoverage(areaCode);
return areaCode;
private void validateAvailableCoordinates(Double x, Double y) {
if (x < 123.0 || x > 132.0 || y < 32.0 || y > 39.0) {
throw new GeoException(INVALID_SERVICE_REGION);
}
}

private void validateCodeCoverage(int areaCode) {
if (Region.getByAreaCode(areaCode) == null) {
private Region validateAreaCodeCoverage(int areaCode) {
Region region = Region.getByAreaCode(areaCode);
if (region == null) {
throw new GeoException(INVALID_SERVICE_REGION);
}
return region;
}

private User validateToken(Long userId) {
return userCommonService.getUserById(userId);
}

private void validateCoordinates(Double x, Double y) {
if (x < 123.0 || x > 132.0 || y < 32.0 || y > 39.0) {
throw new GeoException(INVALID_SERVICE_REGION);
}
}

}
26 changes: 13 additions & 13 deletions src/main/java/io/oeid/mogakgo/domain/geo/domain/enums/Region.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,31 +8,31 @@
@RequiredArgsConstructor
public enum Region {

JONGRO("서울특별시", "종로구", 11110),
JONGNO("서울특별시", "종로구", 11110),
JUNG("서울특별시", "중구", 11140),
YONGSAN("서울특별시", "용산구", 11170),
SEONGDONG("서울특별시", "성동구", 11200),
KWANGJIN("서울특별시", "광진구", 11215),
GWANGJIN("서울특별시", "광진구", 11215),
DONGDAEMUN("서울특별시", "동대문구", 11230),
JUNGRANG("서울특별시", "중랑구", 11260),
JUNGNANG("서울특별시", "중랑구", 11260),
SEONGBUK("서울특별시", "성북구", 11290),
KANGBUK("서울특별시", "강북구", 11305),
GANGBUK("서울특별시", "강북구", 11305),
DOBONG("서울특별시", "도봉구", 11320),
NOWON("서울특별시", "노원구", 11350),
EUNPYEONG("서울특별시", "은평구", 11380),
SEODAEMUN("서울특별시", "서대문구", 11410),
MAPO("서울특별시", "마포구", 11440),
YANGCHUN("서울특별시", "양천구", 11470),
KANGSEO("서울특별시", "강서구", 11500),
YANGCHEON("서울특별시", "양천구", 11470),
GANGSEO("서울특별시", "강서구", 11500),
GURO("서울특별시", "구로구", 11530),
GEUMCHUN("서울특별시", "금천구", 11545),
GEUMCHEON("서울특별시", "금천구", 11545),
YOUNGDEUNGPO("서울특별시", "영등포구", 11560),
DONGJAK("서울특별시", "동작구", 11590),
KWANAK("서울특별시", "관악구", 11620),
GWANAK("서울특별시", "관악구", 11620),
SEOCHO("서울특별시", "서초구", 11650),
KANGNAM("서울특별시", "강남구", 11680),
GANGNAM("서울특별시", "강남구", 11680),
SONGPA("서울특별시", "송파구", 11710),
KANGDONG("서울특별시", "강동구", 11740),
GANGDONG("서울특별시", "강동구", 11740),
BUNDANG("경기도 성남시", "분당구", 41135);

private final String depth1;
Expand All @@ -50,9 +50,9 @@ public static Region getByAreaCode(int areaCode) {

public static List<Region> getDefaultDensityRank() {
return List.of(
JONGRO, JUNG, YONGSAN, SEONGDONG, KWANGJIN, DONGDAEMUN, JUNGRANG, SEONGBUK, KANGBUK,
DOBONG, NOWON, EUNPYEONG, SEODAEMUN, MAPO, YANGCHUN, KANGSEO, GURO, GEUMCHUN,
YOUNGDEUNGPO, DONGJAK, KWANAK, SEOCHO, KANGNAM, SONGPA, KANGDONG
JONGNO, JUNG, YONGSAN, SEONGDONG, GWANGJIN, DONGDAEMUN, JUNGNANG, SEONGBUK, GANGBUK,
DOBONG, NOWON, EUNPYEONG, SEODAEMUN, MAPO, YANGCHEON, GANGSEO, GURO, GEUMCHEON,
YOUNGDEUNGPO, DONGJAK, GWANAK, SEOCHO, GANGNAM, SONGPA, GANGDONG
);
}

Expand Down
Loading
Loading