From 271e50d13bf438dcf113ebb4df112afc64c60983 Mon Sep 17 00:00:00 2001 From: LeeJaehyung <540900@naver.com> Date: Tue, 10 Sep 2024 21:07:31 +0900 Subject: [PATCH 01/13] =?UTF-8?q?Feat:=20#156=20=EC=98=A4=ED=94=88?= =?UTF-8?q?=EC=B1=84=ED=8C=85=EB=B0=A9=20=EC=A0=95=EB=B3=B4=20=EC=A1=B0?= =?UTF-8?q?=ED=9A=8C(for=20user)=20API=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../genti/openchat/api/UserOpenChatApi.java | 20 ++++++ .../controller/UserOpenChatController.java | 29 +++++++++ .../dto/response/OpenChatInfoResponseDto.java | 29 +++++++++ .../openchat/service/OpenChatService.java | 65 +++++++++++++++++++ .../gt/genti/constants/ErrorConstants.java | 1 + .../java/com/gt/genti/error/ResponseCode.java | 1 + .../converter/OpenChatTypeConverter.java | 13 ++++ .../com/gt/genti/openchat/model/OpenChat.java | 26 ++++++++ .../gt/genti/openchat/model/OpenChatType.java | 28 ++++++++ .../repository/OpenChatRepository.java | 9 +++ 10 files changed, 221 insertions(+) create mode 100644 genti-api/src/main/java/com/gt/genti/openchat/api/UserOpenChatApi.java create mode 100644 genti-api/src/main/java/com/gt/genti/openchat/controller/UserOpenChatController.java create mode 100644 genti-api/src/main/java/com/gt/genti/openchat/dto/response/OpenChatInfoResponseDto.java create mode 100644 genti-api/src/main/java/com/gt/genti/openchat/service/OpenChatService.java create mode 100644 genti-domain/src/main/java/com/gt/genti/common/converter/OpenChatTypeConverter.java create mode 100644 genti-domain/src/main/java/com/gt/genti/openchat/model/OpenChat.java create mode 100644 genti-domain/src/main/java/com/gt/genti/openchat/model/OpenChatType.java create mode 100644 genti-domain/src/main/java/com/gt/genti/openchat/repository/OpenChatRepository.java diff --git a/genti-api/src/main/java/com/gt/genti/openchat/api/UserOpenChatApi.java b/genti-api/src/main/java/com/gt/genti/openchat/api/UserOpenChatApi.java new file mode 100644 index 0000000..d898c88 --- /dev/null +++ b/genti-api/src/main/java/com/gt/genti/openchat/api/UserOpenChatApi.java @@ -0,0 +1,20 @@ +package com.gt.genti.openchat.api; + +import com.gt.genti.openchat.dto.response.OpenChatInfoResponseDto; +import com.gt.genti.response.GentiResponse.ApiResult; +import com.gt.genti.swagger.AuthorizedUser; +import com.gt.genti.user.model.AuthUser; +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.tags.Tag; +import org.springframework.http.ResponseEntity; + +@AuthorizedUser +@Tag(name = "[UserOpenChatController] 유저의 오픈채팅방 요청", description = "카카오톡 오픈채팅방 정보 요청") +public interface UserOpenChatApi { + + @Operation(summary = "오픈채팅방 정보 조회", description = "오픈채팅방 url과 인원 수를 조회합니다.") + ResponseEntity> getOpenChatUrl( + @AuthUser Long userId + ); + +} diff --git a/genti-api/src/main/java/com/gt/genti/openchat/controller/UserOpenChatController.java b/genti-api/src/main/java/com/gt/genti/openchat/controller/UserOpenChatController.java new file mode 100644 index 0000000..df1c34f --- /dev/null +++ b/genti-api/src/main/java/com/gt/genti/openchat/controller/UserOpenChatController.java @@ -0,0 +1,29 @@ +package com.gt.genti.openchat.controller; + +import com.gt.genti.openchat.api.UserOpenChatApi; +import com.gt.genti.openchat.dto.response.OpenChatInfoResponseDto; +import com.gt.genti.openchat.service.OpenChatService; +import com.gt.genti.response.GentiResponse; +import com.gt.genti.response.GentiResponse.ApiResult; +import com.gt.genti.user.model.AuthUser; +import lombok.RequiredArgsConstructor; +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; + +@RestController +@RequestMapping("/api/v1/open-chat") +@RequiredArgsConstructor +public class UserOpenChatController implements UserOpenChatApi { + + private final OpenChatService openChatService; + + @GetMapping + public ResponseEntity> getOpenChatUrl( + @AuthUser Long userId + ) { + return GentiResponse.success(openChatService.getOpenChatUrl(userId)); + } + +} diff --git a/genti-api/src/main/java/com/gt/genti/openchat/dto/response/OpenChatInfoResponseDto.java b/genti-api/src/main/java/com/gt/genti/openchat/dto/response/OpenChatInfoResponseDto.java new file mode 100644 index 0000000..5243f4a --- /dev/null +++ b/genti-api/src/main/java/com/gt/genti/openchat/dto/response/OpenChatInfoResponseDto.java @@ -0,0 +1,29 @@ +package com.gt.genti.openchat.dto.response; + +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.AccessLevel; +import lombok.Builder; +import lombok.Getter; +import lombok.NoArgsConstructor; + +@Schema(name = "[OpenChat][User] 오픈채팅방 정보 응답 dto") +@Getter +@NoArgsConstructor(access = AccessLevel.PROTECTED) +public class OpenChatInfoResponseDto { + + @Schema(description = "오픈 채팅방 대상 여부", example = "true") + Boolean accessible; + + @Schema(description = "오픈 채팅방 사람 수") + Long count; + + @Schema(description = "오픈 채팅방 url") + String url; + + @Builder + public OpenChatInfoResponseDto(Boolean accessible, Long count, String url) { + this.accessible = accessible; + this.count = count; + this.url = url; + } +} diff --git a/genti-api/src/main/java/com/gt/genti/openchat/service/OpenChatService.java b/genti-api/src/main/java/com/gt/genti/openchat/service/OpenChatService.java new file mode 100644 index 0000000..08eda6e --- /dev/null +++ b/genti-api/src/main/java/com/gt/genti/openchat/service/OpenChatService.java @@ -0,0 +1,65 @@ +package com.gt.genti.openchat.service; + +import com.gt.genti.error.ExpectedException; +import com.gt.genti.error.ResponseCode; +import com.gt.genti.openchat.dto.response.OpenChatInfoResponseDto; +import com.gt.genti.openchat.model.OpenChat; +import com.gt.genti.openchat.model.OpenChatType; +import com.gt.genti.openchat.repository.OpenChatRepository; +import com.gt.genti.user.model.User; +import com.gt.genti.user.repository.UserRepository; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Service; + +import static com.gt.genti.openchat.model.OpenChatType.*; + +@Service +@RequiredArgsConstructor +public class OpenChatService { + private final OpenChatRepository openChatRepository; + private final UserRepository userRepository; + + public OpenChatInfoResponseDto getOpenChatUrl(Long userId){ + User foundUser = getUserById(userId); + int userBirthYear = parseBirthYear(foundUser.getBirthYear()); + OpenChatType openChatType = getOpenChatType(userBirthYear); + + if(openChatType == YB || openChatType == OB) { + OpenChat openChat = openChatRepository.findByType(openChatType); + return OpenChatInfoResponseDto.builder() + .accessible(true) + .url(openChat.getUrl()) + .count(openChat.getCount()) + .build(); + } else { + return OpenChatInfoResponseDto.builder() + .accessible(false) + .url(null) + .count(null) + .build(); + } + } + + private User getUserById(Long userId) { + return userRepository.findById(userId) + .orElseThrow(() -> ExpectedException.withLogging(ResponseCode.UserNotFound, userId)); + } + + private int parseBirthYear(String birthYear) { + try { + return Integer.parseInt(birthYear); + } catch (NumberFormatException e) { + throw ExpectedException.withLogging(ResponseCode.InvalidBirthYearFormat, birthYear); + } + } + + private OpenChatType getOpenChatType(int userBirthYear) { + if (userBirthYear >= 2001) { + return YB; + } else if (userBirthYear <= 1974) { + return OB; + } else { + return NONE; + } + } +} diff --git a/genti-common/src/main/java/com/gt/genti/constants/ErrorConstants.java b/genti-common/src/main/java/com/gt/genti/constants/ErrorConstants.java index fc8074e..af11a21 100644 --- a/genti-common/src/main/java/com/gt/genti/constants/ErrorConstants.java +++ b/genti-common/src/main/java/com/gt/genti/constants/ErrorConstants.java @@ -68,6 +68,7 @@ private static String CODE(String type, int seq) { public static final String WithDrawnUser = CODE(USER, 5); public static final String UserNotLoggedIn = CODE(USER, 6); public static final String UserAlreadySignedUp = CODE(USER, 7); + public static final String InvalidBirthYearFormat = CODE(USER, 8); public static final String CreatorNotFound = CODE(CREATOR, 1); diff --git a/genti-common/src/main/java/com/gt/genti/error/ResponseCode.java b/genti-common/src/main/java/com/gt/genti/error/ResponseCode.java index b7c2ac2..b19ac42 100644 --- a/genti-common/src/main/java/com/gt/genti/error/ResponseCode.java +++ b/genti-common/src/main/java/com/gt/genti/error/ResponseCode.java @@ -131,6 +131,7 @@ public enum ResponseCode { UserNotFoundByEmail(ErrorConstants.UserNotFound, HttpStatus.NOT_FOUND, false, "존재하지 않는 사용자입니다. 찾은 email: [%s]"), UserDeactivated(ErrorConstants.UserDeactivated, HttpStatus.BAD_REQUEST, false, "비활성화된 계정입니다."), UserAlreadySignedUp(ErrorConstants.UserAlreadySignedUp, HttpStatus.BAD_REQUEST, false, "이미 회원가입 처리가 완료된 유저입니다."), + InvalidBirthYearFormat(ErrorConstants.InvalidBirthYearFormat, BAD_REQUEST, false, "올바르지 않은 생년 형식입니다."), /** * Creator diff --git a/genti-domain/src/main/java/com/gt/genti/common/converter/OpenChatTypeConverter.java b/genti-domain/src/main/java/com/gt/genti/common/converter/OpenChatTypeConverter.java new file mode 100644 index 0000000..507835b --- /dev/null +++ b/genti-domain/src/main/java/com/gt/genti/common/converter/OpenChatTypeConverter.java @@ -0,0 +1,13 @@ +package com.gt.genti.common.converter; + +import com.gt.genti.openchat.model.OpenChatType; +import jakarta.persistence.Converter; + +@Converter +public class OpenChatTypeConverter extends DefaultEnumDBConverter { + + public OpenChatTypeConverter() { + super(OpenChatType.class); + } + +} \ No newline at end of file diff --git a/genti-domain/src/main/java/com/gt/genti/openchat/model/OpenChat.java b/genti-domain/src/main/java/com/gt/genti/openchat/model/OpenChat.java new file mode 100644 index 0000000..47e4b61 --- /dev/null +++ b/genti-domain/src/main/java/com/gt/genti/openchat/model/OpenChat.java @@ -0,0 +1,26 @@ +package com.gt.genti.openchat.model; + +import com.gt.genti.common.converter.OpenChatTypeConverter; +import jakarta.persistence.Convert; +import jakarta.persistence.Entity; +import jakarta.persistence.Id; +import jakarta.persistence.Table; +import lombok.AccessLevel; +import lombok.Getter; +import lombok.NoArgsConstructor; + +@Table(name = "openchat") +@Entity +@Getter +@NoArgsConstructor(access = AccessLevel.PROTECTED) +public class OpenChat { + + @Id + @Convert(converter = OpenChatTypeConverter.class) + private OpenChatType type; + + private Long count; + + private String url; + +} diff --git a/genti-domain/src/main/java/com/gt/genti/openchat/model/OpenChatType.java b/genti-domain/src/main/java/com/gt/genti/openchat/model/OpenChatType.java new file mode 100644 index 0000000..2aa6e45 --- /dev/null +++ b/genti-domain/src/main/java/com/gt/genti/openchat/model/OpenChatType.java @@ -0,0 +1,28 @@ +package com.gt.genti.openchat.model; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.gt.genti.common.ConvertableEnum; +import com.gt.genti.common.EnumUtil; +import lombok.Getter; +import lombok.RequiredArgsConstructor; + +@Getter +@RequiredArgsConstructor +public enum OpenChatType implements ConvertableEnum { + OB("OB", "어린층"), + YB("YB", "중년층"), + NONE("NONE", "해당안됨"); + + private final String stringValue; + private final String response; + + @JsonCreator + public static OpenChatType fromString(String value) { + return EnumUtil.stringToEnum(OpenChatType.class, value); + } + + @Override + public & ConvertableEnum> E getNullValue() { + return null; + } +} diff --git a/genti-domain/src/main/java/com/gt/genti/openchat/repository/OpenChatRepository.java b/genti-domain/src/main/java/com/gt/genti/openchat/repository/OpenChatRepository.java new file mode 100644 index 0000000..582b089 --- /dev/null +++ b/genti-domain/src/main/java/com/gt/genti/openchat/repository/OpenChatRepository.java @@ -0,0 +1,9 @@ +package com.gt.genti.openchat.repository; + +import com.gt.genti.openchat.model.OpenChat; +import com.gt.genti.openchat.model.OpenChatType; +import org.springframework.data.jpa.repository.JpaRepository; + +public interface OpenChatRepository extends JpaRepository { + OpenChat findByType(OpenChatType type); +} From ad1d1edbaf88eb7bcf3281f22ea7c625e18cdde9 Mon Sep 17 00:00:00 2001 From: LeeJaehyung <540900@naver.com> Date: Tue, 10 Sep 2024 22:34:03 +0900 Subject: [PATCH 02/13] =?UTF-8?q?Feat:=20#156=20=EC=98=A4=ED=94=88?= =?UTF-8?q?=EC=B1=84=ED=8C=85=EB=B0=A9=20=EC=A0=95=EB=B3=B4=20=EC=88=98?= =?UTF-8?q?=EC=A0=95(for=20admin)=20API=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../genti/openchat/api/AdminOpenChatApi.java | 26 ++++++++++++++ .../controller/AdminOpenChatController.java | 36 +++++++++++++++++++ .../openchat/service/OpenChatService.java | 22 ++++++++++++ .../gt/genti/constants/ErrorConstants.java | 3 ++ .../java/com/gt/genti/error/ResponseCode.java | 8 ++++- .../com/gt/genti/openchat/model/OpenChat.java | 18 +++++++--- 6 files changed, 108 insertions(+), 5 deletions(-) create mode 100644 genti-api/src/main/java/com/gt/genti/openchat/api/AdminOpenChatApi.java create mode 100644 genti-api/src/main/java/com/gt/genti/openchat/controller/AdminOpenChatController.java diff --git a/genti-api/src/main/java/com/gt/genti/openchat/api/AdminOpenChatApi.java b/genti-api/src/main/java/com/gt/genti/openchat/api/AdminOpenChatApi.java new file mode 100644 index 0000000..de12845 --- /dev/null +++ b/genti-api/src/main/java/com/gt/genti/openchat/api/AdminOpenChatApi.java @@ -0,0 +1,26 @@ +package com.gt.genti.openchat.api; + +import com.gt.genti.openchat.model.OpenChat; +import com.gt.genti.openchat.model.OpenChatType; +import com.gt.genti.response.GentiResponse.ApiResult; +import com.gt.genti.swagger.AuthorizedAdmin; +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.tags.Tag; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.RequestHeader; +import org.springframework.web.bind.annotation.RequestParam; + +@AuthorizedAdmin +@Tag(name = "[AdminOpenChatController] 어드민의 오픈채팅방 정보 수정", description = "카카오톡 오픈채팅방 정보 수정") +public interface AdminOpenChatApi { + + @Operation(summary = "오픈채팅방 정보 수정", description = "오픈채팅방 url 및 인원 수를 수정합니다.") + ResponseEntity> modifyOpenChatInfo( + @RequestHeader(value = "Open-Chat-Secret-Key") String secretKey, + @PathVariable(value = "type") OpenChatType type, + @RequestParam(required = false) Long count, + @RequestParam(required = false) String url + ); + +} diff --git a/genti-api/src/main/java/com/gt/genti/openchat/controller/AdminOpenChatController.java b/genti-api/src/main/java/com/gt/genti/openchat/controller/AdminOpenChatController.java new file mode 100644 index 0000000..9ab84e6 --- /dev/null +++ b/genti-api/src/main/java/com/gt/genti/openchat/controller/AdminOpenChatController.java @@ -0,0 +1,36 @@ +package com.gt.genti.openchat.controller; + +import com.gt.genti.error.ExpectedException; +import com.gt.genti.error.ResponseCode; +import com.gt.genti.openchat.api.AdminOpenChatApi; +import com.gt.genti.openchat.model.OpenChat; +import com.gt.genti.openchat.model.OpenChatType; +import com.gt.genti.openchat.service.OpenChatService; +import com.gt.genti.response.GentiResponse; +import com.gt.genti.response.GentiResponse.ApiResult; +import lombok.RequiredArgsConstructor; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.*; + +@RestController +@RequestMapping("/api/v1/open-chat") +@RequiredArgsConstructor +public class AdminOpenChatController implements AdminOpenChatApi { + + private final OpenChatService openChatService; + private final String API_KEY = "임시-프로퍼티파일로옮길예정입니다"; + + @PatchMapping("/{type}") + public ResponseEntity> modifyOpenChatInfo( + @RequestHeader(value = "Open-Chat-Secret-Key") String secretKey, + @PathVariable(value = "type") OpenChatType type, + @RequestParam(required = false) Long count, + @RequestParam(required = false) String url + ){ + if (!API_KEY.equals(secretKey)) { + throw ExpectedException.withLogging(ResponseCode.InvalidOpenChatSecretKey); + } else{ + return GentiResponse.success(openChatService.modifyOpenChatInfo(type, count, url)); + } + } +} diff --git a/genti-api/src/main/java/com/gt/genti/openchat/service/OpenChatService.java b/genti-api/src/main/java/com/gt/genti/openchat/service/OpenChatService.java index 08eda6e..728964d 100644 --- a/genti-api/src/main/java/com/gt/genti/openchat/service/OpenChatService.java +++ b/genti-api/src/main/java/com/gt/genti/openchat/service/OpenChatService.java @@ -10,10 +10,12 @@ import com.gt.genti.user.repository.UserRepository; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; import static com.gt.genti.openchat.model.OpenChatType.*; @Service +@Transactional @RequiredArgsConstructor public class OpenChatService { private final OpenChatRepository openChatRepository; @@ -40,6 +42,26 @@ public OpenChatInfoResponseDto getOpenChatUrl(Long userId){ } } + public OpenChat modifyOpenChatInfo(OpenChatType type, Long count, String url){ + OpenChat openChat = openChatRepository.findByType(type); + + boolean updated = false; + if (count != null) { + openChat.updateCount(count); + updated = true; + } + if (url != null) { + openChat.updateUrl(url); + updated = true; + } + + if (updated) { + return openChatRepository.save(openChat); + } else{ + return openChat; + } + } + private User getUserById(Long userId) { return userRepository.findById(userId) .orElseThrow(() -> ExpectedException.withLogging(ResponseCode.UserNotFound, userId)); diff --git a/genti-common/src/main/java/com/gt/genti/constants/ErrorConstants.java b/genti-common/src/main/java/com/gt/genti/constants/ErrorConstants.java index af11a21..ec4d337 100644 --- a/genti-common/src/main/java/com/gt/genti/constants/ErrorConstants.java +++ b/genti-common/src/main/java/com/gt/genti/constants/ErrorConstants.java @@ -20,6 +20,7 @@ public class ErrorConstants { private static final String OAUTH = "OAUTH"; private static final String SERVER = "SERVER"; private static final String FCM = "FCM"; + private static final String OPENCHAT = "OPENCHAT"; private static String CODE(String type, int seq) { return type + String.format("-%05d", seq); @@ -115,4 +116,6 @@ private static String CODE(String type, int seq) { public static final String FCM_GOOGLE_REQUEST_TOKEN_ERROR = CODE(FCM, 3); public static final String FCM_CONNECT_ERROR = CODE(FCM, 4); + public static final String InvalidOpenChatSecretKey = CODE(OPENCHAT, 1); + } diff --git a/genti-common/src/main/java/com/gt/genti/error/ResponseCode.java b/genti-common/src/main/java/com/gt/genti/error/ResponseCode.java index b19ac42..69abe4e 100644 --- a/genti-common/src/main/java/com/gt/genti/error/ResponseCode.java +++ b/genti-common/src/main/java/com/gt/genti/error/ResponseCode.java @@ -208,7 +208,13 @@ public enum ResponseCode { FCM_GOOGLE_REQUEST_TOKEN_ERROR(ErrorConstants.FCM_GOOGLE_REQUEST_TOKEN_ERROR, INTERNAL_SERVER_ERROR, false, "파이어베이스 서버 접속 전 구글 통신 오류"), FCM_CONNECT_ERROR(ErrorConstants.FCM_CONNECT_ERROR, INTERNAL_SERVER_ERROR, false, - "파이어베이스 서버 통신 오류 : %s"); + "파이어베이스 서버 통신 오류 : %s"), + + /** + * OpenChat + */ + + InvalidOpenChatSecretKey(ErrorConstants.InvalidOpenChatSecretKey, BAD_REQUEST, false, "유효하지 않은 시크릿 키입니다."); private final String errorCode; private final HttpStatusCode httpStatusCode; diff --git a/genti-domain/src/main/java/com/gt/genti/openchat/model/OpenChat.java b/genti-domain/src/main/java/com/gt/genti/openchat/model/OpenChat.java index 47e4b61..5877495 100644 --- a/genti-domain/src/main/java/com/gt/genti/openchat/model/OpenChat.java +++ b/genti-domain/src/main/java/com/gt/genti/openchat/model/OpenChat.java @@ -1,11 +1,9 @@ package com.gt.genti.openchat.model; import com.gt.genti.common.converter.OpenChatTypeConverter; -import jakarta.persistence.Convert; -import jakarta.persistence.Entity; -import jakarta.persistence.Id; -import jakarta.persistence.Table; +import jakarta.persistence.*; import lombok.AccessLevel; +import lombok.Builder; import lombok.Getter; import lombok.NoArgsConstructor; @@ -23,4 +21,16 @@ public class OpenChat { private String url; + @Builder + public OpenChat(OpenChatType type, Long count, String url) { + this.type = type; + this.count = count; + this.url = url; + } + + public void updateCount(Long count) { + this.count = count; + } + public void updateUrl(String url) { this.url = url; } + } From 6a44e51ee942a33d76ea39218d3e58b628818cfe Mon Sep 17 00:00:00 2001 From: LeeJaehyung <540900@naver.com> Date: Wed, 11 Sep 2024 21:19:57 +0900 Subject: [PATCH 03/13] =?UTF-8?q?Fix:=20#156=20=EC=8B=9C=ED=81=AC=EB=A6=BF?= =?UTF-8?q?=ED=82=A4=20header=EB=AA=85=20=EB=B3=80=EA=B2=BD,=20url=20?= =?UTF-8?q?=EC=88=98=EC=A0=95=20=EB=A1=9C=EC=A7=81=20=EC=82=AD=EC=A0=9C,?= =?UTF-8?q?=20security=20=EA=B4=80=EB=A0=A8=20=EC=88=98=EC=A0=95,=20?= =?UTF-8?q?=EC=83=9D=EB=85=84=20=EC=98=88=EC=99=B8=20=EB=A1=9C=EC=A7=81=20?= =?UTF-8?q?=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../genti/openchat/api/AdminOpenChatApi.java | 7 ++--- .../controller/AdminOpenChatController.java | 7 ++--- .../openchat/service/OpenChatService.java | 30 ++++++++----------- .../com/gt/genti/config/SecurityConfig.java | 2 +- .../gt/genti/constants/ErrorConstants.java | 1 + .../genti/constants/WhiteListConstants.java | 6 ++-- .../java/com/gt/genti/error/ResponseCode.java | 4 ++- 7 files changed, 27 insertions(+), 30 deletions(-) diff --git a/genti-api/src/main/java/com/gt/genti/openchat/api/AdminOpenChatApi.java b/genti-api/src/main/java/com/gt/genti/openchat/api/AdminOpenChatApi.java index de12845..ca142e7 100644 --- a/genti-api/src/main/java/com/gt/genti/openchat/api/AdminOpenChatApi.java +++ b/genti-api/src/main/java/com/gt/genti/openchat/api/AdminOpenChatApi.java @@ -15,12 +15,11 @@ @Tag(name = "[AdminOpenChatController] 어드민의 오픈채팅방 정보 수정", description = "카카오톡 오픈채팅방 정보 수정") public interface AdminOpenChatApi { - @Operation(summary = "오픈채팅방 정보 수정", description = "오픈채팅방 url 및 인원 수를 수정합니다.") + @Operation(summary = "오픈채팅방 정보 수정", description = "오픈채팅방의 인원 수를 수정합니다.") ResponseEntity> modifyOpenChatInfo( - @RequestHeader(value = "Open-Chat-Secret-Key") String secretKey, + @RequestHeader(value = "Admin-Secret-Key") String secretKey, @PathVariable(value = "type") OpenChatType type, - @RequestParam(required = false) Long count, - @RequestParam(required = false) String url + @RequestParam(value = "count") Long count ); } diff --git a/genti-api/src/main/java/com/gt/genti/openchat/controller/AdminOpenChatController.java b/genti-api/src/main/java/com/gt/genti/openchat/controller/AdminOpenChatController.java index 9ab84e6..1fe3a92 100644 --- a/genti-api/src/main/java/com/gt/genti/openchat/controller/AdminOpenChatController.java +++ b/genti-api/src/main/java/com/gt/genti/openchat/controller/AdminOpenChatController.java @@ -22,15 +22,14 @@ public class AdminOpenChatController implements AdminOpenChatApi { @PatchMapping("/{type}") public ResponseEntity> modifyOpenChatInfo( - @RequestHeader(value = "Open-Chat-Secret-Key") String secretKey, + @RequestHeader(value = "Admin-Secret-Key") String secretKey, @PathVariable(value = "type") OpenChatType type, - @RequestParam(required = false) Long count, - @RequestParam(required = false) String url + @RequestParam(value = "count") Long count ){ if (!API_KEY.equals(secretKey)) { throw ExpectedException.withLogging(ResponseCode.InvalidOpenChatSecretKey); } else{ - return GentiResponse.success(openChatService.modifyOpenChatInfo(type, count, url)); + return GentiResponse.success(openChatService.modifyOpenChatInfo(type, count)); } } } diff --git a/genti-api/src/main/java/com/gt/genti/openchat/service/OpenChatService.java b/genti-api/src/main/java/com/gt/genti/openchat/service/OpenChatService.java index 728964d..4de49c6 100644 --- a/genti-api/src/main/java/com/gt/genti/openchat/service/OpenChatService.java +++ b/genti-api/src/main/java/com/gt/genti/openchat/service/OpenChatService.java @@ -42,24 +42,18 @@ public OpenChatInfoResponseDto getOpenChatUrl(Long userId){ } } - public OpenChat modifyOpenChatInfo(OpenChatType type, Long count, String url){ - OpenChat openChat = openChatRepository.findByType(type); - - boolean updated = false; - if (count != null) { - openChat.updateCount(count); - updated = true; - } - if (url != null) { - openChat.updateUrl(url); - updated = true; - } + public OpenChat modifyOpenChatInfo(OpenChatType type, Long count){ + OpenChat openChat = getOpenChatInfoByType(type); + openChat.updateCount(count); + return openChatRepository.save(openChat); + } - if (updated) { - return openChatRepository.save(openChat); - } else{ - return openChat; + private OpenChat getOpenChatInfoByType(OpenChatType type){ + OpenChat openChat = openChatRepository.findByType(type); + if (openChat == null) { + throw ExpectedException.withLogging(ResponseCode.OpenChatNotFound, type); } + return openChat; } private User getUserById(Long userId) { @@ -70,8 +64,8 @@ private User getUserById(Long userId) { private int parseBirthYear(String birthYear) { try { return Integer.parseInt(birthYear); - } catch (NumberFormatException e) { - throw ExpectedException.withLogging(ResponseCode.InvalidBirthYearFormat, birthYear); + } catch (NumberFormatException | NullPointerException e) { + return 2000; } } diff --git a/genti-auth/src/main/java/com/gt/genti/config/SecurityConfig.java b/genti-auth/src/main/java/com/gt/genti/config/SecurityConfig.java index d0b881c..ce982d0 100644 --- a/genti-auth/src/main/java/com/gt/genti/config/SecurityConfig.java +++ b/genti-auth/src/main/java/com/gt/genti/config/SecurityConfig.java @@ -50,7 +50,7 @@ public CorsConfigurationSource corsConfigurationSource() { config.setAllowedMethods(List.of("GET", "POST", "PUT", "DELETE", "HEAD", "OPTIONS")); config.addExposedHeader("Access-Token"); config.addExposedHeader("Refresh-Token"); - config.setAllowedHeaders(List.of("Authorization", "Cache-Control", "Content-Type")); + config.setAllowedHeaders(List.of("Authorization", "Cache-Control", "Content-Type", "Open-Chat-Secret-Key")); config.setAllowCredentials(true); UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource(); diff --git a/genti-common/src/main/java/com/gt/genti/constants/ErrorConstants.java b/genti-common/src/main/java/com/gt/genti/constants/ErrorConstants.java index ec4d337..c62ac4a 100644 --- a/genti-common/src/main/java/com/gt/genti/constants/ErrorConstants.java +++ b/genti-common/src/main/java/com/gt/genti/constants/ErrorConstants.java @@ -117,5 +117,6 @@ private static String CODE(String type, int seq) { public static final String FCM_CONNECT_ERROR = CODE(FCM, 4); public static final String InvalidOpenChatSecretKey = CODE(OPENCHAT, 1); + public static final String OpenChatNotFound = CODE(OPENCHAT, 2); } diff --git a/genti-common/src/main/java/com/gt/genti/constants/WhiteListConstants.java b/genti-common/src/main/java/com/gt/genti/constants/WhiteListConstants.java index 1661372..54a4af6 100644 --- a/genti-common/src/main/java/com/gt/genti/constants/WhiteListConstants.java +++ b/genti-common/src/main/java/com/gt/genti/constants/WhiteListConstants.java @@ -40,7 +40,8 @@ void postConstruct() { "/api-docs/**", "/v3/api-docs/**", "/h2-console/**", - "/h2-console" + "/h2-console", + "/api/v1/open-chat/*" )); private List securityWhiteList = new ArrayList<>(List.of( @@ -56,6 +57,7 @@ void postConstruct() { "/api-docs/**", "/v3/api-docs/**", "/h2-console/**", - "/h2-console" + "/h2-console", + "/api/v1/open-chat/*" )); } diff --git a/genti-common/src/main/java/com/gt/genti/error/ResponseCode.java b/genti-common/src/main/java/com/gt/genti/error/ResponseCode.java index 69abe4e..e46d555 100644 --- a/genti-common/src/main/java/com/gt/genti/error/ResponseCode.java +++ b/genti-common/src/main/java/com/gt/genti/error/ResponseCode.java @@ -214,7 +214,9 @@ public enum ResponseCode { * OpenChat */ - InvalidOpenChatSecretKey(ErrorConstants.InvalidOpenChatSecretKey, BAD_REQUEST, false, "유효하지 않은 시크릿 키입니다."); + InvalidOpenChatSecretKey(ErrorConstants.InvalidOpenChatSecretKey, BAD_REQUEST, false, "유효하지 않은 시크릿 키입니다."), + OpenChatNotFound(ErrorConstants.OpenChatNotFound, HttpStatus.NOT_FOUND, false, "존재하지 않는 오픈채팅방입니다. 찾은 오픈채팅방 type : [%s]"); + private final String errorCode; private final HttpStatusCode httpStatusCode; From 38fc390afb29663c6a6bda40d419f56638789f76 Mon Sep 17 00:00:00 2001 From: BYEONGRYEOL Date: Thu, 12 Sep 2024 08:41:48 +0900 Subject: [PATCH 04/13] =?UTF-8?q?Update:=20#158=20=EA=B0=9C=EB=B0=9C?= =?UTF-8?q?=EC=84=9C=EB=B2=84=20private=20subnet=20=EC=9D=B4=EB=8F=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/cicd-ec2.yml | 146 +++++++++++++++++++++------------ .gitignore | 1 + 2 files changed, 93 insertions(+), 54 deletions(-) diff --git a/.github/workflows/cicd-ec2.yml b/.github/workflows/cicd-ec2.yml index 4dadd61..08e2c59 100644 --- a/.github/workflows/cicd-ec2.yml +++ b/.github/workflows/cicd-ec2.yml @@ -10,7 +10,9 @@ on: env: AWS_REGION: ap-northeast-2 S3_BUCKET_NAME: genti-deploy + S3_BUCKET_NAME_STAGING: genti-staging CODE_DEPLOY_APPLICATION_NAME: genti + CODE_DEPLOY_APPLICATION_NAME_STAGING: genti-dev permissions: contents: read @@ -105,13 +107,13 @@ jobs: run: | chmod +x ./gradlew ./gradlew clean build -x test + - - - name: Get Github action IP - if: contains(github.ref, 'staging') - id: ip - uses: haythem/public-ip@v1.2 - + # - name: Get Github action IP + # if: contains(github.ref, 'staging') + # id: ip + # uses: haythem/public-ip@v1.2 + # - name: Setting environment variables run: | echo "AWS_DEFAULT_REGION=ap-northeast-2" >> $GITHUB_ENV @@ -123,14 +125,14 @@ jobs: aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} aws-region: ap-northeast-2 - - name: Add Github Actions IP to Security group - if: contains(github.ref, 'staging') - run: | - aws ec2 authorize-security-group-ingress --group-id ${{ secrets.AWS_SG_ID }} --protocol tcp --port 22 --cidr ${{ steps.ip.outputs.ipv4 }}/32 - env: - AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }} - AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }} - AWS_DEFAULT_REGION: ap-northeast-2 + # - name: Add Github Actions IP to Security group + # if: contains(github.ref, 'staging') + # run: | + # aws ec2 authorize-security-group-ingress --group-id ${{ secrets.AWS_SG_ID }} --protocol tcp --port 22 --cidr ${{ steps.ip.outputs.ipv4 }}/32 + # env: + # AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }} + # AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }} + # AWS_DEFAULT_REGION: ap-northeast-2 - name: Login to aws ECR @@ -148,6 +150,15 @@ jobs: docker build -f ./Dockerfile_deploy -t $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG . docker push $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG + - name: Build, tag, and push image to aws ECR + if: contains(github.ref, 'staging') + env: + ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }} + ECR_REPOSITORY: genti-staging + IMAGE_TAG: latest + run: | + docker build -f ./Dockerfile_deploy -t $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG . + docker push $ECR_REGISTRY/$ECR_REPOSITORY: - name: Upload docker-compose, appspec, afterInstall file to S3 if: contains(github.ref, 'main') @@ -169,16 +180,36 @@ jobs: # Clean up the temporary directory rm -rf temp_dir - - name: Upload docker compose file to staging server + - name: Upload docker-compose, appspec, afterInstall file to S3 if: contains(github.ref, 'staging') - uses: appleboy/scp-action@master - with: - host: ${{ secrets.HOST_STAGING }} - username: ubuntu - key: ${{ secrets.EC2_KEY }} - port: 22 - source: "./docker/staging/*" - target: "/home/ubuntu/workspace/" + run: | + # Create a temporary directory for the zip contents + mkdir -p temp_dir/scripts + cp -r ./scripts/* temp_dir/scripts/ + cp appspec.yml temp_dir/ + cp ./docker/staging/docker-compose.yml temp_dir/docker-compose.yml + + # Navigate to the temporary directory and create the zip file + cd temp_dir + zip -r ../$GITHUB_SHA.zip ./* + + # Move back to the initial directory and upload the zip file to S3 + cd .. + aws s3 cp --region ap-northeast-2 ./$GITHUB_SHA.zip s3://S3_BUCKET_NAME_STAGING + + # Clean up the temporary directory + rm -rf temp_dir + + # - name: Upload docker compose file to staging server + # if: contains(github.ref, 'staging') + # uses: appleboy/scp-action@master + # with: + # host: ${{ secrets.HOST_STAGING }} + # username: ubuntu + # key: ${{ secrets.EC2_KEY }} + # port: 22 + # source: "./docker/staging/*" + # target: "/home/ubuntu/workspace/" # docker build & push to deploy server - name: Deploy to EC2 with CodeDeploy @@ -189,38 +220,45 @@ jobs: --deployment-group-name ${{ secrets.CODE_DEPLOY_DEPLOYMENT_GROUP_NAME }} \ --s3-location bucket=$S3_BUCKET_NAME,key=$GITHUB_SHA.zip,bundleType=zip - # docker build & push to staging - - name: Docker build & push to staging + - name: Staging Deploy to EC2 with CodeDeploy if: contains(github.ref, 'staging') run: | - docker login -u ${{ secrets.DOCKER_USERNAME }} -p ${{ secrets.DOCKER_PASSWORD }} - docker build -f Dockerfile_staging -t ${{ secrets.DOCKER_USERNAME }}/genti-staging . - docker push ${{ secrets.DOCKER_USERNAME }}/genti-staging + aws deploy create-deployment \ + --application-name ${{ env.CODE_DEPLOY_APPLICATION_NAME_STAGING }} \ + --deployment-group-name genti-tg-staging \ + --s3-location bucket=$S3_BUCKET_NAME,key=$GITHUB_SHA.zip,bundleType=zip + # docker build & push to staging + # - name: Docker build & push to staging + # if: contains(github.ref, 'staging') + # run: | + # docker login -u ${{ secrets.DOCKER_USERNAME }} -p ${{ secrets.DOCKER_PASSWORD }} + # docker build -f Dockerfile_staging -t ${{ secrets.DOCKER_USERNAME }}/genti-staging . + # docker push ${{ secrets.DOCKER_USERNAME }}/genti-staging ## deploy to staging server - - name: Deploy to staging server - uses: appleboy/ssh-action@master - id: deploy-staging - if: contains(github.ref, 'staging') - with: - host: ${{ secrets.HOST_STAGING }} # EC2 퍼블릭 IPv4 DNS - username: ubuntu - password: ${{ secrets.PASSWORD }} - port: 22 - key: ${{ secrets.EC2_KEY }} - script: | - sudo docker ps - cd /home/ubuntu/workspace/docker/staging - docker login -u ${{ secrets.DOCKER_USERNAME }} -p ${{ secrets.DOCKER_PASSWORD }} - sudo docker pull ${{ secrets.DOCKER_USERNAME }}/genti-staging - sudo docker-compose up -d - sudo docker image prune -f - - - name: delete github actions ip from aws security group - if: contains(github.ref, 'staging') - run: | - aws ec2 revoke-security-group-ingress --group-id ${{ secrets.AWS_SG_ID }} --protocol tcp --port 22 --cidr ${{ steps.ip.outputs.ipv4 }}/32 - env: - AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }} - AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }} - AWS_DEFAULT_REGION: ap-northeast-2 + # - name: Deploy to staging server + # uses: appleboy/ssh-action@master + # id: deploy-staging + # if: contains(github.ref, 'staging') + # with: + # host: ${{ secrets.HOST_STAGING }} # EC2 퍼블릭 IPv4 DNS + # username: ubuntu + # password: ${{ secrets.PASSWORD }} + # port: 22 + # key: ${{ secrets.EC2_KEY }} + # script: | + # sudo docker ps + # cd /home/ubuntu/workspace/docker/staging + # docker login -u ${{ secrets.DOCKER_USERNAME }} -p ${{ secrets.DOCKER_PASSWORD }} + # sudo docker pull ${{ secrets.DOCKER_USERNAME }}/genti-staging + # sudo docker-compose up -d + # sudo docker image prune -f + +# - name: delete github actions ip from aws security group +# if: contains(github.ref, 'staging') +# run: | +# aws ec2 revoke-security-group-ingress --group-id ${{ secrets.AWS_SG_ID }} --protocol tcp --port 22 --cidr ${{ steps.ip.outputs.ipv4 }}/32 +# env: +# AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }} +# AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }} +# AWS_DEFAULT_REGION: ap-northeast-2 diff --git a/.gitignore b/.gitignore index c065f73..dae41ce 100644 --- a/.gitignore +++ b/.gitignore @@ -66,3 +66,4 @@ firebase-genti.json AuthKey_ZRZMQQX883.p8 /genti-api/src/main/resources/static/swagger.json +update-github-secret.sh \ No newline at end of file From ff5a197d0eac882ad3a4f88fab83fb07cdb4ebe8 Mon Sep 17 00:00:00 2001 From: BYEONGRYEOL Date: Thu, 12 Sep 2024 08:44:47 +0900 Subject: [PATCH 05/13] =?UTF-8?q?Update:=20#158=20cicd=20=ED=8C=8C?= =?UTF-8?q?=EC=9D=B4=ED=94=84=EB=9D=BC=EC=9D=B8=20=EB=82=B4=20=EC=98=A4?= =?UTF-8?q?=ED=83=80=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/cicd-ec2.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/cicd-ec2.yml b/.github/workflows/cicd-ec2.yml index 08e2c59..cb4b29d 100644 --- a/.github/workflows/cicd-ec2.yml +++ b/.github/workflows/cicd-ec2.yml @@ -157,7 +157,7 @@ jobs: ECR_REPOSITORY: genti-staging IMAGE_TAG: latest run: | - docker build -f ./Dockerfile_deploy -t $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG . + docker build -f ./Dockerfile_staging -t $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG . docker push $ECR_REGISTRY/$ECR_REPOSITORY: - name: Upload docker-compose, appspec, afterInstall file to S3 @@ -195,7 +195,7 @@ jobs: # Move back to the initial directory and upload the zip file to S3 cd .. - aws s3 cp --region ap-northeast-2 ./$GITHUB_SHA.zip s3://S3_BUCKET_NAME_STAGING + aws s3 cp --region ap-northeast-2 ./$GITHUB_SHA.zip s3://$S3_BUCKET_NAME_STAGING # Clean up the temporary directory rm -rf temp_dir From ae0663e6a1f23adc34fccecf8c29d83ceb9aeade Mon Sep 17 00:00:00 2001 From: BYEONGRYEOL Date: Thu, 12 Sep 2024 08:53:26 +0900 Subject: [PATCH 06/13] =?UTF-8?q?Update:=20#158=20login-ecr=20staging?= =?UTF-8?q?=EC=97=90=EB=8F=84=20=EB=B0=98=EC=98=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/cicd-ec2.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/cicd-ec2.yml b/.github/workflows/cicd-ec2.yml index cb4b29d..5888e1c 100644 --- a/.github/workflows/cicd-ec2.yml +++ b/.github/workflows/cicd-ec2.yml @@ -136,7 +136,7 @@ jobs: - name: Login to aws ECR - if: contains(github.ref, 'main') + if: contains(github.ref, 'staging') || contains(github.ref, 'main') id: login-ecr uses: aws-actions/amazon-ecr-login@v1 From 84a66e36dc97c574dd568d6f276198e6bbc10ef6 Mon Sep 17 00:00:00 2001 From: LeeJaehyung <540900@naver.com> Date: Thu, 12 Sep 2024 17:07:55 +0900 Subject: [PATCH 07/13] =?UTF-8?q?Fix:=20#156=20=EC=83=9D=EB=85=84=20?= =?UTF-8?q?=EC=88=AB=EC=9E=90=20=EB=B3=80=ED=99=98=20=EB=A1=9C=EC=A7=81=20?= =?UTF-8?q?=EC=88=98=EC=A0=95,=20SecurityConfig=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../openchat/service/OpenChatService.java | 29 +++++++++---------- .../com/gt/genti/config/SecurityConfig.java | 2 +- 2 files changed, 15 insertions(+), 16 deletions(-) diff --git a/genti-api/src/main/java/com/gt/genti/openchat/service/OpenChatService.java b/genti-api/src/main/java/com/gt/genti/openchat/service/OpenChatService.java index 4de49c6..cbe9d31 100644 --- a/genti-api/src/main/java/com/gt/genti/openchat/service/OpenChatService.java +++ b/genti-api/src/main/java/com/gt/genti/openchat/service/OpenChatService.java @@ -9,6 +9,7 @@ import com.gt.genti.user.model.User; import com.gt.genti.user.repository.UserRepository; import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -17,14 +18,14 @@ @Service @Transactional @RequiredArgsConstructor +@Slf4j public class OpenChatService { private final OpenChatRepository openChatRepository; private final UserRepository userRepository; public OpenChatInfoResponseDto getOpenChatUrl(Long userId){ User foundUser = getUserById(userId); - int userBirthYear = parseBirthYear(foundUser.getBirthYear()); - OpenChatType openChatType = getOpenChatType(userBirthYear); + OpenChatType openChatType = getOpenChatType(foundUser); if(openChatType == YB || openChatType == OB) { OpenChat openChat = openChatRepository.findByType(openChatType); @@ -61,20 +62,18 @@ private User getUserById(Long userId) { .orElseThrow(() -> ExpectedException.withLogging(ResponseCode.UserNotFound, userId)); } - private int parseBirthYear(String birthYear) { - try { - return Integer.parseInt(birthYear); + private OpenChatType getOpenChatType(User user) { + try{ + int userBirthYear = Integer.parseInt(user.getBirthYear()); + if (userBirthYear >= 2001) { + return YB; + } else if (userBirthYear <= 1974) { + return OB; + } else { + return NONE; + } } catch (NumberFormatException | NullPointerException e) { - return 2000; - } - } - - private OpenChatType getOpenChatType(int userBirthYear) { - if (userBirthYear >= 2001) { - return YB; - } else if (userBirthYear <= 1974) { - return OB; - } else { + log.info("사용자 생년의 숫자 변환 시 문제가 발생했습니다.", e); return NONE; } } diff --git a/genti-auth/src/main/java/com/gt/genti/config/SecurityConfig.java b/genti-auth/src/main/java/com/gt/genti/config/SecurityConfig.java index ce982d0..84b7b1f 100644 --- a/genti-auth/src/main/java/com/gt/genti/config/SecurityConfig.java +++ b/genti-auth/src/main/java/com/gt/genti/config/SecurityConfig.java @@ -50,7 +50,7 @@ public CorsConfigurationSource corsConfigurationSource() { config.setAllowedMethods(List.of("GET", "POST", "PUT", "DELETE", "HEAD", "OPTIONS")); config.addExposedHeader("Access-Token"); config.addExposedHeader("Refresh-Token"); - config.setAllowedHeaders(List.of("Authorization", "Cache-Control", "Content-Type", "Open-Chat-Secret-Key")); + config.setAllowedHeaders(List.of("Authorization", "Cache-Control", "Content-Type", "Admin-Secret-Key")); config.setAllowCredentials(true); UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource(); From d06a9b507d8a3670e086b2177df59974b1cc667e Mon Sep 17 00:00:00 2001 From: LeeJaehyung <540900@naver.com> Date: Thu, 12 Sep 2024 20:31:19 +0900 Subject: [PATCH 08/13] =?UTF-8?q?Fix:=20#156=20OpenChatType=EC=97=90?= =?UTF-8?q?=EC=84=9C=20NONE=20=EA=B0=9D=EC=B2=B4=20=EC=82=AD=EC=A0=9C,=20?= =?UTF-8?q?=EC=8B=9C=ED=81=AC=EB=A6=BF=ED=82=A4=20@Value=20=EC=82=AC?= =?UTF-8?q?=EC=9A=A9,=20=EC=96=B4=EB=93=9C=EB=AF=BC=EC=BB=A8=ED=8A=B8?= =?UTF-8?q?=EB=A1=A4=EB=9F=AC=20=EA=B8=B0=ED=83=80=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../gt/genti/openchat/api/AdminOpenChatApi.java | 2 +- .../controller/AdminOpenChatController.java | 14 +++++++++----- .../gt/genti/openchat/service/OpenChatService.java | 6 +++--- genti-api/src/main/resources/application.yaml | 5 ++++- genti-api/src/main/resources/file-appender.xml | 2 +- .../java/com/gt/genti/openchat/model/OpenChat.java | 6 ++++-- .../com/gt/genti/openchat/model/OpenChatType.java | 3 +-- 7 files changed, 23 insertions(+), 15 deletions(-) diff --git a/genti-api/src/main/java/com/gt/genti/openchat/api/AdminOpenChatApi.java b/genti-api/src/main/java/com/gt/genti/openchat/api/AdminOpenChatApi.java index ca142e7..3f7912d 100644 --- a/genti-api/src/main/java/com/gt/genti/openchat/api/AdminOpenChatApi.java +++ b/genti-api/src/main/java/com/gt/genti/openchat/api/AdminOpenChatApi.java @@ -18,7 +18,7 @@ public interface AdminOpenChatApi { @Operation(summary = "오픈채팅방 정보 수정", description = "오픈채팅방의 인원 수를 수정합니다.") ResponseEntity> modifyOpenChatInfo( @RequestHeader(value = "Admin-Secret-Key") String secretKey, - @PathVariable(value = "type") OpenChatType type, + @PathVariable(value = "type") String type, @RequestParam(value = "count") Long count ); diff --git a/genti-api/src/main/java/com/gt/genti/openchat/controller/AdminOpenChatController.java b/genti-api/src/main/java/com/gt/genti/openchat/controller/AdminOpenChatController.java index 1fe3a92..2663e58 100644 --- a/genti-api/src/main/java/com/gt/genti/openchat/controller/AdminOpenChatController.java +++ b/genti-api/src/main/java/com/gt/genti/openchat/controller/AdminOpenChatController.java @@ -9,6 +9,7 @@ import com.gt.genti.response.GentiResponse; import com.gt.genti.response.GentiResponse.ApiResult; import lombok.RequiredArgsConstructor; +import org.springframework.beans.factory.annotation.Value; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.*; @@ -18,18 +19,21 @@ public class AdminOpenChatController implements AdminOpenChatApi { private final OpenChatService openChatService; - private final String API_KEY = "임시-프로퍼티파일로옮길예정입니다"; + + @Value("${openchat.admin-secret-key}") + private String ADMIN_SECRET_KEY; @PatchMapping("/{type}") public ResponseEntity> modifyOpenChatInfo( - @RequestHeader(value = "Admin-Secret-Key") String secretKey, - @PathVariable(value = "type") OpenChatType type, + @RequestHeader(value = "Admin-Secret-Key") String adminSecretKey, + @PathVariable(value = "type") String type, @RequestParam(value = "count") Long count ){ - if (!API_KEY.equals(secretKey)) { + OpenChatType openChatType = OpenChatType.fromString(type); + if (!ADMIN_SECRET_KEY.equals(adminSecretKey)) { throw ExpectedException.withLogging(ResponseCode.InvalidOpenChatSecretKey); } else{ - return GentiResponse.success(openChatService.modifyOpenChatInfo(type, count)); + return GentiResponse.success(openChatService.modifyOpenChatInfo(openChatType, count)); } } } diff --git a/genti-api/src/main/java/com/gt/genti/openchat/service/OpenChatService.java b/genti-api/src/main/java/com/gt/genti/openchat/service/OpenChatService.java index cbe9d31..9dfb57a 100644 --- a/genti-api/src/main/java/com/gt/genti/openchat/service/OpenChatService.java +++ b/genti-api/src/main/java/com/gt/genti/openchat/service/OpenChatService.java @@ -70,11 +70,11 @@ private OpenChatType getOpenChatType(User user) { } else if (userBirthYear <= 1974) { return OB; } else { - return NONE; + return null; } } catch (NumberFormatException | NullPointerException e) { - log.info("사용자 생년의 숫자 변환 시 문제가 발생했습니다.", e); - return NONE; + log.info("사용자 생년의 숫자 변환 시 문제가 발생 : {}", e.getMessage(), e); + return null; } } } diff --git a/genti-api/src/main/resources/application.yaml b/genti-api/src/main/resources/application.yaml index c51f440..807f998 100644 --- a/genti-api/src/main/resources/application.yaml +++ b/genti-api/src/main/resources/application.yaml @@ -8,4 +8,7 @@ spring: include: - secret - common - active: local \ No newline at end of file + active: local + +openchat: + admin-secret-key: "4b8a15e3-8c4a-42e0-9c5b-9a4d72f1c934" \ No newline at end of file diff --git a/genti-api/src/main/resources/file-appender.xml b/genti-api/src/main/resources/file-appender.xml index 6d2f1f4..fec722d 100644 --- a/genti-api/src/main/resources/file-appender.xml +++ b/genti-api/src/main/resources/file-appender.xml @@ -1,6 +1,6 @@ - /logs/genti-%d{yyyy-MM-dd}.log + logs/genti-%d{yyyy-MM-dd}.log 90 diff --git a/genti-domain/src/main/java/com/gt/genti/openchat/model/OpenChat.java b/genti-domain/src/main/java/com/gt/genti/openchat/model/OpenChat.java index 5877495..8b1cb92 100644 --- a/genti-domain/src/main/java/com/gt/genti/openchat/model/OpenChat.java +++ b/genti-domain/src/main/java/com/gt/genti/openchat/model/OpenChat.java @@ -14,11 +14,14 @@ public class OpenChat { @Id - @Convert(converter = OpenChatTypeConverter.class) + @Column(name = "type", length = 2) + @Enumerated(EnumType.STRING) private OpenChatType type; + @Column(name = "count") private Long count; + @Column(name = "url") private String url; @Builder @@ -31,6 +34,5 @@ public OpenChat(OpenChatType type, Long count, String url) { public void updateCount(Long count) { this.count = count; } - public void updateUrl(String url) { this.url = url; } } diff --git a/genti-domain/src/main/java/com/gt/genti/openchat/model/OpenChatType.java b/genti-domain/src/main/java/com/gt/genti/openchat/model/OpenChatType.java index 2aa6e45..7007f2d 100644 --- a/genti-domain/src/main/java/com/gt/genti/openchat/model/OpenChatType.java +++ b/genti-domain/src/main/java/com/gt/genti/openchat/model/OpenChatType.java @@ -10,8 +10,7 @@ @RequiredArgsConstructor public enum OpenChatType implements ConvertableEnum { OB("OB", "어린층"), - YB("YB", "중년층"), - NONE("NONE", "해당안됨"); + YB("YB", "중년층"); private final String stringValue; private final String response; From b4962d1e2a61e35190c7bb80fa98444dd1fcf011 Mon Sep 17 00:00:00 2001 From: BYEONGRYEOL Date: Thu, 12 Sep 2024 22:47:09 +0900 Subject: [PATCH 09/13] =?UTF-8?q?Update:=20#158=20cicd=20=ED=8C=8C?= =?UTF-8?q?=EC=9D=B4=ED=94=84=EB=9D=BC=EC=9D=B8=20=EB=82=B4=20=EC=98=A4?= =?UTF-8?q?=ED=83=80=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/cicd-ec2.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/cicd-ec2.yml b/.github/workflows/cicd-ec2.yml index 5888e1c..b1b59c4 100644 --- a/.github/workflows/cicd-ec2.yml +++ b/.github/workflows/cicd-ec2.yml @@ -158,7 +158,7 @@ jobs: IMAGE_TAG: latest run: | docker build -f ./Dockerfile_staging -t $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG . - docker push $ECR_REGISTRY/$ECR_REPOSITORY: + docker push $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG - name: Upload docker-compose, appspec, afterInstall file to S3 if: contains(github.ref, 'main') From 82fccfcf4a88dc69657d31e4b32a7eaf2dd71c54 Mon Sep 17 00:00:00 2001 From: LeeJaehyung <540900@naver.com> Date: Thu, 12 Sep 2024 22:52:28 +0900 Subject: [PATCH 10/13] Fix: #156 --- genti-api/src/main/resources/application.yaml | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/genti-api/src/main/resources/application.yaml b/genti-api/src/main/resources/application.yaml index 807f998..c51f440 100644 --- a/genti-api/src/main/resources/application.yaml +++ b/genti-api/src/main/resources/application.yaml @@ -8,7 +8,4 @@ spring: include: - secret - common - active: local - -openchat: - admin-secret-key: "4b8a15e3-8c4a-42e0-9c5b-9a4d72f1c934" \ No newline at end of file + active: local \ No newline at end of file From 7403eb4a020be5fb8f736cfffc72208d5f29d51a Mon Sep 17 00:00:00 2001 From: BYEONGRYEOL Date: Thu, 12 Sep 2024 22:53:30 +0900 Subject: [PATCH 11/13] =?UTF-8?q?Update:=20#158=20S3=20=EB=B2=84=ED=82=B7?= =?UTF-8?q?=20=EC=9A=B4=EC=98=81=EA=B3=BC=20=EA=B3=B5=EC=9C=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/cicd-ec2.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.github/workflows/cicd-ec2.yml b/.github/workflows/cicd-ec2.yml index b1b59c4..b5fd574 100644 --- a/.github/workflows/cicd-ec2.yml +++ b/.github/workflows/cicd-ec2.yml @@ -10,7 +10,6 @@ on: env: AWS_REGION: ap-northeast-2 S3_BUCKET_NAME: genti-deploy - S3_BUCKET_NAME_STAGING: genti-staging CODE_DEPLOY_APPLICATION_NAME: genti CODE_DEPLOY_APPLICATION_NAME_STAGING: genti-dev @@ -195,7 +194,7 @@ jobs: # Move back to the initial directory and upload the zip file to S3 cd .. - aws s3 cp --region ap-northeast-2 ./$GITHUB_SHA.zip s3://$S3_BUCKET_NAME_STAGING + aws s3 cp --region ap-northeast-2 ./$GITHUB_SHA.zip s3://$S3_BUCKET_NAME # Clean up the temporary directory rm -rf temp_dir From a313b1064338e13a56962c5f5aec87fe33566f6a Mon Sep 17 00:00:00 2001 From: LeeJaehyung <122717063+LeeJae-H@users.noreply.github.com> Date: Fri, 13 Sep 2024 06:10:02 +0900 Subject: [PATCH 12/13] =?UTF-8?q?Fix:=20SecurityConfig=EC=9D=98=20cors=20?= =?UTF-8?q?=EC=84=A4=EC=A0=95=EC=97=90=20PATCH=20=EB=A9=94=EC=86=8C?= =?UTF-8?q?=EB=93=9C=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/main/java/com/gt/genti/config/SecurityConfig.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/genti-auth/src/main/java/com/gt/genti/config/SecurityConfig.java b/genti-auth/src/main/java/com/gt/genti/config/SecurityConfig.java index 84b7b1f..c5b9b17 100644 --- a/genti-auth/src/main/java/com/gt/genti/config/SecurityConfig.java +++ b/genti-auth/src/main/java/com/gt/genti/config/SecurityConfig.java @@ -47,7 +47,7 @@ public CorsConfigurationSource corsConfigurationSource() { config.setAllowedOriginPatterns(List.of("*")); - config.setAllowedMethods(List.of("GET", "POST", "PUT", "DELETE", "HEAD", "OPTIONS")); + config.setAllowedMethods(List.of("GET", "POST", "PUT", "PATCH", "DELETE", "HEAD", "OPTIONS")); config.addExposedHeader("Access-Token"); config.addExposedHeader("Refresh-Token"); config.setAllowedHeaders(List.of("Authorization", "Cache-Control", "Content-Type", "Admin-Secret-Key")); From 8dc903d0e07a278286ecd49172b247c9cbe7f854 Mon Sep 17 00:00:00 2001 From: LeeJaehyung <540900@naver.com> Date: Fri, 13 Sep 2024 19:23:20 +0900 Subject: [PATCH 13/13] Fix: file-appender.xml --- genti-api/src/main/resources/file-appender.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/genti-api/src/main/resources/file-appender.xml b/genti-api/src/main/resources/file-appender.xml index fec722d..6d2f1f4 100644 --- a/genti-api/src/main/resources/file-appender.xml +++ b/genti-api/src/main/resources/file-appender.xml @@ -1,6 +1,6 @@ - logs/genti-%d{yyyy-MM-dd}.log + /logs/genti-%d{yyyy-MM-dd}.log 90