[Feat] 카테고리 마스터 테이블과 조회 API - #14
Closed
RootToApex wants to merge 3 commits into
Closed
Conversation
테스트 클래스마다 MySQL·Redis 컨테이너 선언과 DynamicPropertySource 블록이 그대로 복사돼 있어, 도메인이 늘어나는 만큼 같은 블록도 늘어난다. IntegrationTestSupport로 옮기고 하위 테스트가 상속받게 한다. 컨테이너는 static 초기화 블록에서 직접 띄우고 내리지 않는다. @testcontainers는 컨테이너 수명을 테스트 클래스 단위로 관리해 클래스가 끝날 때마다 내렸다 다시 띄우는데, 그때 매핑 포트가 새로 잡힌다. 스프링 컨텍스트는 클래스 사이에 캐시되므로 사라진 옛 포트를 붙잡고 연결 거부가 난다. 클래스마다 컨테이너를 따로 두면 드러나지 않다가 공유하는 순간 터진다. ServiceConnection으로 접속 정보를 넘겨 url·계정·포트 수동 주입을 없앤다. 해당 애노테이션이 spring-boot-testcontainers 모듈 소속이라 의존성을 추가한다.
매물 분류를 enum이 아니라 테이블로 둔다. 카테고리는 매물 필터·가격통계·챗봇이 공유하는 축이라 값이 늘거나 표시명이 바뀔 때 배포 없이 반영돼야 한다. 대신 모든 참조는 숫자 id가 아니라 code로 한다 - 시드 id는 환경마다 달라서 id로 참조하면 로컬에서 되던 것이 운영에서 깨진다. 시드는 기동 시 code 기준 upsert로 반영한다. 로컬은 create-drop이라 재기동마다 테이블이 비고, 카테고리가 비면 매물 등록이 전부 실패한다. data.sql은 로컬에서만 돌고 운영(validate + Flyway)에서는 돌지 않아 두 환경이 갈라진다. 정의에서 빠진 분류는 삭제하지 않고 비활성으로 내린다 - 매물·통계가 참조 중이라 지우면 고아가 된다. 응답은 평면 리스트이되 대분류별로 묶어 내린다. depth와 sortOrder만으로 정렬하면 각 대분류의 첫 자식들이 한 덩어리가 되어 형제가 흩어진다. 가격통계의 categorySnapshot이 categories 부재로 항상 null이던 제약이 이 테이블로 풀린다.
DIGITAL_MOBILE을 쓰고 있었으나 카테고리 마스터의 스마트폰 code는 DIGITAL_PHONE이다. code는 매물·통계가 분류를 참조하는 불변 식별자라 정의와 어긋나면 존재하지 않는 분류를 가리키게 된다. categorySnapshot 예시의 부모도 실제 대분류인 DIGITAL로 맞춘다.
|
Important
This repository does not receive automatic reviews because it has fewer than 10 stars. ⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Plus Run ID: Comment |
Member
Author
|
브랜치 이름을 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
💡 개요
매물 분류를 담을
categories마스터 테이블과 조회 API를 추가합니다.대분류 11 / 중분류 49, 2뎁스 고정입니다.
가격통계의
categorySnapshot이 categories 테이블 부재로 항상 null이던 제약이이 PR로 풀립니다 (deferred #13).
매물(
listings) 엔티티는 이 PR 범위 밖이며 다음 PR에서 올립니다.🛠️ 작업 내용
카테고리 마스터
Category엔티티 — 2뎁스 고정, 중분류의 부모는 반드시 대분류code는 불변 업무 식별자. 모든 참조는 숫자 id가 아니라 code로 합니다(시드 id는 환경마다 달라 id로 참조하면 로컬에서만 동작합니다)
active=false로 내립니다시드
CategorySeeder(ApplicationRunner)가 기동 시 code 기준 upsertdata.sql을 쓰지 않은 이유: 로컬에서만 돌고 운영(validate + Flyway)에서는돌지 않아 두 환경이 갈라집니다
조회 API
GET /api/categories— 비로그인 허용, 활성 분류 전량id는 응답에 넣지 않습니다테스트 공통화
IntegrationTestSupport로 추출하고,기존
ApiContractTest·PriceStatisticsRepositoryTest도 상속으로 옮겼습니다@Testcontainers대신 static 초기화로 컨테이너를 띄웁니다. 클래스 단위수명 관리는 클래스마다 컨테이너를 내렸다 다시 띄워 포트가 바뀌는데,
캐시된 스프링 컨텍스트가 옛 포트를 붙잡아 연결 거부가 납니다
검증
clean build전체 테스트 59건 통과GET /api/categories200, 60건 (대분류 11 / 중분류 49)신규 0건, 갱신 60건, 행 수 변화 없음📌 참고
ETC_OTHER(기타)를 남긴 이유: 분류가 애매한 매물의 등록 경로가 필요하고,MVP 이후 상품명 기반 집계가 들어오면 카테고리 축의 한계는 해소됩니다
ddl-auto로 생성되지 않으므로, 검색 API 착수시 마이그레이션에 명시적으로 넣어야 합니다