-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #176 from Genti2024/staging
Staging
- Loading branch information
Showing
17 changed files
with
358 additions
and
11 deletions.
There are no files selected for viewing
26 changes: 26 additions & 0 deletions
26
genti-api/src/main/java/com/gt/genti/maintenance/api/AdminMaintenanceApi.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,26 @@ | ||
package com.gt.genti.maintenance.api; | ||
|
||
import com.gt.genti.response.GentiResponse; | ||
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.RequestBody; | ||
import org.springframework.web.bind.annotation.RequestHeader; | ||
|
||
@AuthorizedAdmin | ||
@Tag(name = "[AdminMaintenanceController] 점검 설정", description = "점검 시작 및 점검 종료하기") | ||
public interface AdminMaintenanceApi { | ||
|
||
@Operation(summary = "점검 시작 메시지 설정", description = "점검 시작 메시지를 설정합니다(해당 api 호출 즉시 점검이 시작됩니다") | ||
ResponseEntity<GentiResponse.ApiResult<Boolean>> setMaintenanceMessage( | ||
@RequestHeader(value = "Admin-Secret-Key") String secretKey, | ||
@RequestBody String type | ||
); | ||
|
||
@Operation(summary = "점검 종료", description = "점검을 종료합니다") | ||
ResponseEntity<GentiResponse.ApiResult<Boolean>> finishMaintenance( | ||
@RequestHeader(value = "Admin-Secret-Key") String secretKey | ||
); | ||
|
||
} |
17 changes: 17 additions & 0 deletions
17
genti-api/src/main/java/com/gt/genti/maintenance/api/UserMaintenanceApi.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,17 @@ | ||
package com.gt.genti.maintenance.api; | ||
|
||
import com.gt.genti.maintenance.dto.response.MaintenanceInfoResponseDto; | ||
import com.gt.genti.response.GentiResponse; | ||
import com.gt.genti.swagger.AuthorizedUser; | ||
import io.swagger.v3.oas.annotations.Operation; | ||
import io.swagger.v3.oas.annotations.tags.Tag; | ||
import org.springframework.http.ResponseEntity; | ||
|
||
@AuthorizedUser | ||
@Tag(name = "[UserMaintenanceController] 점검 정보 확인", description = "서비스 이용 가능 여부 및 점검 메시지 확인") | ||
public interface UserMaintenanceApi { | ||
|
||
@Operation(summary = "점검 정보 확인", description = "서비스 이용 가능 여부 및 점검 메시지를 조회합니다.") | ||
ResponseEntity<GentiResponse.ApiResult<MaintenanceInfoResponseDto>> getMaintenanceInfo(); | ||
|
||
} |
45 changes: 45 additions & 0 deletions
45
genti-api/src/main/java/com/gt/genti/maintenance/controller/AdminMaintenanceController.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,45 @@ | ||
package com.gt.genti.maintenance.controller; | ||
|
||
import com.gt.genti.error.ExpectedException; | ||
import com.gt.genti.error.ResponseCode; | ||
import com.gt.genti.maintenance.api.AdminMaintenanceApi; | ||
import com.gt.genti.maintenance.service.MaintenanceService; | ||
import com.gt.genti.response.GentiResponse; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.beans.factory.annotation.Value; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.*; | ||
|
||
@RestController | ||
@RequestMapping("/api/v1/maintenance/setting") | ||
@RequiredArgsConstructor | ||
public class AdminMaintenanceController implements AdminMaintenanceApi { | ||
|
||
private final MaintenanceService maintenanceService; | ||
|
||
@Value("${openchat.admin-secret-key}") | ||
private String ADMIN_SECRET_KEY; | ||
|
||
@PostMapping | ||
public ResponseEntity<GentiResponse.ApiResult<Boolean>> setMaintenanceMessage( | ||
@RequestHeader(value = "Admin-Secret-Key") String adminSecretKey, | ||
@RequestBody String message | ||
){ | ||
if (!ADMIN_SECRET_KEY.equals(adminSecretKey)) { | ||
throw ExpectedException.withLogging(ResponseCode.InvalidOpenChatSecretKey); | ||
} else{ | ||
return GentiResponse.success(maintenanceService.setMaintenanceMessage(message)); | ||
} | ||
} | ||
|
||
@DeleteMapping | ||
public ResponseEntity<GentiResponse.ApiResult<Boolean>> finishMaintenance( | ||
@RequestHeader(value = "Admin-Secret-Key") String adminSecretKey | ||
){ | ||
if (!ADMIN_SECRET_KEY.equals(adminSecretKey)) { | ||
throw ExpectedException.withLogging(ResponseCode.InvalidOpenChatSecretKey); | ||
} else{ | ||
return GentiResponse.success(maintenanceService.finishMaintenance()); | ||
} | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
genti-api/src/main/java/com/gt/genti/maintenance/controller/UserMaintenanceController.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.gt.genti.maintenance.controller; | ||
|
||
import com.gt.genti.maintenance.api.UserMaintenanceApi; | ||
import com.gt.genti.maintenance.dto.response.MaintenanceInfoResponseDto; | ||
import com.gt.genti.maintenance.service.MaintenanceService; | ||
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.GetMapping; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
@RestController | ||
@RequestMapping("/api/v1/maintenance") | ||
@RequiredArgsConstructor | ||
public class UserMaintenanceController implements UserMaintenanceApi { | ||
|
||
private final MaintenanceService maintenanceService; | ||
|
||
@GetMapping | ||
public ResponseEntity<ApiResult<MaintenanceInfoResponseDto>> getMaintenanceInfo() { | ||
return GentiResponse.success(maintenanceService.getMaintenanceInfo()); | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
...i-api/src/main/java/com/gt/genti/maintenance/dto/response/MaintenanceInfoResponseDto.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,21 @@ | ||
package com.gt.genti.maintenance.dto.response; | ||
|
||
import io.swagger.v3.oas.annotations.media.Schema; | ||
import lombok.Getter; | ||
|
||
@Schema(name = "[Maintenance][User] 점검 정보 응답 dto") | ||
@Getter | ||
public class MaintenanceInfoResponseDto { | ||
|
||
@Schema(description = "서비스 이용 가능 여부", example = "false") | ||
Boolean status; | ||
|
||
@Schema(description = "점검 메시지", example = "09:00 ~ 18:00") | ||
String message; | ||
|
||
public MaintenanceInfoResponseDto(Boolean status, String message) { | ||
this.status = status; | ||
this.message = message; | ||
} | ||
|
||
} |
40 changes: 40 additions & 0 deletions
40
genti-api/src/main/java/com/gt/genti/maintenance/service/MaintenanceService.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,40 @@ | ||
package com.gt.genti.maintenance.service; | ||
|
||
import com.gt.genti.maintenance.dto.response.MaintenanceInfoResponseDto; | ||
import lombok.RequiredArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.beans.factory.annotation.Value; | ||
import org.springframework.data.redis.core.RedisTemplate; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
@Service | ||
@Transactional | ||
@RequiredArgsConstructor | ||
@Slf4j | ||
public class MaintenanceService { | ||
|
||
private final RedisTemplate<String, String> redisTemplate; | ||
|
||
@Value("{maintenance.redis-key}") | ||
private String maintenanceKey; | ||
|
||
public MaintenanceInfoResponseDto getMaintenanceInfo() { | ||
String maintenanceInfo = redisTemplate.opsForValue().get(maintenanceKey); | ||
if (maintenanceInfo == null) { | ||
return new MaintenanceInfoResponseDto(true, null); | ||
} else { | ||
return new MaintenanceInfoResponseDto(false, maintenanceInfo); | ||
} | ||
} | ||
|
||
public Boolean setMaintenanceMessage(String message){ | ||
redisTemplate.opsForValue().set(maintenanceKey, message); | ||
return true; | ||
} | ||
|
||
public Boolean finishMaintenance(){ | ||
return redisTemplate.delete(maintenanceKey); | ||
} | ||
|
||
} |
35 changes: 35 additions & 0 deletions
35
genti-api/src/main/java/com/gt/genti/userverification/api/UserVerificationApi.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,35 @@ | ||
package com.gt.genti.userverification.api; | ||
|
||
import com.gt.genti.error.ResponseCode; | ||
import com.gt.genti.response.GentiResponse.ApiResult; | ||
import com.gt.genti.swagger.AuthorizedUser; | ||
import com.gt.genti.swagger.EnumResponse; | ||
import com.gt.genti.swagger.EnumResponses; | ||
import com.gt.genti.user.model.AuthUser; | ||
import com.gt.genti.userverification.dto.request.UserVerificationRequestDto; | ||
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.RequestBody; | ||
|
||
@AuthorizedUser | ||
@Tag(name = "[UserVerificationController] 유저 본인 인증 컨트롤러", description = "유저의 본인 인증 수행 및 본인 인증 여부를 확인합니다.") | ||
public interface UserVerificationApi { | ||
|
||
@Operation(summary = "본인인증여부확인", description = "유저의 본인 인증 여부를 조회합니다.") | ||
@EnumResponses(value = { | ||
@EnumResponse(ResponseCode.OK), | ||
@EnumResponse(ResponseCode.UserNotFound) | ||
}) | ||
ResponseEntity<ApiResult<Boolean>> checkUserVerification( | ||
@AuthUser Long userId); | ||
|
||
@Operation(summary = "본인인증수행", description = "본인인증사진 저장 및 본인인증변경여부를 수정합니다.") | ||
@EnumResponses(value = { | ||
@EnumResponse(ResponseCode.OK), | ||
@EnumResponse(ResponseCode.UserNotFound) | ||
}) | ||
ResponseEntity<ApiResult<Boolean>> savePictureUserVerification( | ||
@AuthUser Long userId, | ||
@RequestBody UserVerificationRequestDto userVerificationRequestDto); | ||
} |
35 changes: 35 additions & 0 deletions
35
...pi/src/main/java/com/gt/genti/userverification/controller/UserVerificationController.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,35 @@ | ||
package com.gt.genti.userverification.controller; | ||
|
||
import com.gt.genti.response.GentiResponse; | ||
import com.gt.genti.response.GentiResponse.ApiResult; | ||
import com.gt.genti.user.model.AuthUser; | ||
import com.gt.genti.userverification.api.UserVerificationApi; | ||
import com.gt.genti.userverification.dto.request.UserVerificationRequestDto; | ||
import com.gt.genti.userverification.service.UserVerificationService; | ||
import lombok.RequiredArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.*; | ||
|
||
@Slf4j | ||
@RestController | ||
@RequestMapping("/api/v1/user-verification") | ||
@RequiredArgsConstructor | ||
public class UserVerificationController implements UserVerificationApi { | ||
|
||
private final UserVerificationService userVerificationService; | ||
|
||
@GetMapping | ||
public ResponseEntity<ApiResult<Boolean>> checkUserVerification( | ||
@AuthUser Long userId){ | ||
return GentiResponse.success(userVerificationService.checkUserVerification(userId)); | ||
} | ||
|
||
@PostMapping | ||
public ResponseEntity<ApiResult<Boolean>> savePictureUserVerification( | ||
@AuthUser Long userId, | ||
@RequestBody UserVerificationRequestDto userVerificationRequestDto) { | ||
return GentiResponse.success(userVerificationService.savePictureUserVerification(userId, userVerificationRequestDto)); | ||
} | ||
|
||
} |
16 changes: 16 additions & 0 deletions
16
...i/src/main/java/com/gt/genti/userverification/dto/request/UserVerificationRequestDto.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.gt.genti.userverification.dto.request; | ||
|
||
import io.swagger.v3.oas.annotations.media.Schema; | ||
import lombok.AccessLevel; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
|
||
@Getter | ||
@NoArgsConstructor(access = AccessLevel.PROTECTED) | ||
@Schema(name = "[UserVerification][User] 사용자 본인 인증 요청 dto", description = "본인 인증 사진을 저장함") | ||
public class UserVerificationRequestDto { | ||
|
||
@Schema(description = "s3 key", example = "USER_VERIFICATION_IMAGE/image.jpg") | ||
String key; | ||
|
||
} |
44 changes: 44 additions & 0 deletions
44
genti-api/src/main/java/com/gt/genti/userverification/service/UserVerificationService.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,44 @@ | ||
package com.gt.genti.userverification.service; | ||
|
||
import com.gt.genti.error.ExpectedException; | ||
import com.gt.genti.error.ResponseCode; | ||
import com.gt.genti.picture.userverification.model.PictureUserVerification; | ||
import com.gt.genti.picture.userverification.repository.PictureUserVerificationRepository; | ||
import com.gt.genti.user.model.User; | ||
import com.gt.genti.user.repository.UserRepository; | ||
import com.gt.genti.userverification.dto.request.UserVerificationRequestDto; | ||
import lombok.RequiredArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
@Slf4j | ||
@Service | ||
@Transactional | ||
@RequiredArgsConstructor | ||
public class UserVerificationService { | ||
|
||
private final UserRepository userRepository; | ||
private final PictureUserVerificationRepository pictureUserVerificationRepository; | ||
|
||
public Boolean checkUserVerification(Long userId){ | ||
User foundUser = getUserByUserId(userId); | ||
Boolean isVerified = foundUser.getUserVerified(); | ||
return isVerified != null && isVerified; | ||
} | ||
|
||
public Boolean savePictureUserVerification(Long userId, UserVerificationRequestDto userVerificationRequestDto){ | ||
User foundUser = getUserByUserId(userId); | ||
PictureUserVerification pictureUserVerification = new PictureUserVerification(userVerificationRequestDto.getKey(), foundUser); | ||
pictureUserVerificationRepository.save(pictureUserVerification); | ||
foundUser.verifyUser(); | ||
return true; | ||
} | ||
|
||
|
||
private User getUserByUserId(Long userId) { | ||
return userRepository.findById(userId) | ||
.orElseThrow(() -> ExpectedException.withLogging(ResponseCode.UserNotFound, userId)); | ||
} | ||
|
||
} |
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
25 changes: 25 additions & 0 deletions
25
...in/src/main/java/com/gt/genti/picture/userverification/model/PictureUserVerification.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.gt.genti.picture.userverification.model; | ||
|
||
import com.gt.genti.common.picture.model.PictureEntity; | ||
import com.gt.genti.user.model.User; | ||
import jakarta.persistence.*; | ||
import lombok.AccessLevel; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
|
||
@Table(name = "picture_user_verification") | ||
@Entity | ||
@Getter | ||
@NoArgsConstructor(access = AccessLevel.PROTECTED) | ||
public class PictureUserVerification extends PictureEntity { | ||
|
||
@Id | ||
@GeneratedValue(strategy = GenerationType.IDENTITY) | ||
Long id; | ||
|
||
public PictureUserVerification(String key, User user) { | ||
this.key = key; | ||
this.setUploadedBy(user); | ||
} | ||
|
||
} |
8 changes: 8 additions & 0 deletions
8
...a/com/gt/genti/picture/userverification/repository/PictureUserVerificationRepository.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,8 @@ | ||
package com.gt.genti.picture.userverification.repository; | ||
|
||
import com.gt.genti.picture.userverification.model.PictureUserVerification; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
|
||
public interface PictureUserVerificationRepository extends JpaRepository<PictureUserVerification, Long> { | ||
|
||
} |
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
Oops, something went wrong.