Skip to content

Commit

Permalink
Merge pull request #176 from Genti2024/staging
Browse files Browse the repository at this point in the history
Staging
  • Loading branch information
LeeJae-H authored Sep 30, 2024
2 parents b0bd459 + c6f827d commit 7444f9e
Show file tree
Hide file tree
Showing 17 changed files with 358 additions and 11 deletions.
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
);

}
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();

}
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());
}
}
}
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());
}
}
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;
}

}
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);
}

}
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);
}
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));
}

}
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;

}
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));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ void postConstruct() {
"/h2-console/**",
"/h2-console",
"/api/v1/open-chat/*",
"/api/v1/maintenance/setting",
"/api/v1/push",
"/api/v1/push/**"
));
Expand All @@ -61,6 +62,7 @@ void postConstruct() {
"/h2-console/**",
"/h2-console",
"/api/v1/open-chat/*",
"/api/v1/maintenance/setting",
"/api/v1/push",
"/api/v1/push/**"
));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
@Getter
@RequiredArgsConstructor
public enum OpenChatType implements ConvertableEnum {

OB("OB", "OB"),
YB("YB", "YB");

Expand Down
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);
}

}
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> {

}
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,7 @@
import com.gt.genti.common.basetimeentity.model.BaseTimeEntity;
import com.gt.genti.picturegenerateresponse.model.PictureGenerateResponse;

import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
import jakarta.persistence.JoinColumn;
import jakarta.persistence.ManyToOne;
import jakarta.persistence.OneToOne;
import jakarta.persistence.Table;
import jakarta.persistence.*;
import lombok.AccessLevel;
import lombok.Builder;
import lombok.Getter;
Expand All @@ -28,7 +20,7 @@ public class Settlement extends BaseTimeEntity {
@GeneratedValue(strategy = GenerationType.IDENTITY)
Long id;

@OneToOne
@OneToOne(cascade = CascadeType.REMOVE)
@JoinColumn(name = "picture_generate_response_id", referencedColumnName = "id", nullable = false)
PictureGenerateResponse pictureGenerateResponse;

Expand Down
Loading

0 comments on commit 7444f9e

Please sign in to comment.