Skip to content

josibak/Walk-Library

Repository files navigation

πŸ“– ν”„λ‘ νŠΈμ—”λ“œ & 이미지 생성 κΈ°λŠ₯ μš”μ•½ (React + OpenAI)

πŸ“‚ ν”„λ‘œμ νŠΈ ꡬ쑰 μš”μ•½

πŸ“† src
 β”œ πŸ“ components       // μž¬μ‚¬μš© κ°€λŠ₯ν•œ UI contribute
 β”œ πŸ“ pages            // λΌμš°νŠΈμ™€ λ§€ν•‘λ˜λŠ” μ£Όμš” νŽ˜μ΄μ§€
 β”œ πŸ“ routes           // React Router μ„€μ •
 β”œ πŸ“ services         // API 톡신 및 μ™ΈλΆ€ μ„œλΉ„μŠ€
 β”” πŸ—Ύ App.jsx          // 루트 contribute


🌐 Router ꡬ쑰 μš”μ•½ (Router.jsx)

React Routerλ₯Ό μ‚¬μš©ν•œ SPA(Single Page Application) λΌμš°νŠΈμž…λ‹ˆλ‹€.

πŸ“Œ μ£Όμš” 라우트

건데 μ„€λͺ…
/ β†’ /login μ ‘κ·Ό μ‹œ 둜그인 νŽ˜μ΄μ§€λ‘œ redirection
/home 메인 ν™ˆ νŽ˜μ΄μ§€
/books 전체 λ„μ„œ λͺ©λ‘
/books/:id νŠΉμ • λ„μ„œ 상세
/create λ„μ„œ 생성
/edit/:id λ„μ„œ νŽΈμ§‘
/my μ‚¬μš©μžκ°€ λ“±λ‘ν•œ λ„μ„œ
/ai-cover AI 컀버 이미지 생성 νŽ˜μ΄μ§€

πŸ“Œ Navigateλ₯Ό μ‚¬μš©ν•˜μ—¬ /둜 μ ‘κ·Ό μ‹œ /login으둜 redirection 처리


🎨 AI 이미지 생성 κΈ°λŠ₯ (services/imageGenerator.js)

OpenAI의 DALLΒ·E λͺ¨λΈμ„ μ‚¬μš©ν•΄ ν…μŠ€νŠΈ ν”„λ‘¬ν”„νŠΈλ‘œ 컀버 이미지λ₯Ό μƒμ„±ν•©λ‹ˆλ‹€.

πŸ”§ μ£Όμš” ν•¨μˆ˜

export async function generateImageFromPrompt(apiKey, prompt, model, quality, style, size)

νŒŒλΌλ―Έν„° μ„€λͺ…
apiKey OpenAI API ν‚€
prompt 이미지 생성 ν”„λ‘ ν”„νŠΈ
model μ‚¬μš© λͺ¨λΈ (dall-e-3, dall-e-2)
quality standard or hd (dall-e-3 μ „μš©)
style vivid or natural (dall-e-3 μ „μš©)
size 이미지 크기 (κΈ°λ³Έ: 1024x1024)

βœ… μ£Όμš” νŠΉμ§•

  • dall-e-3κ³Ό dall-e-2의 API μŠ€ν… 차이λ₯Ό λ°˜μ˜ν•˜μ—¬ μ˜΅μ…˜ 동적 μ„€μ •
  • 응닡 데이터가 μ—†κ±°λ‚˜ 였λ₯˜ μ‹œ μ˜ˆμ™Έ 처리
  • μœ νš¨ν•˜μ§€ μ•Šμ€ μ‚¬μ΄μ¦ˆ μš”μ²­ μ‹œ κΈ°λ³Έκ°’μœΌλ‘œ μžλ™ λ³€κ²½

πŸ’‘ μ‚¬μš© μ˜ˆμ‹œ

const url = await generateImageFromPrompt(
  OPENAI_API_KEY,
  'A fantasy-style magical book cover with dragons and castles'
);


πŸ”„ 전체 데이터 Process μ˜ˆμ‹œ

πŸ“† μ‚¬μš©μž
   └── [둜그인]
       └── /home β†’ /create
            └── [ν”„λ‘ ν”„νŠΈ μž…λ ₯ + generateImageFromPrompt 호좜]
                └── OpenAI API 호좜
                    └── 이미지 URL λ°˜ν™˜
                        └── 컀버 이미지 미리보기 및 μ €μž₯


πŸ§ͺ μ˜ˆμ™Έ 처리 및 보완사항

  • 이미지 응닡 였λ₯˜ μ‹œ throw new Error(...)둜 μ˜ˆμ™Έ λ°œμƒ β†’ ν”„λ‘¬ν”„νŠΈμ—μ„œ Toast Notification λ“± 처리 ν•„μš”
  • API KeyλŠ” .env 등을 톡해 λ³΄μ•ˆ 관리 ꢌμž₯

βœ… ν–₯ν›„ 계정 아이디어

  • ν”„λ‘ ν”„νŠΈ μΆ”μ²œ κΈ°λŠ₯ μΆ”κ°€ (μž₯λ₯΄ 기반 μžλ™ μ œμ•ˆ)
  • μ‚¬μš©μž 생성 이미지 μ €μž₯ 이λ ₯ 쑰회 κΈ°λŠ₯
  • 생성 이미지 μˆ˜μ • μ˜΅μ…˜ (re-roll, μ—…μŠ€μΌ€μΌ λ“±)

πŸš€ 의쑴 기술

기술 μ„€λͺ…
React UI ν”„λ ˆμž„μ›Œν¬
React Router DOM SPA 라우트 관리
fetch API 이미지 μƒμ„±μš© OpenAI API μš”μ²­
OpenAI DALLΒ·E ν…μŠ€νŠΈ-이미지 생성 λͺ¨λΈ

BackEnd

🚦 Controller & Config μš”μ•½

πŸ”§ WebConfig.java

Spring MVC μ„€μ • 클래슀.

μ£Όμš” μ—­ν• :

  • CORS 섀정을 톡해 **React ν”„λ‘ νŠΈμ—”λ“œ(포트 3000)**μ—μ„œμ˜ μš”μ²­ ν—ˆμš©
πŸ“Œ ν—ˆμš© 도메인: <http://localhost:3000>
πŸ“Œ ν—ˆμš© λ©”μ„œλ“œ: GET, POST, PUT, PATCH, DELETE, OPTIONS
πŸ“Œ allowCredentials: true


πŸ“š BookController.java

/api/books 경둜둜 λ„μ„œ κ΄€λ ¨ API 제곡.

HTTP URL κΈ°λŠ₯
POST /api/books λ„μ„œ 등둝
GET /api/books 전체 λ„μ„œ λͺ©λ‘ 쑰회
GET /api/books/{id} νŠΉμ • λ„μ„œ 상세 쑰회
PUT /api/books/{id} λ„μ„œ 정보 μˆ˜μ •
DELETE /api/books/{id} λ„μ„œ μ‚­μ œ

기타 νŠΉμ§•:

  • @CrossOrigin으둜 CORS ν—ˆμš© (localhost:3000)
  • BookService에 μ‹€μ œ 둜직 μœ„μž„

πŸ‘€ UserController.java

/api/users 경둜둜 μ‚¬μš©μž κ΄€λ ¨ API 제곡.

HTTP URL κΈ°λŠ₯
POST /api/users μ‚¬μš©μž 등둝
GET /api/users 전체 μ‚¬μš©μž 쑰회
POST /api/users/login μ‚¬μš©μž 둜그인 (이메일/λΉ„λ°€λ²ˆν˜Έ 기반)

기타 νŠΉμ§•:

  • LoginFailedException μ˜ˆμ™Έ λ°œμƒ μ‹œ 401 응닡 처리
  • UserServiceλ₯Ό 톡해 μ‚¬μš©μž 둜직 처리
  • 응닡 μ‹œ UserResponseDto, UserLoginResponseDto μ‚¬μš©

βœ… DTO μ„€λͺ… (Data Transfer Object)

λ„μ„œ 및 μ‚¬μš©μž κ΄€λ ¨ 데이터λ₯Ό μš”μ²­ν•˜κ±°λ‚˜ 응닡할 λ•Œ μ‚¬μš©ν•˜λŠ” κ°μ²΄μž…λ‹ˆλ‹€. Controller ↔ Service ↔ Entity κ°„ 데이터 전달에 μ‚¬μš©λ©λ‹ˆλ‹€.


πŸ“˜ User κ΄€λ ¨ DTO

  • UserRequestDto

    μ‚¬μš©μž 등둝 μš”μ²­μ— μ‚¬μš©.

    ν•„λ“œ: username, email, password

  • UserResponseDto

    μ‚¬μš©μž 정보 응닡에 μ‚¬μš©.

    ν•„λ“œ: userId, username, email

  • UserLoginResponseDto

    둜그인 응닡 μ‹œ μ‚¬μš©.

    ν•„λ“œ: token (JWT λ“±), user (UserResponseDto)


πŸ“˜ Book κ΄€λ ¨ DTO

  • BookRequestDto

    λ„μ„œ 등둝/μˆ˜μ • μš”μ²­μ— μ‚¬μš©.

    ν•„λ“œ: title, description, coverImageUrl, userId

  • BookResponseDto

    λ„μ„œ 정보 응닡에 μ‚¬μš©.

    ν•„λ“œ: id, title, description, coverImageUrl, createdAt, updatedAt, userId, username


⚠️ Error DTO

  • ErrorResponse

    μ—λŸ¬ 응닡 포맷.

    ν•„λ“œ: code (HTTP μƒνƒœ μ½”λ“œ), status (error λ“±), message (μ—λŸ¬ λ©”μ‹œμ§€)

🧩 μ„œλΉ„μŠ€ λ ˆμ΄μ–΄ ꡬ쑰 μš”μ•½ (Service Layer Structure Summary)

πŸ“ BookService.java

  • μ—­ν• : λ„μ„œ κ΄€λ ¨ λΉ„μ¦ˆλ‹ˆμŠ€ 둜직 처리
  • μ£Όμš” λ©”μ„œλ“œ:
    • createBook(BookRequestDto dto): λ„μ„œ 등둝 (userIdλ₯Ό λ°›μ•„ Users와 μ—°κ΄€ μ§€μŒ)
    • getAllBooks(): λͺ¨λ“  λ„μ„œ 쑰회
    • getBook(Long id): 단일 λ„μ„œ 상세 쑰회
    • updateBook(Long id, BookRequestDto dto): λ„μ„œ μˆ˜μ •
    • deleteBook(Long id): λ„μ„œ μ‚­μ œ
  • νŠΉμ§•:
    • BookRepository와 UserRepositoryλ₯Ό ν™œμš©
    • DTO ↔ Entity λ³€ν™˜
    • Users와 Book κ°„μ˜ μ—°κ΄€ 관계 λ§€ν•‘ μ‚¬μš©

πŸ“ UserService.java

  • μ—­ν• : μ‚¬μš©μž κ΄€λ ¨ λΉ„μ¦ˆλ‹ˆμŠ€ 둜직 처리
  • μ£Όμš” λ©”μ„œλ“œ:
    • createUser(UserRequestDto dto): μ‚¬μš©μž νšŒμ›κ°€μž…
    • getAllUsers(): 전체 μ‚¬μš©μž λͺ©λ‘ 쑰회
    • login(UserRequestDto dto): μ‚¬μš©μž 둜그인 (λ‹¨μˆœ 둜그인 둜직 / JWT 미포함)
  • νŠΉμ§•:
    • μ‚¬μš©μž 인증 처리 (μ‹€νŒ¨ μ‹œ LoginFailedException λ°œμƒ)
    • μ‚¬μš©μž 정보 응닡 μ‹œ UserResponseDto μ‚¬μš©

🧩 μ—”ν‹°ν‹° 관계 μš”μ•½ (Entities)

πŸ“˜ Book

  • @ManyToOne β†’ Users (λ„μ„œλ₯Ό μž‘μ„±ν•œ μ‚¬μš©μž)
  • ν•„λ“œ: title, description, coverImageUrl, createdAt, updatedAt

πŸ‘€ Users

  • @OneToMany(mappedBy = "user") β†’ List<Book>
  • ν•„λ“œ: username, email, password, book(λ„μ„œ λͺ©λ‘)

πŸ”— λ ˆμ΄μ–΄ κ°„ μ—°κ²° 흐름 μ˜ˆμ‹œ

πŸ“¦ Controller
   └── BookController
         └── BookService
               β”œβ”€β”€ BookRepository
               └── UserRepository (userId β†’ Users 쑰회)

πŸ“¦ Controller
   └── UserController
         └── UserService
               └── UserRepository


πŸ—‚ Repository Layer ꡬ쑰 μš”μ•½

Spring Data JPAλ₯Ό ν™œμš©ν•˜μ—¬ λ°μ΄ν„°λ² μ΄μŠ€ 접근을 μΆ”μƒν™”ν•œ Repository κ³„μΈ΅μž…λ‹ˆλ‹€. λ³΅μž‘ν•œ SQL μž‘μ„± 없이 λ©”μ„œλ“œ λ„€μ΄λ°λ§ŒμœΌλ‘œ 쿼리λ₯Ό μžλ™ 생성할 수 μžˆμŠ΅λ‹ˆλ‹€.


βœ… 1. BookRepository

  • λ„μ„œ 정보λ₯Ό κ΄€λ¦¬ν•˜λŠ” JPA Repository
  • JpaRepository<Book, Long> 상속 β†’ 기본적인 CRUD 제곡
public interface BookRepository extends JpaRepository<Book, Long> {
    // ν•„μš”μ‹œ μ»€μŠ€ν…€ 쿼리 μΆ”κ°€ κ°€λŠ₯
}

βœ… 2. UserRepository

  • μ‚¬μš©μž 정보λ₯Ό κ΄€λ¦¬ν•˜λŠ” JPA Repository
  • 이메일 기반 쑰회 κΈ°λŠ₯을 μœ„ν•œ μ»€μŠ€ν…€ λ©”μ„œλ“œ μΆ”κ°€
public interface UserRepository extends JpaRepository<Users, Long> {
    Optional<Users> findByEmail(String email);
}

πŸ“Œ κΈ°λŠ₯ μš”μ•½

λ©”μ„œλ“œ μ„€λͺ…
findByEmail(String email) μ‚¬μš©μžμ˜ 이메일을 기반으둜 Optional둜 쑰회
κΈ°λ³Έ 제곡 λ©”μ„œλ“œ findById, findAll, save, deleteById λ“±

πŸ“Œ μž₯점 μš”μ•½

  • λΉ„μ¦ˆλ‹ˆμŠ€ 둜직과 DB 둜직 뢄리
  • SQL μž‘μ„± 없이 λΉ λ₯Έ 개발 κ°€λŠ₯
  • ν•„μš”μ‹œ @Query λ˜λŠ” Querydsl둜 ν™•μž₯ κ°€λŠ₯

🧩 Service Layer ꡬ쑰 μš”μ•½

λΉ„μ¦ˆλ‹ˆμŠ€ λ‘œμ§μ„ μ²˜λ¦¬ν•˜λŠ” 핡심 κ³„μΈ΅μž…λ‹ˆλ‹€. DTOλ₯Ό 톡해 μ»¨νŠΈλ‘€λŸ¬μ™€μ˜ 데이터 흐름을 κ΄€λ¦¬ν•˜κ³ , DB 접근은 Repositoryλ₯Ό 톡해 μˆ˜ν–‰ν•©λ‹ˆλ‹€.


βœ… BookService, BookServiceImpl

πŸ“˜ μ±… CRUD + μœ μ € 연동

λ©”μ„œλ“œ μ„€λͺ…
createBook(BookRequestDto dto) μ±… 생성 (제λͺ©, μ„€λͺ…, 이미지 URL, μœ μ € ID ν•„μš”)
getAllBooks() 전체 μ±… λͺ©λ‘ 쑰회
getBook(Long id) ID둜 μ±… 쑰회
updateBook(Long id, BookRequestDto dto) μ±… 정보 μˆ˜μ •
deleteBook(Long id) μ±… μ‚­μ œ

πŸ”§ μ£Όμš” νŠΉμ§•:

  • BookRequestDto β†’ μ—”ν‹°ν‹° β†’ μ €μž₯ β†’ BookResponseDto λ³€ν™˜
  • μ±… μ €μž₯ μ‹œ μœ μ € 쑴재 μ—¬λΆ€ 확인
  • LocalDateTime.now()으둜 createdAt, updatedAt μžλ™ μ„€μ •
  • μ˜ˆμ™Έ 처리:
    • BookCreateException: μž…λ ₯ κ°’ μœ νš¨μ„± μ‹€νŒ¨
    • BookNotFoundException: ν•΄λ‹Ή ID의 책이 μ—†λŠ” 경우

βœ… UserService, UserServiceImpl

πŸ‘€ μœ μ € 쑰회 + 둜그인 (νšŒμ›κ°€μž… μ—†μŒ)

λ©”μ„œλ“œ μ„€λͺ…
getAllUsers() 전체 μœ μ € λͺ©λ‘ 쑰회
getUser(Long userId) ID둜 μœ μ € 쑰회
deleteUser(Long userId) μœ μ € μ‚­μ œ
login(UserRequestDto dto) 이메일 & νŒ¨μŠ€μ›Œλ“œ 기반 둜그인, μž„μ‹œ 토큰 λ°œκΈ‰

πŸ” 둜그인 상세:

  • μ΄λ©”μΌλ‘œ μœ μ € 쑰회 (findByEmail)
  • λΉ„λ°€λ²ˆν˜Έ 일치 μ—¬λΆ€ 확인
  • 성곡 μ‹œ UserLoginResponseDto λ°˜ν™˜ (토큰 + μœ μ € 정보)
  • μ‹€νŒ¨ μ‹œ LoginFailedException μ˜ˆμ™Έ λ°œμƒ

⚠️ 주의: νšŒμ›κ°€μž… κΈ°λŠ₯은 κ΅¬ν˜„λ˜μ–΄ μžˆμ§€ μ•ŠμœΌλ©°,

λ‘œκ·ΈμΈμ€ 사전에 DB에 μ €μž₯된 μœ μ € μ •λ³΄λ§Œμ„ 기반으둜 μž‘λ™ν•©λ‹ˆλ‹€.


✨ ꡬ쑰적 이점

  • DTO ↔ Entity λͺ…ν™• 뢄리
  • μ˜ˆμ™Έ 처리둜 μ‚¬μš©μž κ²½ν—˜ κ°œμ„ 
  • μΆ”ν›„ ν™•μž₯ 용이 (예: JWT 토큰 λ°œκΈ‰, νšŒμ›κ°€μž… μΆ”κ°€ κ°€λŠ₯)

βœ… 1. application.yml μ„€μ •

spring:
  datasource:
    url: jdbc:h2:file:~/librarytestdb
    driver-class-name: org.h2.Driver
    username: sa
    password: 1234

  jpa:
    hibernate:
      ddl-auto: create
    show-sql: true
    properties:
      hibernate:
        format_sql: true
    defer-datasource-initialization: true

  h2:
    console:
      enabled: true
      path: /h2-console

  sql:
    init:
      mode: always

server:
  port: 8081
  • H2 DB: 파일 λͺ¨λ“œ (~/librarytestdb)
  • μ›Ή μ½˜μ†” URL: http://localhost:8081/h2-console
  • 접속 정보:
    • JDBC URL: jdbc:h2:file:~/librarytestdb
    • μ‚¬μš©μžλͺ…: sa
    • λΉ„λ°€λ²ˆν˜Έ: 1234
  • JPA ddl-auto: create β†’ μ„œλ²„ μ‹€ν–‰ μ‹œ 맀번 ν…Œμ΄λΈ” μƒˆλ‘œ 생성
  • μ„œλ²„ 포트: 8081

βœ… 2. 둜그인 κΈ°λŠ₯ κ΄€λ ¨ μ£Όμ˜μ‚¬ν•­

⚠️ νšŒμ›κ°€μž… νŽ˜μ΄μ§€λŠ” μ œκ³΅ν•˜μ§€ μ•ŠμœΌλ©°,

H2 DB에 미리 λ“±λ‘λœ μœ μ € μ •λ³΄λ‘œλ§Œ 둜그인이 κ°€λŠ₯ν•©λ‹ˆλ‹€.

  • 둜그인 ν…ŒμŠ€νŠΈλ₯Ό μœ„ν•΄ resources/data.sql에 μ‚¬μš©μž 정보와 μ±… 데이터λ₯Ό 사전 μ‚½μž…ν•΄μ•Ό ν•©λ‹ˆλ‹€.
  • 직접 H2 μ½˜μ†”μ—μ„œ μ‚½μž…ν•΄λ„ κ°€λŠ₯ν•˜μ§€λ§Œ, μ΄ˆκΈ°ν™” μžλ™ν™”λ₯Ό μœ„ν•΄ data.sql μ‚¬μš©μ„ ꢌμž₯ν•©λ‹ˆλ‹€.

βœ… 3. src/main/resources/data.sql λ‚΄μš©

-- μœ μ € 데이터 μ‚½μž…
INSERT INTO users (user_id, username, email, password) VALUES
(1, 'testuser', 'test@example.com', 'password123'),
(2, 'anotheruser', 'another@example.com', 'password456');

-- λ„μ„œ 데이터 μ‚½μž…
INSERT INTO book (title, description, cover_image_url, created_at, updated_at, user_id) VALUES
('Spring Boot in Action', 'Spring Boot μ„€λͺ…μ„œ', '<https://example.com/spring.jpg>', CURRENT_TIMESTAMP, CURRENT_TIMESTAMP, 1),
('JPA with Hibernate', 'JPAλ₯Ό ν™œμš©ν•œ ORM μ„€λͺ…μ„œ', '<https://example.com/jpa.jpg>', CURRENT_TIMESTAMP, CURRENT_TIMESTAMP, 1),
('React for Beginners', 'ν”„λ‘ νŠΈμ—”λ“œ μž…λ¬Έμ„œ', '<https://example.com/react.jpg>', CURRENT_TIMESTAMP, CURRENT_TIMESTAMP, 2);
  • users ν…Œμ΄λΈ”μ˜ user_idλŠ” 직접 μ§€μ •
  • book ν…Œμ΄λΈ”μ˜ idλŠ” auto-increment라 μƒλž΅
  • 각 λ„μ„œμ˜ user_idλŠ” λ“±λ‘λœ μ‚¬μš©μžμ™€ μ—°κ΄€

⚠️ μ˜ˆμ™Έ 처리 ꡬ쑰 (Exception Handling)

λ³Έ ν”„λ‘œμ νŠΈλŠ” μ˜ˆμ™Έ 상황을 λͺ…ν™•νžˆ λΆ„λ¦¬ν•˜κ³ , μ‚¬μš©μžμ—κ²Œ 의미 μžˆλŠ” 응닡을 μ œκ³΅ν•˜κΈ° μœ„ν•΄ μ»€μŠ€ν…€ μ˜ˆμ™Έ ν΄λž˜μŠ€μ™€ **μ „μ—­ μ˜ˆμ™Έ 처리기(GlobalExceptionHandler)**λ₯Ό μ‚¬μš©ν•©λ‹ˆλ‹€.


βœ… 1. μ»€μŠ€ν…€ μ˜ˆμ™Έ 클래슀 λͺ©λ‘

μ˜ˆμ™Έ 클래슀λͺ… μ„€λͺ…
BookNotFoundException μš”μ²­ν•œ λ„μ„œλ₯Ό 찾을 수 없을 λ•Œ λ°œμƒ (404)
BookCreateException λ„μ„œ 생성 쀑 였λ₯˜κ°€ λ°œμƒν–ˆμ„ λ•Œ
CoverNotFoundException λ„μ„œ ν‘œμ§€ 이미지가 μ‘΄μž¬ν•˜μ§€ μ•Šμ„ λ•Œ
CoverGenerateException λ„μ„œ ν‘œμ§€ 생성 쀑 였λ₯˜κ°€ λ°œμƒν–ˆμ„ λ•Œ
LoginFailedException 둜그인 정보가 μΌμΉ˜ν•˜μ§€ μ•Šμ„ λ•Œ (401)
UserNotFoundException νŠΉμ • μ‚¬μš©μžλ₯Ό 찾을 수 없을 λ•Œ λ°œμƒ (404)

μ˜ˆμ‹œ μ½”λ“œ (LoginFailedException)

public class LoginFailedException extends RuntimeException {
    public LoginFailedException(String message) {
        super(message);
    }
}

βœ… 2. μ „μ—­ μ˜ˆμ™Έ 처리기: GlobalExceptionHandler

@RestControllerAdviceλ₯Ό 톡해 λͺ¨λ“  μ»¨νŠΈλ‘€λŸ¬μ—μ„œ λ°œμƒν•˜λŠ” μ˜ˆμ™Έλ₯Ό 일괄 μ²˜λ¦¬ν•©λ‹ˆλ‹€.

μ£Όμš” 처리 ν•­λͺ©

μ˜ˆμ™Έ νƒ€μž… HTTP μƒνƒœμ½”λ“œ 응닡 λ©”μ‹œμ§€ μ˜ˆμ‹œ
BookNotFoundException, UserNotFoundException 404 Not Found ν•΄λ‹Ή λ¦¬μ†ŒμŠ€κ°€ μ‘΄μž¬ν•˜μ§€ μ•ŠμŠ΅λ‹ˆλ‹€: [message]
LoginFailedException 401 Unauthorized 둜그인 μ‹€νŒ¨: [message] (직접 핸듀링 κ°€λŠ₯)
IllegalArgumentException 400 Bad Request 잘λͺ»λœ μš”μ²­μž…λ‹ˆλ‹€: [message]
κ·Έ μ™Έ λͺ¨λ“  μ˜ˆμ™Έ 500 Internal Server Error μ„œλ²„ λ‚΄λΆ€ 였λ₯˜κ°€ λ°œμƒν–ˆμŠ΅λ‹ˆλ‹€.
@ExceptionHandler(UserNotFoundException.class)
public ResponseEntity<String> handleUserNotFound(UserNotFoundException ex) {
    return ResponseEntity
            .status(HttpStatus.NOT_FOUND)
            .body("ν•΄λ‹Ή μ‚¬μš©μžκ°€ μ‘΄μž¬ν•˜μ§€ μ•ŠμŠ΅λ‹ˆλ‹€: " + ex.getMessage());
}

πŸ”Έ Note: LoginFailedException은 UserController λ‚΄λΆ€μ—μ„œ try-catch둜 μ²˜λ¦¬λ˜μ–΄ 있으며, μΆ”ν›„ μ „μ—­ μ˜ˆμ™Έ 처리기둜 μ΄λ™μ‹œν‚¬ 수 μžˆμŠ΅λ‹ˆλ‹€.


πŸ“Œ μž₯점 μš”μ•½

  • μ˜ˆμ™Έλ³„ λ©”μ‹œμ§€ 및 μƒνƒœμ½”λ“œ λͺ…ν™•ν•˜κ²Œ 관리
  • μ½”λ“œ 쀑볡 제거 및 μœ μ§€λ³΄μˆ˜ 용이
  • μ‚¬μš©μž μ€‘μ‹¬μ˜ 응닡 제곡으둜 UX ν–₯상

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors