Skip to content

stella.choi be 과제 제출#12

Open
choiyoorim wants to merge 16 commits into
ej31:mainfrom
choiyoorim:feature
Open

stella.choi be 과제 제출#12
choiyoorim wants to merge 16 commits into
ej31:mainfrom
choiyoorim:feature

Conversation

@choiyoorim

@choiyoorim choiyoorim commented Feb 16, 2025

Copy link
Copy Markdown

🏷 Stock 주식 정보 제공 API

🚀 Spring Boot 기반의 주식 종가 조회 API
✅ RESTful API 설계 | ✅ MySQL 연동 | ✅ JPA 및 Query 최적화 | ✅ Swagger API 문서화


📌 프로젝트 개요

Stock 주식 정보 제공 API는 특정 기업의 주식 종가 데이터를 조회하는 기능을 제공합니다.
JPA와 MySQL을 활용하여 데이터를 관리하며, API Key 기반의 인증을 적용하였습니다.
또한, Swagger를 사용하여 API 문서를 자동 생성하여 편리한 테스트 환경을 제공합니다.


📌 기술 스택

Backend

  • Framework: Spring Boot 3.x
  • Language: Java 17
  • Database: MySQL
  • ORM: JPA
  • Documentation: Swagger (SpringDoc OpenAPI)

Dependencies

dependencies {
    implementation 'org.springframework.boot:spring-boot-starter'
    implementation 'org.springframework.boot:spring-boot-starter-web'
    implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
    implementation 'mysql:mysql-connector-java:8.0.33'
    implementation 'org.projectlombok:lombok:1.18.28'
    annotationProcessor 'org.projectlombok:lombok:1.18.28'
    implementation 'org.springdoc:springdoc-openapi-starter-webmvc-ui:2.2.0'
    testImplementation 'org.springframework.boot:spring-boot-starter-test'
}
라이브러리 설명 및 선택 이유
spring-boot-starter Spring Boot의 핵심 라이브러리로, 자동 설정 및 애플리케이션 실행 지원
spring-boot-starter-web REST API 개발을 위한 Spring MVC 포함
spring-boot-starter-data-jpa JPA(Hibernate)를 활용한 객체-관계형 매핑(ORM) 지원
mysql:mysql-connector-java:8.0.33 MySQL 데이터베이스와의 연동을 위한 JDBC 드라이버
org.projectlombok:lombok @Getter, @Setter, @AllArgsConstructor 등 반복적인 코드 생성을 줄이는 라이브러리
springdoc-openapi-starter-webmvc-ui:2.2.0 Swagger UI를 통해 API 문서를 자동 생성하고 테스트 가능하도록 설정
spring-boot-starter-test 단위 테스트 및 통합 테스트를 위한 JUnit, Mockito 등의 테스트 환경 제공

** 현재 테스트 코드는 시간상 도입 못해서 나중에 수정 예정

📌 API 명세서 (Swagger UI)
API 명세는 Swagger OpenAPI를 통해 제공되며, 실행 후 다음 URL에서 확인 가능합니다.
🔗 Swagger UI

📌 특별히 신경 쓴 부분
📍 1. RESTful API 설계
✅ URI를 리소스 중심으로 설계 (/api/v1/stock/history) -> 이후 stock 관련 기능 추가를 고려해 history로 한번 더 분리
✅ HTTP 메서드를 의미에 맞게 사용 (GET은 조회, POST는 생성)

📍 2. API Key 보안 강화
✅ 하드코딩된 API Key 제거 → application.yml에서 환경 변수로 관리
@value("${api.key}")를 사용하여 API Key를 동적으로 주입
✅ 인증 실패 시 403 Forbidden 응답 반환

📍 3. 예외 처리 (GlobalExceptionHandler 적용)
✅ @RestControllerAdvice를 활용하여 예외를 중앙에서 관리
✅ API 요청 검증 (필수 파라미터 누락, 날짜 형식 오류 등)을 ErrorCode Enum과 함께 구조화
✅ 일관된 에러 응답 포맷 유지

📍 4. 계층형 아키텍처 구현 (Layered Architecture 적용)
✅ Controller - Service - Repository 계층 분리하여 역할별 책임을 명확히 구분
✅ Controller: 클라이언트 요청을 처리하고 응답을 반환
✅ Service: 비즈니스 로직을 수행하고, 데이터 검증 및 변환 처리
✅ Repository: 데이터베이스와의 직접적인 연결 및 CRUD 수행 (JPA 활용)
✅ DTO (Data Transfer Object) 도입

📌 트러블슈팅 (문제 해결 과정)

문제 해결 방법
JPA와 Native Query 조인 문제 JPQL에서 DTO(new DTO(...))를 사용하여 해결
API Key를 하드코딩하면 보안 취약 application.yml에서 관리하도록 변경 (@value 활용)
Entity를 그대로 반환하여 데이터 과다 노출 문제 DTO(StockHistoryResponse)를 도입하여 필요한 데이터만 반환하도록 수정

@choiyoorim choiyoorim changed the title [1차] 과제 제출 stella.choi be 과제 제출 Feb 16, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant