🛒 쇼핑몰 API 서버 구축 가이드
📁 프로젝트 파일 구조
shopping-mall-api/
├── src/
│   ├── main/
│   │   ├── java/
│   │   │   └── com/
│   │   │       └── example/
│   │   │           └── shoppingmall/
│   │   │               ├── ShoppingMallApplication.java
│   │   │               ├── config/
│   │   │               │   ├── SecurityConfig.java
│   │   │               │   ├── SwaggerConfig.java
│   │   │               │   └── JwtConfig.java
│   │   │               ├── controller/
│   │   │               │   ├── AuthController.java
│   │   │               │   ├── UserController.java
│   │   │               │   ├── ProductController.java
│   │   │               │   ├── CartController.java
│   │   │               │   └── OrderController.java
│   │   │               ├── service/
│   │   │               │   ├── AuthService.java
│   │   │               │   ├── UserService.java
│   │   │               │   ├── ProductService.java
│   │   │               │   ├── CartService.java
│   │   │               │   └── OrderService.java
│   │   │               ├── repository/
│   │   │               │   ├── UserRepository.java
│   │   │               │   ├── ProductRepository.java
│   │   │               │   ├── CartRepository.java
│   │   │               │   └── OrderRepository.java
│   │   │               ├── entity/
│   │   │               │   ├── User.java
│   │   │               │   ├── Product.java
│   │   │               │   ├── Cart.java
│   │   │               │   ├── CartItem.java
│   │   │               │   ├── Order.java
│   │   │               │   └── OrderItem.java
│   │   │               ├── dto/
│   │   │               │   ├── request/
│   │   │               │   │   ├── LoginRequest.java
│   │   │               │   │   ├── RegisterRequest.java
│   │   │               │   │   ├── ProductRequest.java
│   │   │               │   │   ├── CartItemRequest.java
│   │   │               │   │   └── OrderRequest.java
│   │   │               │   └── response/
│   │   │               │       ├── ApiResponse.java
│   │   │               │       ├── AuthResponse.java
│   │   │               │       ├── ProductResponse.java
│   │   │               │       ├── CartResponse.java
│   │   │               │       └── OrderResponse.java
│   │   │               ├── security/
│   │   │               │   ├── JwtTokenProvider.java
│   │   │               │   ├── JwtAuthenticationFilter.java
│   │   │               │   └── CustomUserDetailsService.java
│   │   │               ├── exception/
│   │   │               │   ├── GlobalExceptionHandler.java
│   │   │               │   ├── CustomException.java
│   │   │               │   └── ErrorCode.java
│   │   │               └── util/
│   │   │                   └── ResponseUtil.java
│   │   └── resources/
│   │       ├── application.yml
│   │       ├── application-dev.yml
│   │       ├── application-prod.yml
│   │       └── data.sql
│   └── test/
│       └── java/
│           └── com/
│               └── example/
│                   └── shoppingmall/
│                       ├── controller/
│                       ├── service/
│                       └── repository/
├── build.gradle
├── README.md
└── docs/
    ├── api-docs.md
    └── postman/
        └── shopping-mall-api.postman_collection.json
🗄️ 데이터베이스 설계
ERD (Entity Relationship Diagram)
┌─────────────┐     ┌─────────────┐     ┌─────────────┐
│    User     │     │   Product   │     │    Cart     │
├─────────────┤     ├─────────────┤     ├─────────────┤
│ id (PK)     │     │ id (PK)     │     │ id (PK)     │
│ email       │     │ name        │     │ user_id(FK) │
│ password    │     │ description │     │ created_at  │
│ name        │     │ price       │     └─────────────┘
│ phone       │     │ stock       │           │
│ role        │     │ category    │           │
│ created_at  │     │ image_url   │           │
│ updated_at  │     │ created_at  │           │
└─────────────┘     │ updated_at  │           │
       │            └─────────────┘           │
       │                   │                 │
       │                   │                 │
       └───────┐           │     ┌───────────┘
               │           │     │
        ┌─────────────┐    │     │    ┌─────────────┐
        │    Order    │    │     │    │  CartItem   │
        ├─────────────┤    │     │    ├─────────────┤
        │ id (PK)     │    │     │    │ id (PK)     │
        │ user_id(FK) │────┘     │    │ cart_id(FK) │
        │ total_price │          │    │ product_id  │
        │ status      │          │    │ quantity    │
        │ order_date  │          │    │ created_at  │
        └─────────────┘          │    └─────────────┘
               │                 │           │
               │                 └───────────┘
               │
        ┌─────────────┐
        │  OrderItem  │
        ├─────────────┤
        │ id (PK)     │
        │ order_id(FK)│
        │ product_id  │
        │ quantity    │
        │ price       │
        └─────────────┘
🚀 개발 순서 (단계별 진행)
1단계: 프로젝트 초기 설정
- Spring Boot 프로젝트 생성
- 의존성 추가 (Spring Security, JWT, MySQL, Swagger 등)
- application.yml 설정
- 기본 패키지 구조 생성
2단계: 데이터베이스 & 엔티티 설계
- MySQL 데이터베이스 생성
- JPA 엔티티 클래스 작성
- Repository 인터페이스 생성
- 초기 데이터 설정 (data.sql)
3단계: 보안 & 인증 구현
- JWT 토큰 관련 클래스 구현
- Spring Security 설정
- 회원가입/로그인 API 구현
- 테스트 진행
4단계: 상품 관리 API
- 상품 CRUD API 구현
- 상품 목록 조회 (페이징, 정렬)
- 카테고리별 조회
- 테스트 코드 작성
5단계: 장바구니 기능
- 장바구니 추가/수정/삭제 API
- 장바구니 조회 API
- 테스트 코드 작성
6단계: 주문 관리
- 주문 생성 API
- 주문 조회 API
- 주문 상태 관리
- 테스트 코드 작성
7단계: API 문서화 & 최종 테스트
- Swagger 설정 및 API 문서 자동 생성
- Postman 컬렉션 작성
- 통합 테스트 진행
- README 문서 작성
📋 주요 의존성 (build.gradle)
dependencies {
    implementation 'org.springframework.boot:spring-boot-starter-web'
    implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
    implementation 'org.springframework.boot:spring-boot-starter-security'
    implementation 'org.springframework.boot:spring-boot-starter-validation'
    // JWT
    implementation 'io.jsonwebtoken:jjwt-api:0.11.5'
    implementation 'io.jsonwebtoken:jjwt-impl:0.11.5'
    implementation 'io.jsonwebtoken:jjwt-jackson:0.11.5'
    // MySQL
    implementation 'mysql:mysql-connector-java'
    // Swagger
    implementation 'org.springdoc:springdoc-openapi-starter-webmvc-ui:2.0.2'
    // Test
    testImplementation 'org.springframework.boot:spring-boot-starter-test'
    testImplementation 'org.springframework.security:spring-security-test'
}
🔥 핵심 구현 포인트
1. JWT 토큰 기반 인증
- 로그인 시 JWT 토큰 발급
- API 요청 시 토큰 검증
- 토큰 만료 시간 관리
2. RESTful API 설계
- 적절한 HTTP 메서드 사용
- 일관된 응답 형식
- 상태 코드 활용
3. 예외 처리
- 글로벌 예외 핸들러
- 커스텀 예외 클래스
- 사용자 친화적 에러 메시지
4. 테스트 코드
- 단위 테스트 (Service 레이어)
- 통합 테스트 (Controller 레이어)
- MockMvc 활용
📚 학습 리소스
- Spring Boot 공식 문서
- Spring Security Reference
- JWT 공식 문서
- Swagger/OpenAPI 문서
- JPA/Hibernate 가이드
Error
shopping_mall_api.pdf
openapi.json