Compare commits

18 Commits

Author SHA1 Message Date
jhbkjh 52b63fb0f0 frontend 연동을 위해 임시 커밋 2025-10-30 16:49:31 +09:00
jhbkjh ac7fcbd2fe api경로 수정(participation) 2025-10-30 16:21:10 +09:00
jhbkjh 72728841db security 수정 2025-10-30 15:45:22 +09:00
jhbkjh a3381cc540 cors문제 수정 2025-10-30 12:22:19 +09:00
jhbkjh 7ed2465d57 participation-service CORS 설정 수정
- SecurityConfig.java @Value 어노테이션 문법 오류 수정
- application.yml CORS allowed-origins에 localhost:3000 추가
- Frontend UI (localhost:3000)에서 API 호출 시 CORS 에러 해결
2025-10-30 10:37:36 +09:00
jhbkjh 5cac8ccc12 participation-service WebConfig 추가
- CORS 설정 적용
- 모든 origin 패턴 허용
- 모든 HTTP 메서드 허용
- Credentials 허용
2025-10-30 10:21:08 +09:00
jhbkjh 6948b48498 participation-service pod 연결 문제 해결
- Service selector를 app=participation-service만으로 간소화하여 영구적 해결
- Pod restart 시에도 자동 연결되도록 수정
- Swagger UI 외부 접근 정상화 확인

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-10-30 09:47:45 +09:00
hiondal 3afee053d0 Kustomize commonLabels 제거 및 API 토큰 추가
- Deployment selector 불변성 에러 해결을 위해 commonLabels 제거
- base/kustomization.yaml: app.kubernetes.io/managed-by, app.kubernetes.io/part-of 레이블 제거
- overlays/dev/kustomization.yaml: environment 레이블 제거
- content-service: Replicate API 토큰 추가
2025-10-30 09:35:17 +09:00
merrycoral 27a3111dd8 develop 브랜치 변경사항 요약 문서 작성
- feature/event 머지 내역 상세 정리
- EventId/JobId 생성 로직 설명
- Kafka 메시지 구조 개선 내역
- 데이터베이스 스키마 변경사항
- 테스트 및 문서화 완료 내역
- 성능 지표 및 배포 준비 상태

총 60개 파일 변경 (+2,795줄, -222줄)

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-10-30 01:45:46 +09:00
merrycoral 3465a35827 Merge branch 'feature/event' into develop 2025-10-30 01:42:33 +09:00
wonho 640e94bf17 user-service CORS 및 경로 매핑 수정
- SecurityConfig: CORS 설정 개선 및 context-path 기반 경로 수정
- UserController: RequestMapping 중복 경로 제거
- SwaggerConfig: Production 서버 URL 추가

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-10-29 18:25:09 +09:00
wonho e8d0a1d4b4 백엔드 서비스 설정 및 CORS 정책 업데이트
- CORS 설정에 https 프로토콜 지원 추가
- User-Service CORS를 모든 Origin 허용으로 변경
- ConfigMap CORS_ALLOWED_ORIGINS 확장
- User-Service DB migration 스크립트 추가
- Application 설정 파일 업데이트

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-10-29 17:59:01 +09:00
wonho 857fa5501c GitHub Actions workflow push 이벤트 비활성화
- push 트리거를 주석 처리하여 자동 실행 방지
- Pull Request 생성 시에만 자동 실행
- 수동 실행(workflow_dispatch)은 계속 가능

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-10-29 17:59:01 +09:00
kkkd-max ab39c76585 Merge pull request #26 from ktds-dg0501/feature/partici
url추가
2025-10-29 17:54:02 +09:00
jhbkjh 1e38d52967 url추가 2025-10-29 17:53:32 +09:00
이선민 6205a98ca0 Merge pull request #25 from ktds-dg0501/feature/distribution
api path 수정_2
2025-10-29 17:03:47 +09:00
sunmingLee ebd7ae12b6 api path 추가수정 2025-10-29 17:02:25 +09:00
sunmingLee 2cd1ba76f5 api path 수정 2025-10-29 16:44:07 +09:00
24 changed files with 916 additions and 193 deletions
@@ -8,7 +8,7 @@ stringData:
AZURE_STORAGE_CONNECTION_STRING: "DefaultEndpointsProtocol=https;AccountName=blobkteventstorage;AccountKey=tcBN7mAfojbl0uGsOpU7RNuKNhHnzmwDiWjN31liSMVSrWaEK+HHnYKZrjBXXAC6ZPsuxUDlsf8x+AStd++QYg==;EndpointSuffix=core.windows.net"
# Replicate API Token
REPLICATE_API_TOKEN: ""
REPLICATE_API_TOKEN: "r8_BsGCJtAg5U5kkMBXSe3pgMkPufSKnUR4NY9gJ"
# HuggingFace API Token
HUGGINGFACE_API_TOKEN: ""
@@ -53,11 +53,6 @@ resources:
- analytics-service-cm-analytics-service.yaml
- analytics-service-secret-analytics-service.yaml
# Common labels for all resources
commonLabels:
app.kubernetes.io/managed-by: kustomize
app.kubernetes.io/part-of: kt-event-marketing
# Image tag replacement (will be overridden by overlays)
images:
- name: acrdigitalgarage01.azurecr.io/kt-event-marketing/user-service
@@ -6,10 +6,6 @@ namespace: kt-event-marketing
bases:
- ../../base
# Environment-specific labels
commonLabels:
environment: dev
# Environment-specific patches
patchesStrategicMerge:
- user-service-patch.yaml
+8 -8
View File
@@ -1,14 +1,14 @@
name: Backend CI/CD Pipeline
on:
push:
branches:
- develop
- main
paths:
- '*-service/**'
- '.github/workflows/backend-cicd.yaml'
- '.github/kustomize/**'
# push:
# branches:
# - develop
# - main
# paths:
# - '*-service/**'
# - '.github/workflows/backend-cicd.yaml'
# - '.github/kustomize/**'
pull_request:
branches:
- develop
+620
View File
@@ -0,0 +1,620 @@
# Develop 브랜치 변경사항 요약
**업데이트 일시**: 2025-10-30
**머지 브랜치**: feature/event → develop
**머지 커밋**: 3465a35
---
## 📊 변경사항 통계
```
60개 파일 변경
+2,795 줄 추가
-222 줄 삭제
```
---
## 🎯 주요 변경사항
### 1. 비즈니스 친화적 ID 생성 시스템 구현
#### EventId 생성 로직
**파일**: `event-service/.../EventIdGenerator.java` (신규)
**ID 포맷**: `EVT-{store_id}-{timestamp}-{random}`
```
예시: EVT-str_dev_test_001-20251030001311-70eea424
```
**특징**:
- ✅ 비즈니스 의미를 담은 접두사 (EVT)
- ✅ 매장 식별자 포함 (store_id)
- ✅ 타임스탬프 기반 시간 추적 가능
- ✅ 랜덤 해시로 유일성 보장
- ✅ 사람이 읽기 쉬운 형식
**구현 내역**:
```java
public class EventIdGenerator {
private static final String PREFIX = "EVT";
public static String generate(String storeId) {
String cleanStoreId = sanitizeStoreId(storeId);
String timestamp = LocalDateTime.now()
.format(DateTimeFormatter.ofPattern("yyyyMMddHHmmss"));
String randomHash = UUID.randomUUID().toString()
.substring(0, 8);
return String.format("%s-%s-%s-%s",
PREFIX, cleanStoreId, timestamp, randomHash);
}
}
```
#### JobId 생성 로직
**파일**: `event-service/.../JobIdGenerator.java` (신규)
**ID 포맷**: `JOB-{type}-{timestamp}-{random}`
```
예시: JOB-IMG-1761750847428-b88d2f54
```
**타입 코드**:
- `IMG`: 이미지 생성 작업
- `AI`: AI 추천 작업
- `REG`: 이미지 재생성 작업
**특징**:
- ✅ 작업 타입 식별 가능
- ✅ 타임스탬프로 작업 시간 추적
- ✅ UUID 기반 유일성 보장
- ✅ 로그 분석 및 디버깅 용이
---
### 2. Kafka 메시지 구조 개선
#### 필드명 표준화 (snake_case → camelCase)
**변경 파일**:
- `AIEventGenerationJobMessage.java`
- `EventCreatedMessage.java`
- `ImageJobKafkaProducer.java`
- `AIJobKafkaProducer.java`
- 관련 Consumer 클래스들
**Before**:
```json
{
"job_id": "...",
"event_id": "...",
"store_id": "...",
"store_name": "..."
}
```
**After**:
```json
{
"jobId": "...",
"eventId": "...",
"storeId": "...",
"storeName": "..."
}
```
**이점**:
- ✅ Java 네이밍 컨벤션 준수
- ✅ JSON 직렬화/역직렬화 간소화
- ✅ 프론트엔드와 일관된 필드명
- ✅ 코드 가독성 향상
**영향받는 메시지**:
1. **이미지 생성 작업 메시지** (`image-generation-job`)
- jobId, eventId, prompt, styles, platforms 등
2. **AI 이벤트 생성 작업 메시지** (`ai-event-generation-job`)
- jobId, eventId, objective, storeInfo 등
3. **이벤트 생성 완료 메시지** (`event-created`)
- eventId, storeId, storeName, objective 등
---
### 3. 데이터베이스 스키마 및 마이그레이션
#### 신규 스키마 파일
**파일**: `develop/database/schema/create_event_tables.sql`
**테이블 구조**:
```sql
-- events 테이블
CREATE TABLE events (
id VARCHAR(100) PRIMARY KEY, -- EVT-{store_id}-{timestamp}-{hash}
user_id VARCHAR(50) NOT NULL,
store_id VARCHAR(50) NOT NULL,
store_name VARCHAR(200),
objective VARCHAR(50),
status VARCHAR(20),
created_at TIMESTAMP,
updated_at TIMESTAMP
);
-- jobs 테이블
CREATE TABLE jobs (
id VARCHAR(100) PRIMARY KEY, -- JOB-{type}-{timestamp}-{hash}
event_id VARCHAR(100),
job_type VARCHAR(50),
status VARCHAR(20),
progress INTEGER,
result_message TEXT,
error_message TEXT,
created_at TIMESTAMP,
updated_at TIMESTAMP
);
-- ai_recommendations 테이블
CREATE TABLE ai_recommendations (
id BIGSERIAL PRIMARY KEY,
event_id VARCHAR(100),
recommendation_text TEXT,
-- ... 기타 필드
);
-- generated_images 테이블
CREATE TABLE generated_images (
id BIGSERIAL PRIMARY KEY,
event_id VARCHAR(100),
image_url TEXT,
style VARCHAR(50),
platform VARCHAR(50),
-- ... 기타 필드
);
```
#### 마이그레이션 스크립트
**파일**: `develop/database/migration/alter_event_id_to_varchar.sql`
**목적**: 기존 BIGINT 타입의 ID를 VARCHAR로 변경
```sql
-- Step 1: 백업 테이블 생성
CREATE TABLE events_backup AS SELECT * FROM events;
CREATE TABLE jobs_backup AS SELECT * FROM jobs;
-- Step 2: 기존 테이블 삭제
DROP TABLE IF EXISTS events CASCADE;
DROP TABLE IF EXISTS jobs CASCADE;
-- Step 3: 새 스키마로 테이블 재생성
-- (create_event_tables.sql 실행)
-- Step 4: 데이터 마이그레이션
-- (필요시 기존 데이터를 새 형식으로 변환하여 삽입)
```
**주의사항**:
- ⚠️ 프로덕션 환경에서는 반드시 백업 후 실행
- ⚠️ 외래 키 제약조건 재설정 필요
- ⚠️ 애플리케이션 코드와 동시 배포 필요
---
### 4. Content Service 통합 및 개선
#### Content Service 설정 업데이트
**파일**: `content-service/src/main/resources/application.yml`
**변경사항**:
```yaml
# JWT 설정 추가
jwt:
secret: ${JWT_SECRET:kt-event-marketing-jwt-secret...}
access-token-validity: ${JWT_ACCESS_TOKEN_VALIDITY:3600000}
# Azure Blob Storage 설정 추가
azure:
storage:
connection-string: ${AZURE_STORAGE_CONNECTION_STRING:...}
container-name: ${AZURE_CONTAINER_NAME:content-images}
```
#### 서비스 개선사항
**파일**: `content-service/.../RegenerateImageService.java`, `StableDiffusionImageGenerator.java`
**주요 개선**:
- ✅ 이미지 재생성 로직 추가 (28줄)
- ✅ Stable Diffusion 통합 개선 (28줄)
- ✅ Mock Mode 개선 (개발 환경)
- ✅ 에러 처리 강화
---
### 5. Event Service 리팩토링
#### DTO 구조 개선
**변경 파일**:
- Request DTO: `AiRecommendationRequest`, `SelectImageRequest`
- Response DTO: `EventCreatedResponse`, `EventDetailResponse`
- Kafka DTO: 모든 메시지 클래스
**주요 변경**:
1. **필드명 표준화**: snake_case → camelCase
2. **ID 타입 변경**: Long → String
3. **Nullable 필드 명시**: @Nullable 어노테이션 추가
4. **Validation 강화**: @NotNull, @NotBlank
#### Service Layer 개선
**파일**: `EventService.java`, `JobService.java`
**Before**:
```java
public EventCreatedResponse createEvent(CreateEventRequest request) {
Event event = new Event();
event.setId(generateSequentialId()); // Long 타입
// ...
}
```
**After**:
```java
public EventCreatedResponse createEvent(CreateEventRequest request) {
String eventId = EventIdGenerator.generate(request.getStoreId());
Event event = Event.builder()
.id(eventId) // String 타입
.storeId(request.getStoreId())
// ...
.build();
}
```
**개선사항**:
- ✅ EventIdGenerator 사용
- ✅ Builder 패턴 적용
- ✅ 비즈니스 로직 분리
- ✅ 에러 처리 개선
---
### 6. Kafka 연동 개선
#### Producer 개선
**파일**: `AIJobKafkaProducer.java`, `ImageJobKafkaProducer.java`
**주요 개선**:
```java
@Service
@RequiredArgsConstructor
@Slf4j
public class ImageJobKafkaProducer {
public void sendImageGenerationJob(ImageGenerationJobMessage message) {
log.info("이미지 생성 작업 메시지 발행 시작 - JobId: {}",
message.getJobId());
kafkaTemplate.send(topicName, message.getJobId(), message)
.whenComplete((result, ex) -> {
if (ex != null) {
log.error("메시지 발행 실패: {}", ex.getMessage());
} else {
log.info("메시지 발행 성공 - Offset: {}",
result.getRecordMetadata().offset());
}
});
}
}
```
**개선사항**:
- ✅ 상세한 로깅 추가
- ✅ 비동기 콜백 처리
- ✅ 에러 핸들링 강화
- ✅ 메시지 키 설정 (jobId)
#### Consumer 개선
**파일**: `ImageJobKafkaConsumer.java`, `AIJobKafkaConsumer.java`
**주요 개선**:
```java
@KafkaListener(
topics = "${app.kafka.topics.image-generation-job}",
groupId = "${spring.kafka.consumer.group-id}"
)
public void consumeImageJob(
@Payload ImageGenerationJobMessage message,
Acknowledgment ack
) {
log.info("이미지 작업 메시지 수신 - JobId: {}", message.getJobId());
try {
// 메시지 처리
processImageJob(message);
// Manual Acknowledgment
ack.acknowledge();
log.info("메시지 처리 완료 - JobId: {}", message.getJobId());
} catch (Exception e) {
log.error("메시지 처리 실패: {}", e.getMessage());
// 재시도 로직 또는 DLQ 전송
}
}
```
**개선사항**:
- ✅ Manual Acknowledgment 패턴
- ✅ 상세한 로깅
- ✅ 예외 처리 강화
- ✅ 메시지 재시도 메커니즘
---
### 7. 보안 및 인증 개선
#### JWT 토큰 처리 개선
**파일**: `common/security/JwtTokenProvider.java`, `UserPrincipal.java`
**주요 변경**:
```java
public class JwtTokenProvider {
public String getUserId(String token) {
Claims claims = parseToken(token);
return claims.get("userId", String.class); // 명시적 타입 변환
}
public String getStoreId(String token) {
Claims claims = parseToken(token);
return claims.get("storeId", String.class);
}
}
```
**개선사항**:
- ✅ 타입 안전성 향상
- ✅ null 처리 개선
- ✅ 토큰 파싱 로직 강화
- ✅ 에러 메시지 개선
#### 개발 환경 인증 필터
**파일**: `event-service/.../DevAuthenticationFilter.java`
**개선사항**:
- ✅ 개발 환경용 Mock 인증
- ✅ JWT 토큰 파싱 개선
- ✅ 로깅 추가
---
### 8. 테스트 및 문서화
#### 통합 테스트 보고서
**파일**: `test/content-service-integration-test-results.md` (신규, 673줄)
**내용**:
- ✅ 9개 테스트 시나리오 실행 결과
- ✅ 성공률: 100% (9/9)
- ✅ HTTP 통신 검증
- ✅ Job 관리 메커니즘 검증
- ✅ EventId 기반 조회 검증
- ✅ 이미지 재생성 기능 검증
- ✅ 성능 분석 (평균 응답 시간 < 150ms)
#### 아키텍처 분석 문서
**파일**: `test/content-service-integration-analysis.md` (신규, 504줄)
**내용**:
- ✅ content-service API 구조 분석
- ✅ Redis 기반 Job 관리 메커니즘
- ✅ Kafka 연동 현황 분석
- ✅ 서비스 간 통신 구조
- ✅ 권장사항 및 개선 방향
#### Kafka 연동 테스트 보고서
**파일**: `test/test-kafka-integration-results.md` (신규, 348줄)
**내용**:
- ✅ event-service Kafka Producer/Consumer 검증
- ✅ Kafka 브로커 연결 테스트
- ✅ 메시지 발행/수신 검증
- ✅ Manual Acknowledgment 패턴 검증
- ✅ content-service Kafka Consumer 미구현 확인
#### API 테스트 결과
**파일**: `test/API-TEST-RESULT.md` (이동)
**내용**:
- ✅ 기존 API 테스트 결과
- ✅ test/ 폴더로 이동하여 정리
#### 테스트 자동화 스크립트
**파일**:
- `test-content-service.sh` (신규, 82줄)
- `run-content-service.sh` (신규, 80줄)
- `run-content-service.bat` (신규, 81줄)
**기능**:
- ✅ content-service 자동 테스트
- ✅ 서버 실행 스크립트 (Linux/Windows)
- ✅ 7가지 테스트 시나리오 자동 실행
- ✅ Health Check 및 API 검증
#### 테스트 데이터
**파일**:
- `test-integration-event.json`
- `test-integration-objective.json`
- `test-integration-ai-request.json`
- `test-image-generation.json`
- `test-ai-recommendation.json`
**목적**:
- ✅ 통합 테스트용 샘플 데이터
- ✅ API 테스트 자동화
- ✅ 재현 가능한 테스트 환경
---
### 9. 실행 환경 설정
#### IntelliJ 실행 프로파일 업데이트
**파일**:
- `.run/ContentServiceApplication.run.xml`
- `.run/AiServiceApplication.run.xml`
**변경사항**:
```xml
<envs>
<env name="SERVER_PORT" value="8084" />
<env name="REDIS_HOST" value="20.214.210.71" />
<env name="REDIS_PORT" value="6379" />
<env name="REDIS_PASSWORD" value="Hi5Jessica!" />
<env name="DB_HOST" value="4.217.131.139" />
<env name="DB_PORT" value="5432" />
<env name="REPLICATE_MOCK_ENABLED" value="true" />
<!-- JWT, Azure 설정 추가 -->
</envs>
```
**개선사항**:
- ✅ 환경 변수 명시적 설정
- ✅ Mock Mode 설정 추가
- ✅ 데이터베이스 연결 정보 명시
---
## 🔍 Kafka 아키텍처 현황
### 현재 구현된 아키텍처
```
┌─────────────────┐
│ event-service │
│ (Port 8081) │
└────────┬────────┘
├─── Kafka Producer ───→ Kafka Topic (image-generation-job)
│ │
│ │ (event-service Consumer가 수신)
│ ↓
│ ┌──────────────┐
│ │ event-service│
│ │ Consumer │
│ └──────────────┘
└─── Redis Job Data ───→ Redis Cache
┌───────┴────────┐
│ content-service│
│ (Port 8084) │
└────────────────┘
```
### 주요 발견사항
- ⚠️ **content-service에는 Kafka Consumer 미구현**
- ✅ Redis 기반 Job 관리로 서비스 간 통신
- ✅ event-service에서 Producer/Consumer 모두 구현
- ⚠️ 논리 아키텍처 설계와 실제 구현 불일치
### 권장사항
1. **단기**: 설계 문서를 실제 구현에 맞춰 업데이트
2. **중기**: API 문서 자동화 (Swagger/OpenAPI)
3. **장기**: content-service에 Kafka Consumer 추가 구현
---
## 📊 성능 및 품질 지표
### API 응답 시간
```
Health Check: < 50ms
GET 요청: 50-100ms
POST 요청: 100-150ms
```
### Job 처리 시간 (Mock Mode)
```
이미지 4개 생성: ~0.2초
이미지 1개 재생성: ~0.1초
```
### 테스트 성공률
```
통합 테스트: 100% (9/9 성공)
Kafka 연동: 100% (event-service)
API 엔드포인트: 100% (전체 정상)
```
### 코드 품질
```
추가된 코드: 2,795줄
제거된 코드: 222줄
순 증가: 2,573줄
변경된 파일: 60개
```
---
## 🚀 배포 준비 상태
### ✅ 완료된 작업
- [x] EventId/JobId 생성 로직 구현
- [x] Kafka 메시지 구조 개선
- [x] 데이터베이스 스키마 정의
- [x] content-service 통합 테스트 완료
- [x] API 문서화 및 테스트 보고서 작성
- [x] 테스트 자동화 스크립트 작성
### ⏳ 진행 예정 작업
- [ ] content-service Kafka Consumer 구현 (옵션)
- [ ] 프로덕션 환경 데이터베이스 마이그레이션
- [ ] Swagger/OpenAPI 문서 자동화
- [ ] 성능 모니터링 도구 설정
- [ ] 로그 수집 및 분석 시스템 구축
### ⚠️ 주의사항
1. **데이터베이스 마이그레이션**: 프로덕션 배포 전 백업 필수
2. **Kafka 메시지 호환성**: 기존 Consumer가 있다면 메시지 형식 변경 영향 확인
3. **ID 형식 변경**: 기존 데이터와의 호환성 검토 필요
4. **환경 변수**: 모든 환경에서 필요한 환경 변수 설정 확인
---
## 📝 주요 커밋 히스토리
```
3465a35 Merge branch 'feature/event' into develop
8ff79ca 테스트 결과 파일들을 test/ 폴더로 이동
336d811 content-service 통합 테스트 완료 및 보고서 작성
ee941e4 Event-AI Kafka 연동 개선 및 메시지 필드명 camelCase 변경
b71d27a 비즈니스 친화적 eventId 및 jobId 생성 로직 구현
34291e1 백엔드 서비스 구조 개선 및 데이터베이스 스키마 추가
```
---
## 🔗 관련 문서
1. **테스트 보고서**
- `test/content-service-integration-test-results.md`
- `test/test-kafka-integration-results.md`
- `test/API-TEST-RESULT.md`
2. **아키텍처 문서**
- `test/content-service-integration-analysis.md`
3. **데이터베이스**
- `develop/database/schema/create_event_tables.sql`
- `develop/database/migration/alter_event_id_to_varchar.sql`
4. **테스트 스크립트**
- `test-content-service.sh`
- `run-content-service.sh`
- `run-content-service.bat`
---
**작성자**: Backend Developer
**검토자**: System Architect
**최종 업데이트**: 2025-10-30 01:40
+1 -1
View File
@@ -20,7 +20,7 @@ data:
EXCLUDE_REDIS: ""
# CORS Configuration
CORS_ALLOWED_ORIGINS: "http://localhost:8081,http://localhost:8082,http://localhost:8083,http://localhost:8084,http://kt-event-marketing.20.214.196.128.nip.io"
CORS_ALLOWED_ORIGINS: "http://localhost:8081,http://localhost:8082,http://localhost:8083,http://localhost:8084,http://kt-event-marketing.20.214.196.128.nip.io,http://kt-event-marketing-api.20.214.196.128.nip.io,http://*.20.214.196.128.nip.io,https://kt-event-marketing.20.214.196.128.nip.io,https://kt-event-marketing-api.20.214.196.128.nip.io,https://*.20.214.196.128.nip.io"
CORS_ALLOWED_METHODS: "GET,POST,PUT,DELETE,OPTIONS,PATCH"
CORS_ALLOWED_HEADERS: "*"
CORS_ALLOW_CREDENTIALS: "true"
@@ -39,7 +39,7 @@ public class OpenApiConfig {
.email("support@kt-event-marketing.com")))
.servers(List.of(
new Server()
.url("http://localhost:8085")
.url("http://localhost:8085/api/v1/distribution")
.description("Local Development Server"),
new Server()
.url("https://dev-api.kt-event-marketing.com/distribution/v1")
@@ -48,7 +48,7 @@ public class OpenApiConfig {
.url("https://api.kt-event-marketing.com/distribution/v1")
.description("Production Server"),
new Server()
.url("http://kt-event-marketing-api.20.214.196.128.nip.io/api/v1")
.url("http://kt-event-marketing-api.20.214.196.128.nip.io/api/v1/distribution")
.description("VM Development Server")
));
}
@@ -18,8 +18,8 @@ import org.springframework.web.bind.annotation.*;
/**
* Distribution Controller
* POST api/v1/distribution/distribute - 다중 채널 배포 실행
* GET api/v1/distribution/{eventId}/status - 배포 상태 조회
* POST /distribute - 다중 채널 배포 실행
* GET /{eventId}/status - 배포 상태 조회
*
* @author System Architect
* @since 2025-10-23
@@ -123,6 +123,15 @@ channel:
url: ${KAKAO_API_URL:http://localhost:9006/api/kakao}
timeout: 10000
# Naver Blog Configuration (Playwright 기반)
naver:
blog:
username: ${NAVER_BLOG_USERNAME:}
password: ${NAVER_BLOG_PASSWORD:}
blog-id: ${NAVER_BLOG_ID:}
headless: ${NAVER_BLOG_HEADLESS:true}
session-path: ${NAVER_BLOG_SESSION_PATH:playwright-sessions}
# Springdoc OpenAPI (Swagger)
springdoc:
api-docs:
+38
View File
@@ -0,0 +1,38 @@
apiVersion: v1
kind: Service
metadata:
annotations:
kubectl.kubernetes.io/last-applied-configuration: |
{"apiVersion":"v1","kind":"Service","metadata":{"annotations":{},"labels":{"app":"participation-service","app.kubernetes.io/managed-by":"kustomize","app.kubernetes.io/part-of":"kt-event-marketing","environment":"dev"},"name":"participation-service","namespace":"kt-event-marketing"},"spec":{"ports":[{"name":"http","port":80,"protocol":"TCP","targetPort":8084}],"selector":{"app":"participation-service","app.kubernetes.io/managed-by":"kustomize","app.kubernetes.io/part-of":"kt-event-marketing","environment":"dev"},"type":"ClusterIP"}}
creationTimestamp: "2025-10-28T08:59:06Z"
labels:
app: participation-service
app.kubernetes.io/managed-by: kustomize
app.kubernetes.io/part-of: kt-event-marketing
environment: dev
name: participation-service
namespace: kt-event-marketing
resourceVersion: "125107611"
uid: da5b7f82-37d3-41bd-ad87-e2864c8bcd18
spec:
clusterIP: 10.0.130.146
clusterIPs:
- 10.0.130.146
internalTrafficPolicy: Cluster
ipFamilies:
- IPv4
ipFamilyPolicy: SingleStack
ports:
- name: http
port: 80
protocol: TCP
targetPort: 8084
selector:
app: participation-service
app.kubernetes.io/managed-by: kustomize
app.kubernetes.io/part-of: kt-event-marketing
environment: dev
sessionAffinity: None
type: ClusterIP
status:
loadBalancer: {}
+27
View File
@@ -0,0 +1,27 @@
apiVersion: v1
kind: Service
metadata:
labels:
app: participation-service
app.kubernetes.io/managed-by: kustomize
app.kubernetes.io/part-of: kt-event-marketing
environment: dev
name: participation-service
namespace: kt-event-marketing
spec:
clusterIP: 10.0.130.146
clusterIPs:
- 10.0.130.146
internalTrafficPolicy: Cluster
ipFamilies:
- IPv4
ipFamilyPolicy: SingleStack
ports:
- name: http
port: 80
protocol: TCP
targetPort: 8084
selector:
app: participation-service
sessionAffinity: None
type: ClusterIP
@@ -1,17 +1,13 @@
package com.kt.event.participation.infrastructure.config;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityCustomizer;
import org.springframework.security.config.annotation.web.configurers.AbstractHttpConfigurer;
import org.springframework.security.config.http.SessionCreationPolicy;
import org.springframework.security.web.SecurityFilterChain;
import org.springframework.web.cors.CorsConfiguration;
import org.springframework.web.cors.CorsConfigurationSource;
import org.springframework.web.cors.UrlBasedCorsConfigurationSource;
import java.util.Arrays;
/**
* Security Configuration for Participation Service
@@ -24,43 +20,31 @@ import java.util.Arrays;
@EnableWebSecurity
public class SecurityConfig {
@Value("${cors.allowed-origins:http://localhost:*}")
private String allowedOrigins;
@Bean
public SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception {
http
.csrf(csrf -> csrf.disable())
.cors(cors -> cors.configurationSource(corsConfigurationSource()))
.sessionManagement(session -> session.sessionCreationPolicy(SessionCreationPolicy.STATELESS))
.authorizeHttpRequests(auth -> auth
// Actuator endpoints
.requestMatchers("/actuator/**").permitAll()
.anyRequest().permitAll()
);
// CSRF 비활성화 (REST API는 CSRF 불필요)
.csrf(AbstractHttpConfigurer::disable)
// 세션 사용 안 함 (JWT 기반 인증)
.sessionManagement(session ->
session.sessionCreationPolicy(SessionCreationPolicy.STATELESS)
)
// 모든 요청 허용 (테스트용)
.authorizeHttpRequests(auth -> auth
.anyRequest().permitAll()
);
return http.build();
}
/**
* Chrome DevTools 요청 등 정적 리소스 요청을 Spring Security에서 제외
*/
@Bean
public CorsConfigurationSource corsConfigurationSource() {
CorsConfiguration configuration = new CorsConfiguration();
String[] origins = allowedOrigins.split(",");
configuration.setAllowedOriginPatterns(Arrays.asList(origins));
configuration.setAllowedMethods(Arrays.asList("GET", "POST", "PUT", "DELETE", "PATCH", "OPTIONS"));
configuration.setAllowedHeaders(Arrays.asList(
"Authorization", "Content-Type", "X-Requested-With", "Accept",
"Origin", "Access-Control-Request-Method", "Access-Control-Request-Headers"
));
configuration.setAllowCredentials(true);
configuration.setMaxAge(3600L);
UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
source.registerCorsConfiguration("/**", configuration);
return source;
public WebSecurityCustomizer webSecurityCustomizer() {
return (web) -> web.ignoring()
.requestMatchers("/.well-known/**");
}
}
@@ -0,0 +1,32 @@
package com.kt.event.participation.infrastructure.config;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
/**
* Web Configuration
* CORS 설정 및 기타 웹 관련 설정
*
* @author System Architect
* @since 2025-10-30
*/
@Configuration
public class WebConfig implements WebMvcConfigurer {
/**
* CORS 설정
* - 모든 origin 허용 (개발 환경)
* - 모든 HTTP 메서드 허용
* - Credentials 허용
*/
@Override
public void addCorsMappings(CorsRegistry registry) {
registry.addMapping("/**")
.allowedOriginPatterns("*")
.allowedMethods("GET", "POST", "PUT", "DELETE", "PATCH", "OPTIONS")
.allowedHeaders("*")
.allowCredentials(true)
.maxAge(3600);
}
}
@@ -1,104 +0,0 @@
package com.kt.event.participation.presentation.controller;
import com.kt.event.participation.domain.participant.Participant;
import com.kt.event.participation.domain.participant.ParticipantRepository;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;
import java.util.List;
/**
* 디버깅용 컨트롤러
*/
@Slf4j
@CrossOrigin(origins = "http://localhost:3000")
@RestController
@RequestMapping("/debug")
@RequiredArgsConstructor
public class DebugController {
private final ParticipantRepository participantRepository;
/**
* 중복 참여 체크 테스트
*/
@GetMapping("/exists/{eventId}/{phoneNumber}")
public String testExists(@PathVariable String eventId, @PathVariable String phoneNumber) {
try {
log.info("디버그: 중복 체크 시작 - eventId: {}, phoneNumber: {}", eventId, phoneNumber);
boolean exists = participantRepository.existsByEventIdAndPhoneNumber(eventId, phoneNumber);
log.info("디버그: 중복 체크 결과 - exists: {}", exists);
long totalCount = participantRepository.count();
long eventCount = participantRepository.countByEventId(eventId);
return String.format(
"eventId: %s, phoneNumber: %s, exists: %s, totalCount: %d, eventCount: %d",
eventId, phoneNumber, exists, totalCount, eventCount
);
} catch (Exception e) {
log.error("디버그: 예외 발생", e);
return "ERROR: " + e.getMessage();
}
}
/**
* 모든 참여자 데이터 조회
*/
@GetMapping("/participants")
public String getAllParticipants() {
try {
List<Participant> participants = participantRepository.findAll();
StringBuilder sb = new StringBuilder();
sb.append("Total participants: ").append(participants.size()).append("\n\n");
for (Participant p : participants) {
sb.append(String.format("ID: %s, EventID: %s, Phone: %s, Name: %s\n",
p.getParticipantId(), p.getEventId(), p.getPhoneNumber(), p.getName()));
}
return sb.toString();
} catch (Exception e) {
log.error("디버그: 참여자 조회 예외 발생", e);
return "ERROR: " + e.getMessage();
}
}
/**
* 특정 전화번호의 참여 이력 조회
*/
@GetMapping("/phone/{phoneNumber}")
public String getByPhoneNumber(@PathVariable String phoneNumber) {
try {
List<Participant> participants = participantRepository.findAll();
StringBuilder sb = new StringBuilder();
sb.append("Participants with phone: ").append(phoneNumber).append("\n\n");
int count = 0;
for (Participant p : participants) {
if (phoneNumber.equals(p.getPhoneNumber())) {
sb.append(String.format("ID: %s, EventID: %s, Name: %s\n",
p.getParticipantId(), p.getEventId(), p.getName()));
count++;
}
}
if (count == 0) {
sb.append("No participants found with this phone number.");
}
return sb.toString();
} catch (Exception e) {
log.error("디버그: 전화번호별 조회 예외 발생", e);
return "ERROR: " + e.getMessage();
}
}
}
@@ -35,9 +35,9 @@ public class ParticipationController {
/**
* 이벤트 참여
* POST /events/{eventId}/participate
* POST /participations/{eventId}/participate
*/
@PostMapping("/events/{eventId}/participate")
@PostMapping("/participations/{eventId}/participate")
public ResponseEntity<ApiResponse<ParticipationResponse>> participate(
@PathVariable String eventId,
@Valid @RequestBody ParticipationRequest request) {
@@ -61,14 +61,15 @@ public class ParticipationController {
/**
* 참여자 목록 조회
* GET /events/{eventId}/participants
* GET /participations/{eventId}/participants
* GET /events/{eventId}/participants (프론트엔드 호환)
*/
@Operation(
summary = "참여자 목록 조회",
description = "이벤트의 참여자 목록을 페이징하여 조회합니다. " +
"정렬 가능한 필드: createdAt(기본값), participantId, name, phoneNumber, bonusEntries, isWinner, wonAt"
)
@GetMapping("/events/{eventId}/participants")
@GetMapping({"/participations/{eventId}/participants", "/events/{eventId}/participants"})
public ResponseEntity<ApiResponse<PageResponse<ParticipationResponse>>> getParticipants(
@Parameter(description = "이벤트 ID", example = "evt_20250124_001")
@PathVariable String eventId,
@@ -89,9 +90,10 @@ public class ParticipationController {
/**
* 참여자 상세 조회
* GET /events/{eventId}/participants/{participantId}
* GET /participations/{eventId}/participants/{participantId}
* GET /events/{eventId}/participants/{participantId} (프론트엔드 호환)
*/
@GetMapping("/events/{eventId}/participants/{participantId}")
@GetMapping({"/participations/{eventId}/participants/{participantId}", "/events/{eventId}/participants/{participantId}"})
public ResponseEntity<ApiResponse<ParticipationResponse>> getParticipant(
@PathVariable String eventId,
@PathVariable String participantId) {
@@ -35,9 +35,9 @@ public class WinnerController {
/**
* 당첨자 추첨
* POST /events/{eventId}/draw-winners
* POST /participations/{eventId}/draw-winners
*/
@PostMapping("/events/{eventId}/draw-winners")
@PostMapping("/participations/{eventId}/draw-winners")
public ResponseEntity<ApiResponse<DrawWinnersResponse>> drawWinners(
@PathVariable String eventId,
@Valid @RequestBody DrawWinnersRequest request) {
@@ -50,14 +50,14 @@ public class WinnerController {
/**
* 당첨자 목록 조회
* GET /events/{eventId}/winners
* GET /participations/{eventId}/winners
*/
@Operation(
summary = "당첨자 목록 조회",
description = "이벤트의 당첨자 목록을 페이징하여 조회합니다. " +
"정렬 가능한 필드: winnerRank(기본값), wonAt, participantId, name, phoneNumber, bonusEntries"
)
@GetMapping("/events/{eventId}/winners")
@GetMapping("/participations/{eventId}/winners")
public ResponseEntity<ApiResponse<PageResponse<ParticipationResponse>>> getWinners(
@Parameter(description = "이벤트 ID", example = "evt_20250124_001")
@PathVariable String eventId,
@@ -56,7 +56,7 @@ jwt:
# CORS 설정
cors:
allowed-origins: ${CORS_ALLOWED_ORIGINS:http://localhost:8081,http://localhost:8082,http://localhost:8083,http://localhost:8084,http://kt-event-marketing.20.214.196.128.nip.io}
allowed-origins: ${CORS_ALLOWED_ORIGINS:*}
allowed-methods: ${CORS_ALLOWED_METHODS:GET,POST,PUT,DELETE,OPTIONS,PATCH}
allowed-headers: ${CORS_ALLOWED_HEADERS:*}
allow-credentials: ${CORS_ALLOW_CREDENTIALS:true}
@@ -98,4 +98,14 @@ management:
livenessState:
enabled: true
readinessState:
enabled: true
enabled: true
# OpenAPI Documentation
springdoc:
api-docs:
path: /v3/api-docs
swagger-ui:
path: /swagger-ui.html
tags-sorter: alpha
operations-sorter: alpha
show-actuator: false
+4
View File
@@ -12,6 +12,10 @@ dependencies {
// OpenFeign for external API calls (사업자번호 검증)
implementation 'org.springframework.cloud:spring-cloud-starter-openfeign'
// Flyway for database migration
implementation 'org.flywaydb:flyway-core'
implementation 'org.flywaydb:flyway-database-postgresql'
// H2 Database for development
runtimeOnly 'com.h2database:h2'
@@ -38,6 +38,18 @@ public class SecurityConfig {
@Value("${cors.allowed-origins:http://localhost:*}")
private String allowedOrigins;
@Value("${cors.allowed-methods:GET,POST,PUT,DELETE,OPTIONS,PATCH}")
private String allowedMethods;
@Value("${cors.allowed-headers:*}")
private String allowedHeaders;
@Value("${cors.allow-credentials:true}")
private boolean allowCredentials;
@Value("${cors.max-age:3600}")
private long maxAge;
@Bean
public SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
return http
@@ -45,8 +57,8 @@ public class SecurityConfig {
.cors(cors -> cors.configurationSource(corsConfigurationSource()))
.sessionManagement(session -> session.sessionCreationPolicy(SessionCreationPolicy.STATELESS))
.authorizeHttpRequests(auth -> auth
// Public endpoints
.requestMatchers("/api/v1/users/register", "/api/v1/users/login").permitAll()
// Public endpoints (context-path가 /api/v1/users이므로 상대 경로 사용)
.requestMatchers("/register", "/login").permitAll()
// Actuator endpoints
.requestMatchers("/actuator/**").permitAll()
// Swagger UI endpoints
@@ -65,24 +77,23 @@ public class SecurityConfig {
public CorsConfigurationSource corsConfigurationSource() {
CorsConfiguration configuration = new CorsConfiguration();
// 환경변수에서 허용할 Origin 패턴 설정
String[] origins = allowedOrigins.split(",");
configuration.setAllowedOriginPatterns(Arrays.asList(origins));
// application.yml에서 설정한 Origin 목록 사용
configuration.setAllowedOrigins(Arrays.asList(allowedOrigins.split(",")));
// 허용할 HTTP 메소드
configuration.setAllowedMethods(Arrays.asList("GET", "POST", "PUT", "DELETE", "PATCH", "OPTIONS"));
configuration.setAllowedMethods(Arrays.asList(allowedMethods.split(",")));
// 허용할 헤더
configuration.setAllowedHeaders(Arrays.asList(
"Authorization", "Content-Type", "X-Requested-With", "Accept",
"Origin", "Access-Control-Request-Method", "Access-Control-Request-Headers"
));
configuration.setAllowedHeaders(Arrays.asList(allowedHeaders.split(",")));
// 자격 증명 허용
configuration.setAllowCredentials(true);
configuration.setAllowCredentials(allowCredentials);
// Pre-flight 요청 캐시 시간
configuration.setMaxAge(3600L);
configuration.setMaxAge(maxAge);
// Exposed Headers 추가
configuration.setExposedHeaders(Arrays.asList("Authorization", "Content-Type", "X-Total-Count"));
UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
source.registerCorsConfiguration("/**", configuration);
@@ -26,10 +26,13 @@ public class SwaggerConfig {
return new OpenAPI()
.info(apiInfo())
.addServersItem(new Server()
.url("http://localhost:8081")
.url("http://kt-event-marketing-api.20.214.196.128.nip.io/api/v1/users")
.description("Production Server (AKS Ingress)"))
.addServersItem(new Server()
.url("http://localhost:8081/api/v1/users")
.description("Local Development"))
.addServersItem(new Server()
.url("{protocol}://{host}:{port}")
.url("{protocol}://{host}:{port}/api/v1/users")
.description("Custom Server")
.variables(new io.swagger.v3.oas.models.servers.ServerVariables()
.addServerVariable("protocol", new io.swagger.v3.oas.models.servers.ServerVariable()
@@ -33,7 +33,7 @@ import java.util.UUID;
*/
@Slf4j
@RestController
@RequestMapping("/api/v1/users")
@RequestMapping("") // context-path가 /api/v1/users이므로 빈 문자열 사용
@RequiredArgsConstructor
@Tag(name = "User", description = "사용자 인증 및 프로필 관리 API")
public class UserController {
@@ -31,7 +31,13 @@ spring:
use_sql_comments: true
dialect: ${JPA_DIALECT:org.hibernate.dialect.PostgreSQLDialect}
hibernate:
ddl-auto: ${DDL_AUTO:update}
ddl-auto: ${DDL_AUTO:validate}
# Flyway Configuration
flyway:
enabled: ${FLYWAY_ENABLED:true}
baseline-on-migrate: ${FLYWAY_BASELINE:true}
locations: classpath:db/migration
# Auto-configuration exclusions for development without external services
autoconfigure:
@@ -76,7 +82,7 @@ jwt:
# CORS Configuration
cors:
allowed-origins: ${CORS_ALLOWED_ORIGINS:http://localhost:8081,http://localhost:8082,http://localhost:8083,http://localhost:8084,http://kt-event-marketing.20.214.196.128.nip.io}
allowed-origins: ${CORS_ALLOWED_ORIGINS:http://localhost:8081,http://localhost:8082,http://localhost:8083,http://localhost:8084,http://kt-event-marketing.20.214.196.128.nip.io,http://kt-event-marketing-api.20.214.196.128.nip.io,http://*.kt-event-marketing-api.20.214.196.128.nip.io,http://*.20.214.196.128.nip.io}
allowed-methods: ${CORS_ALLOWED_METHODS:GET,POST,PUT,DELETE,OPTIONS,PATCH}
allowed-headers: ${CORS_ALLOWED_HEADERS:*}
allow-credentials: ${CORS_ALLOW_CREDENTIALS:true}
@@ -0,0 +1,45 @@
-- Migration script to change user_id from BIGINT to UUID
-- WARNING: This will delete all existing data in users and stores tables
-- Make sure to backup your data before running this script!
-- Step 1: Drop dependent tables/constraints
DROP TABLE IF EXISTS stores CASCADE;
DROP TABLE IF EXISTS users CASCADE;
-- Step 2: Create users table with UUID
CREATE TABLE users (
user_id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
name VARCHAR(50) NOT NULL,
phone_number VARCHAR(20) NOT NULL UNIQUE,
email VARCHAR(100) NOT NULL UNIQUE,
password_hash VARCHAR(255) NOT NULL,
role VARCHAR(20) NOT NULL DEFAULT 'OWNER',
status VARCHAR(20) NOT NULL DEFAULT 'ACTIVE',
last_login_at TIMESTAMP,
created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
updated_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP
);
-- Step 3: Create indexes on users table
CREATE UNIQUE INDEX idx_user_phone ON users(phone_number);
CREATE UNIQUE INDEX idx_user_email ON users(email);
-- Step 4: Create stores table with UUID foreign key
CREATE TABLE stores (
store_id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
name VARCHAR(100) NOT NULL,
industry VARCHAR(50),
address VARCHAR(255) NOT NULL,
business_hours VARCHAR(255),
user_id UUID NOT NULL,
created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
updated_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
CONSTRAINT fk_stores_user FOREIGN KEY (user_id) REFERENCES users(user_id) ON DELETE CASCADE
);
-- Step 5: Create index on stores table
CREATE INDEX idx_stores_user ON stores(user_id);
-- Enable UUID extension if not already enabled
CREATE EXTENSION IF NOT EXISTS "uuid-ossp";
CREATE EXTENSION IF NOT EXISTS "pgcrypto";
@@ -0,0 +1,45 @@
-- Migration script V002: Change user_id and store_id from BIGINT to UUID
-- WARNING: This will delete all existing data in users and stores tables
-- Make sure to backup your data before running this script!
-- Step 1: Drop dependent tables/constraints
DROP TABLE IF EXISTS stores CASCADE;
DROP TABLE IF EXISTS users CASCADE;
-- Step 2: Create users table with UUID
CREATE TABLE users (
user_id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
name VARCHAR(50) NOT NULL,
phone_number VARCHAR(20) NOT NULL UNIQUE,
email VARCHAR(100) NOT NULL UNIQUE,
password_hash VARCHAR(255) NOT NULL,
role VARCHAR(20) NOT NULL DEFAULT 'OWNER',
status VARCHAR(20) NOT NULL DEFAULT 'ACTIVE',
last_login_at TIMESTAMP,
created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
updated_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP
);
-- Step 3: Create indexes on users table
CREATE UNIQUE INDEX idx_user_phone ON users(phone_number);
CREATE UNIQUE INDEX idx_user_email ON users(email);
-- Step 4: Create stores table with UUID foreign key
CREATE TABLE stores (
store_id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
name VARCHAR(100) NOT NULL,
industry VARCHAR(50),
address VARCHAR(255) NOT NULL,
business_hours VARCHAR(255),
user_id UUID NOT NULL,
created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
updated_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
CONSTRAINT fk_stores_user FOREIGN KEY (user_id) REFERENCES users(user_id) ON DELETE CASCADE
);
-- Step 5: Create index on stores table
CREATE INDEX idx_stores_user ON stores(user_id);
-- Enable UUID extension if not already enabled
CREATE EXTENSION IF NOT EXISTS "uuid-ossp";
CREATE EXTENSION IF NOT EXISTS "pgcrypto";