mirror of
https://github.com/won-ktds/smarketing-backend.git
synced 2025-12-06 07:06:24 +00:00
fix redis config
This commit is contained in:
parent
16ce90c394
commit
7cb0efa769
@ -4,6 +4,7 @@ import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
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.core.RedisTemplate;
|
||||
import org.springframework.data.redis.serializer.StringRedisSerializer;
|
||||
@ -21,6 +22,12 @@ public class RedisConfig {
|
||||
@Value("${spring.data.redis.port}")
|
||||
private int redisPort;
|
||||
|
||||
@Value("${spring.data.redis.password:}")
|
||||
private String redisPassword;
|
||||
|
||||
@Value("${spring.data.redis.ssl:true}")
|
||||
private boolean useSsl;
|
||||
|
||||
/**
|
||||
* Redis 연결 팩토리 설정
|
||||
*
|
||||
@ -28,7 +35,22 @@ public class RedisConfig {
|
||||
*/
|
||||
@Bean
|
||||
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;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@ -26,7 +26,7 @@ public class Member {
|
||||
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
@Column(name = "member_id")
|
||||
@Column(name = "id")
|
||||
private Long id;
|
||||
|
||||
@Column(name = "user_id", nullable = false, unique = true, length = 50)
|
||||
|
||||
@ -20,7 +20,7 @@ spring:
|
||||
data:
|
||||
redis:
|
||||
host: ${REDIS_HOST:localhost}
|
||||
port: ${REDIS_PORT:6379}
|
||||
port: ${REDIS_PORT:6380}
|
||||
password: ${REDIS_PASSWORD:}
|
||||
|
||||
jwt:
|
||||
|
||||
@ -42,15 +42,16 @@ public class StoreController {
|
||||
/**
|
||||
* 매장 정보 조회
|
||||
*
|
||||
* @param storeId 조회할 매장 ID
|
||||
* //@param userId 조회할 매장 ID
|
||||
* @return 매장 정보
|
||||
*/
|
||||
@Operation(summary = "매장 조회", description = "매장 ID로 매장 정보를 조회합니다.")
|
||||
@Operation(summary = "매장 조회", description = "유저 ID로 매장 정보를 조회합니다.")
|
||||
@GetMapping
|
||||
public ResponseEntity<ApiResponse<StoreResponse>> getStore(
|
||||
@Parameter(description = "매장 ID", required = true)
|
||||
@RequestParam String storeId) {
|
||||
StoreResponse response = storeService.getStore(storeId);
|
||||
// @Parameter(description = "유저 ID", required = true)
|
||||
// @RequestParam String userId
|
||||
) {
|
||||
StoreResponse response = storeService.getStore();
|
||||
return ResponseEntity.ok(ApiResponse.success(response));
|
||||
}
|
||||
|
||||
|
||||
@ -30,8 +30,8 @@ public class Store {
|
||||
@Column(name = "store_id")
|
||||
private Long id;
|
||||
|
||||
@Column(name = "member_id", nullable = false)
|
||||
private Long memberId;
|
||||
@Column(name = "user_id", nullable = false)
|
||||
private String userId;
|
||||
|
||||
@Column(name = "store_name", nullable = false, length = 100)
|
||||
private String storeName;
|
||||
|
||||
@ -16,18 +16,18 @@ public interface StoreRepository extends JpaRepository<Store, Long> {
|
||||
/**
|
||||
* 회원 ID로 매장 조회
|
||||
*
|
||||
* @param memberId 회원 ID
|
||||
* @param userId 회원 ID
|
||||
* @return 매장 정보 (Optional)
|
||||
*/
|
||||
Optional<Store> findByMemberId(Long memberId);
|
||||
Optional<Store> findByUserId(String userId);
|
||||
|
||||
/**
|
||||
* 회원의 매장 존재 여부 확인
|
||||
*
|
||||
* @param memberId 회원 ID
|
||||
* @param userId 회원 ID
|
||||
* @return 존재 여부
|
||||
*/
|
||||
boolean existsByMemberId(Long memberId);
|
||||
boolean existsByUserId(String userId);
|
||||
|
||||
/**
|
||||
* 매장명으로 매장 조회
|
||||
|
||||
@ -28,10 +28,10 @@ public interface StoreService {
|
||||
/**
|
||||
* 매장 정보 조회 (매장 ID)
|
||||
*
|
||||
* @param storeId 매장 ID
|
||||
* //@param userId 매장 ID
|
||||
* @return 매장 정보
|
||||
*/
|
||||
StoreResponse getStore(String storeId);
|
||||
StoreResponse getStore();
|
||||
|
||||
/**
|
||||
* 매장 정보 수정
|
||||
|
||||
@ -7,6 +7,8 @@ import com.won.smarketing.store.dto.StoreResponse;
|
||||
import com.won.smarketing.store.dto.StoreUpdateRequest;
|
||||
import com.won.smarketing.store.entity.Store;
|
||||
import com.won.smarketing.store.repository.StoreRepository;
|
||||
import jakarta.xml.bind.annotation.XmlType;
|
||||
import lombok.Builder;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.security.core.context.SecurityContextHolder;
|
||||
@ -34,19 +36,19 @@ public class StoreServiceImpl implements StoreService {
|
||||
@Override
|
||||
@Transactional
|
||||
public StoreResponse register(StoreCreateRequest request) {
|
||||
String currentUserId = getCurrentUserId();
|
||||
Long memberId = Long.valueOf(currentUserId); // 실제로는 Member ID 조회 필요
|
||||
String memberId = getCurrentUserId();
|
||||
// Long memberId = Long.valueOf(currentUserId); // 실제로는 Member ID 조회 필요
|
||||
|
||||
log.info("매장 등록 시작: {} (회원: {})", request.getStoreName(), memberId);
|
||||
|
||||
// 회원당 하나의 매장만 등록 가능
|
||||
if (storeRepository.existsByMemberId(memberId)) {
|
||||
if (storeRepository.existsByUserId(memberId)) {
|
||||
throw new BusinessException(ErrorCode.STORE_ALREADY_EXISTS);
|
||||
}
|
||||
|
||||
// 매장 엔티티 생성 및 저장
|
||||
Store store = Store.builder()
|
||||
.memberId(memberId)
|
||||
.userId(memberId)
|
||||
.storeName(request.getStoreName())
|
||||
.businessType(request.getBusinessType())
|
||||
.address(request.getAddress())
|
||||
@ -71,10 +73,10 @@ public class StoreServiceImpl implements StoreService {
|
||||
*/
|
||||
@Override
|
||||
public StoreResponse getMyStore() {
|
||||
String currentUserId = getCurrentUserId();
|
||||
Long memberId = Long.valueOf(currentUserId);
|
||||
String memberId = getCurrentUserId();
|
||||
// Long memberId = Long.valueOf(currentUserId);
|
||||
|
||||
Store store = storeRepository.findByMemberId(memberId)
|
||||
Store store = storeRepository.findByUserId(memberId)
|
||||
.orElseThrow(() -> new BusinessException(ErrorCode.STORE_NOT_FOUND));
|
||||
|
||||
return toStoreResponse(store);
|
||||
@ -83,14 +85,14 @@ public class StoreServiceImpl implements StoreService {
|
||||
/**
|
||||
* 매장 정보 조회 (매장 ID)
|
||||
*
|
||||
* @param storeId 매장 ID
|
||||
* //@param storeId 매장 ID
|
||||
* @return 매장 정보
|
||||
*/
|
||||
@Override
|
||||
public StoreResponse getStore(String storeId) {
|
||||
public StoreResponse getStore() {
|
||||
try {
|
||||
Long id = Long.valueOf(storeId);
|
||||
Store store = storeRepository.findById(id)
|
||||
String userId = getCurrentUserId();
|
||||
Store store = storeRepository.findByUserId(userId)
|
||||
.orElseThrow(() -> new BusinessException(ErrorCode.STORE_NOT_FOUND));
|
||||
|
||||
return toStoreResponse(store);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user