fix redis config

This commit is contained in:
박서은 2025-06-12 15:17:15 +09:00
parent 16ce90c394
commit 7cb0efa769
8 changed files with 52 additions and 27 deletions

View File

@ -4,6 +4,7 @@ import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.connection.RedisConnectionFactory; import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.data.redis.connection.RedisStandaloneConfiguration;
import org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory; import org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory;
import org.springframework.data.redis.core.RedisTemplate; import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.serializer.StringRedisSerializer; import org.springframework.data.redis.serializer.StringRedisSerializer;
@ -21,6 +22,12 @@ public class RedisConfig {
@Value("${spring.data.redis.port}") @Value("${spring.data.redis.port}")
private int redisPort; private int redisPort;
@Value("${spring.data.redis.password:}")
private String redisPassword;
@Value("${spring.data.redis.ssl:true}")
private boolean useSsl;
/** /**
* Redis 연결 팩토리 설정 * Redis 연결 팩토리 설정
* *
@ -28,7 +35,22 @@ public class RedisConfig {
*/ */
@Bean @Bean
public RedisConnectionFactory redisConnectionFactory() { public RedisConnectionFactory redisConnectionFactory() {
return new LettuceConnectionFactory(redisHost, redisPort); RedisStandaloneConfiguration config = new RedisStandaloneConfiguration();
config.setHostName(redisHost);
config.setPort(redisPort);
// Azure Redis는 패스워드 인증 필수
if (redisPassword != null && !redisPassword.isEmpty()) {
config.setPassword(redisPassword);
}
LettuceConnectionFactory factory = new LettuceConnectionFactory(config);
// Azure Redis는 SSL 사용 (6380 포트)
factory.setUseSsl(useSsl);
factory.setValidateConnection(true);
return factory;
} }
/** /**

View File

@ -26,7 +26,7 @@ public class Member {
@Id @Id
@GeneratedValue(strategy = GenerationType.IDENTITY) @GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "member_id") @Column(name = "id")
private Long id; private Long id;
@Column(name = "user_id", nullable = false, unique = true, length = 50) @Column(name = "user_id", nullable = false, unique = true, length = 50)

View File

@ -20,7 +20,7 @@ spring:
data: data:
redis: redis:
host: ${REDIS_HOST:localhost} host: ${REDIS_HOST:localhost}
port: ${REDIS_PORT:6379} port: ${REDIS_PORT:6380}
password: ${REDIS_PASSWORD:} password: ${REDIS_PASSWORD:}
jwt: jwt:

View File

@ -42,15 +42,16 @@ public class StoreController {
/** /**
* 매장 정보 조회 * 매장 정보 조회
* *
* @param storeId 조회할 매장 ID * //@param userId 조회할 매장 ID
* @return 매장 정보 * @return 매장 정보
*/ */
@Operation(summary = "매장 조회", description = "매장 ID로 매장 정보를 조회합니다.") @Operation(summary = "매장 조회", description = "유저 ID로 매장 정보를 조회합니다.")
@GetMapping @GetMapping
public ResponseEntity<ApiResponse<StoreResponse>> getStore( public ResponseEntity<ApiResponse<StoreResponse>> getStore(
@Parameter(description = "매장 ID", required = true) // @Parameter(description = "유저 ID", required = true)
@RequestParam String storeId) { // @RequestParam String userId
StoreResponse response = storeService.getStore(storeId); ) {
StoreResponse response = storeService.getStore();
return ResponseEntity.ok(ApiResponse.success(response)); return ResponseEntity.ok(ApiResponse.success(response));
} }

View File

@ -30,8 +30,8 @@ public class Store {
@Column(name = "store_id") @Column(name = "store_id")
private Long id; private Long id;
@Column(name = "member_id", nullable = false) @Column(name = "user_id", nullable = false)
private Long memberId; private String userId;
@Column(name = "store_name", nullable = false, length = 100) @Column(name = "store_name", nullable = false, length = 100)
private String storeName; private String storeName;

View File

@ -16,18 +16,18 @@ public interface StoreRepository extends JpaRepository<Store, Long> {
/** /**
* 회원 ID로 매장 조회 * 회원 ID로 매장 조회
* *
* @param memberId 회원 ID * @param userId 회원 ID
* @return 매장 정보 (Optional) * @return 매장 정보 (Optional)
*/ */
Optional<Store> findByMemberId(Long memberId); Optional<Store> findByUserId(String userId);
/** /**
* 회원의 매장 존재 여부 확인 * 회원의 매장 존재 여부 확인
* *
* @param memberId 회원 ID * @param userId 회원 ID
* @return 존재 여부 * @return 존재 여부
*/ */
boolean existsByMemberId(Long memberId); boolean existsByUserId(String userId);
/** /**
* 매장명으로 매장 조회 * 매장명으로 매장 조회

View File

@ -28,10 +28,10 @@ public interface StoreService {
/** /**
* 매장 정보 조회 (매장 ID) * 매장 정보 조회 (매장 ID)
* *
* @param storeId 매장 ID * //@param userId 매장 ID
* @return 매장 정보 * @return 매장 정보
*/ */
StoreResponse getStore(String storeId); StoreResponse getStore();
/** /**
* 매장 정보 수정 * 매장 정보 수정

View File

@ -7,6 +7,8 @@ import com.won.smarketing.store.dto.StoreResponse;
import com.won.smarketing.store.dto.StoreUpdateRequest; import com.won.smarketing.store.dto.StoreUpdateRequest;
import com.won.smarketing.store.entity.Store; import com.won.smarketing.store.entity.Store;
import com.won.smarketing.store.repository.StoreRepository; import com.won.smarketing.store.repository.StoreRepository;
import jakarta.xml.bind.annotation.XmlType;
import lombok.Builder;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.security.core.context.SecurityContextHolder; import org.springframework.security.core.context.SecurityContextHolder;
@ -34,19 +36,19 @@ public class StoreServiceImpl implements StoreService {
@Override @Override
@Transactional @Transactional
public StoreResponse register(StoreCreateRequest request) { public StoreResponse register(StoreCreateRequest request) {
String currentUserId = getCurrentUserId(); String memberId = getCurrentUserId();
Long memberId = Long.valueOf(currentUserId); // 실제로는 Member ID 조회 필요 // Long memberId = Long.valueOf(currentUserId); // 실제로는 Member ID 조회 필요
log.info("매장 등록 시작: {} (회원: {})", request.getStoreName(), memberId); log.info("매장 등록 시작: {} (회원: {})", request.getStoreName(), memberId);
// 회원당 하나의 매장만 등록 가능 // 회원당 하나의 매장만 등록 가능
if (storeRepository.existsByMemberId(memberId)) { if (storeRepository.existsByUserId(memberId)) {
throw new BusinessException(ErrorCode.STORE_ALREADY_EXISTS); throw new BusinessException(ErrorCode.STORE_ALREADY_EXISTS);
} }
// 매장 엔티티 생성 저장 // 매장 엔티티 생성 저장
Store store = Store.builder() Store store = Store.builder()
.memberId(memberId) .userId(memberId)
.storeName(request.getStoreName()) .storeName(request.getStoreName())
.businessType(request.getBusinessType()) .businessType(request.getBusinessType())
.address(request.getAddress()) .address(request.getAddress())
@ -71,10 +73,10 @@ public class StoreServiceImpl implements StoreService {
*/ */
@Override @Override
public StoreResponse getMyStore() { public StoreResponse getMyStore() {
String currentUserId = getCurrentUserId(); String memberId = getCurrentUserId();
Long memberId = Long.valueOf(currentUserId); // Long memberId = Long.valueOf(currentUserId);
Store store = storeRepository.findByMemberId(memberId) Store store = storeRepository.findByUserId(memberId)
.orElseThrow(() -> new BusinessException(ErrorCode.STORE_NOT_FOUND)); .orElseThrow(() -> new BusinessException(ErrorCode.STORE_NOT_FOUND));
return toStoreResponse(store); return toStoreResponse(store);
@ -83,14 +85,14 @@ public class StoreServiceImpl implements StoreService {
/** /**
* 매장 정보 조회 (매장 ID) * 매장 정보 조회 (매장 ID)
* *
* @param storeId 매장 ID * //@param storeId 매장 ID
* @return 매장 정보 * @return 매장 정보
*/ */
@Override @Override
public StoreResponse getStore(String storeId) { public StoreResponse getStore() {
try { try {
Long id = Long.valueOf(storeId); String userId = getCurrentUserId();
Store store = storeRepository.findById(id) Store store = storeRepository.findByUserId(userId)
.orElseThrow(() -> new BusinessException(ErrorCode.STORE_NOT_FOUND)); .orElseThrow(() -> new BusinessException(ErrorCode.STORE_NOT_FOUND));
return toStoreResponse(store); return toStoreResponse(store);