Skip to content

[Phase 2] spring analysis apis - #39

Merged
HOKAGO-MEMORIES merged 2 commits into
developfrom
phase/2-spring-analysis-apis
Jun 23, 2026
Merged

[Phase 2] spring analysis apis#39
HOKAGO-MEMORIES merged 2 commits into
developfrom
phase/2-spring-analysis-apis

Conversation

@HOKAGO-MEMORIES

@HOKAGO-MEMORIES HOKAGO-MEMORIES commented Jun 23, 2026

Copy link
Copy Markdown
Contributor

변경 내용

  • 매물 실거래가 비교 API 추가: GET /api/v1/properties/{propertyId}/transactions
  • 매물 안전 요약 API 추가: GET /api/v1/properties/{propertyId}/safety-summary
  • 지역/건물 시세 분석 API 추가: GET /api/v1/price-analysis
  • property_score_stat 운영 마이그레이션 추가
  • F-4 캐시 조회용 DTO/DAO/서비스/컨트롤러 구현
  • API/도메인/DB 문서 업데이트

연결 이슈

closes #38

테스트

  • backend: .\mvnw.cmd -Dtest=PropertyControllerTest,PriceAnalysisControllerTest test
  • backend: .\mvnw.cmd test
  • git diff --check

Summary by CodeRabbit

  • New Features

    • Price analysis: Added GET /api/v1/price-analysis to compare regional and building price statistics by property type and transaction type.
    • Transaction history: Added GET /api/v1/properties/{propertyId}/transactions to view past transactions for a property.
    • Safety summary: Added GET /api/v1/properties/{propertyId}/safety-summary to view safety metrics and nearby infrastructure counts.
  • Bug Fixes

    • Improved handling of validation errors by returning a consistent invalid-request response.
  • Documentation

    • Updated API spec examples and response schemas for the new endpoints.

@HOKAGO-MEMORIES HOKAGO-MEMORIES added the ai-generated Created by AI harness automation label Jun 23, 2026
@coderabbitai

coderabbitai Bot commented Jun 23, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: e4574a8d-7086-4ac1-838c-8c64914cf106

📥 Commits

Reviewing files that changed from the base of the PR and between 778e9f7 and cf746ed.

📒 Files selected for processing (7)
  • backend/src/main/java/com/ssafy/salmanhae/common/exception/GlobalExceptionHandler.java
  • backend/src/main/java/com/ssafy/salmanhae/controller/price/PriceAnalysisController.java
  • backend/src/main/java/com/ssafy/salmanhae/controller/property/PropertyController.java
  • backend/src/main/java/com/ssafy/salmanhae/service/property/PropertyServiceImpl.java
  • backend/src/test/java/com/ssafy/salmanhae/controller/price/PriceAnalysisControllerTest.java
  • backend/src/test/java/com/ssafy/salmanhae/controller/property/PropertyControllerTest.java
  • backend/src/test/resources/schema.sql
🚧 Files skipped from review as they are similar to previous changes (5)
  • backend/src/main/java/com/ssafy/salmanhae/controller/price/PriceAnalysisController.java
  • backend/src/test/java/com/ssafy/salmanhae/controller/property/PropertyControllerTest.java
  • backend/src/main/java/com/ssafy/salmanhae/controller/property/PropertyController.java
  • backend/src/test/resources/schema.sql
  • backend/src/main/java/com/ssafy/salmanhae/service/property/PropertyServiceImpl.java

📝 Walkthrough

Walkthrough

Three new REST endpoints are added to the property backend: GET /api/v1/properties/{id}/transactions, GET /api/v1/properties/{id}/safety-summary, and GET /api/v1/price-analysis. These are backed by five new response DTOs, four new PropertyDao query methods implemented in JdbcPropertyDao, and three new PropertyService methods. A new property_score_stat DB table and migration are included, along with updated test schema, seed data, integration tests, and API documentation.

Changes

Property Analysis APIs

Layer / File(s) Summary
Response DTO contracts
backend/src/main/java/com/ssafy/salmanhae/model/dto/property/PropertyTransactionResponse.java, backend/src/main/java/com/ssafy/salmanhae/model/dto/property/PropertySafetySummaryResponse.java, backend/src/main/java/com/ssafy/salmanhae/model/dto/property/RegionPriceStatResponse.java, backend/src/main/java/com/ssafy/salmanhae/model/dto/property/BuildingPriceStatResponse.java, backend/src/main/java/com/ssafy/salmanhae/model/dto/property/PriceAnalysisResponse.java
Five new Java records define response shapes for transactions, safety summary, and price statistics. PriceAnalysisResponse uses a compact constructor to ensure regionStats and buildingStats are never null.
DAO interface and JDBC implementation
backend/src/main/java/com/ssafy/salmanhae/model/dao/property/PropertyDao.java, backend/src/main/java/com/ssafy/salmanhae/model/dao/property/JdbcPropertyDao.java
PropertyDao gains four new query method declarations. JdbcPropertyDao implements them with inline SQL (match-ranked transaction lookup, safety summary fetch, region/building price-stat queries), private row mappers for each new DTO, and a formatYearMonth helper.
Service interface and implementation
backend/src/main/java/com/ssafy/salmanhae/service/property/PropertyService.java, backend/src/main/java/com/ssafy/salmanhae/service/property/PropertyServiceImpl.java
PropertyService declares getTransactions, getSafetySummary, and getPriceAnalysis. PropertyServiceImpl adds parameter defaulting, validation (throwing INVALID_REQUEST), fallback construction for missing safety data, and a private getActiveProperty helper that throws PROPERTY_NOT_FOUND.
Exception handling for validation
backend/src/main/java/com/ssafy/salmanhae/common/exception/GlobalExceptionHandler.java
GlobalExceptionHandler adds ConstraintViolationException to the bad-request handler list so parameter-validation failures return INVALID_REQUEST responses.
REST controllers
backend/src/main/java/com/ssafy/salmanhae/controller/price/PriceAnalysisController.java, backend/src/main/java/com/ssafy/salmanhae/controller/property/PropertyController.java
New PriceAnalysisController exposes GET /api/v1/price-analysis with validated legalDongCode, propertyType, and transactionType parameters. PropertyController gains GET /{propertyId}/transactions and GET /{propertyId}/safety-summary with optional year/radius parameters, both delegating to PropertyService and wrapping results in ApiResponse.
DB migration and infrastructure
database/migrations/202606230003_create_property_score_stat.sql, database/README.md
Migration creates property_score_stat table with safety/price scores, nearby facility counts, and an updated_at trigger. README documents the new migration order and data-loading pipeline targets.
Test database schema and seed data
backend/src/test/resources/schema.sql, backend/src/test/resources/data.sql
Test schema.sql adds DDL for all four new tables with foreign-key constraints; data.sql seeds transaction_history, property_score_stat, region_price_stat, and building_price_stat with representative rows.
Integration tests
backend/src/test/java/com/ssafy/salmanhae/controller/price/PriceAnalysisControllerTest.java, backend/src/test/java/com/ssafy/salmanhae/controller/property/PropertyControllerTest.java
PriceAnalysisControllerTest and six new cases in PropertyControllerTest cover success, 404 (missing property), and validation-error (invalid params) paths for all three endpoints.
Documentation
docs/07_DOMAIN_MODEL.md, docs/08_API_SPEC.md
Domain model doc updates region_price_stat schema with decomposed region fields and median statistics; API spec adds response examples for transactions, safety-summary, and price-analysis endpoints.

Sequence Diagram(s)

sequenceDiagram
  participant Client
  participant PropertyController
  participant PriceAnalysisController
  participant PropertyServiceImpl
  participant PropertyDao
  participant DB

  Client->>PropertyController: GET /{propertyId}/transactions?years=3
  PropertyController->>PropertyServiceImpl: getTransactions(propertyId, years)
  PropertyServiceImpl->>PropertyDao: findActiveById(propertyId)
  PropertyDao->>DB: SELECT from properties
  DB-->>PropertyDao: PropertyRow
  PropertyDao-->>PropertyServiceImpl: Optional<PropertyRow>
  PropertyServiceImpl->>PropertyDao: findComparableTransactions(property, minContractYearMonth)
  PropertyDao->>DB: SELECT from transaction_history (match_rank, LIMIT 20)
  DB-->>PropertyDao: rows
  PropertyDao-->>PropertyServiceImpl: List<PropertyTransactionResponse>
  PropertyServiceImpl-->>PropertyController: list
  PropertyController-->>Client: ApiResponse<ListResponse>

  Client->>PropertyController: GET /{propertyId}/safety-summary?radius=500
  PropertyController->>PropertyServiceImpl: getSafetySummary(propertyId, radius)
  PropertyServiceImpl->>PropertyDao: findSafetySummary(propertyId, radius)
  PropertyDao->>DB: SELECT from property_score_stat
  DB-->>PropertyDao: Optional row
  PropertyDao-->>PropertyServiceImpl: Optional<PropertySafetySummaryResponse>
  PropertyServiceImpl-->>PropertyController: PropertySafetySummaryResponse (or default)
  PropertyController-->>Client: ApiResponse<PropertySafetySummaryResponse>

  Client->>PriceAnalysisController: GET /price-analysis?legalDongCode=...&propertyType=...&transactionType=...
  PriceAnalysisController->>PropertyServiceImpl: getPriceAnalysis(legalDongCode, propertyType, transactionType)
  PropertyServiceImpl->>PropertyDao: findRegionPriceStats(...)
  PropertyDao->>DB: SELECT from region_price_stat
  DB-->>PropertyDao: List<RegionPriceStatResponse>
  PropertyServiceImpl->>PropertyDao: findBuildingPriceStats(...)
  PropertyDao->>DB: SELECT from building_price_stat (LIMIT 20)
  DB-->>PropertyDao: List<BuildingPriceStatResponse>
  PropertyServiceImpl-->>PriceAnalysisController: PriceAnalysisResponse
  PriceAnalysisController-->>Client: ApiResponse<PriceAnalysisResponse>
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~60 minutes

Possibly related PRs

  • ssafy-salman/salmanhae#10: Extends the same Phase-1 property API layer (PropertyController/PropertyService/PropertyDao) with new property-specific endpoints (transactions/safety/price-analysis) on top of the existing /api/v1/properties list/detail structure.

Poem

🐇 Hippity-hoppity, new APIs appear,
Transactions and safety now crystal clear!
Price stats by region and building in view,
With triggers and records all shiny and new.
The rabbit has mapped every schema with care—
ApiResponse.ok() floats gently through air! 🎉

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title '[Phase 2] spring analysis apis' clearly summarizes the main change - the implementation of Phase 2 spring analysis APIs with three new REST endpoints for property market analysis.
Description check ✅ Passed The PR description covers all key changes (three new APIs, database migration, DTO/DAO/service/controller implementation, documentation updates) and follows the template structure with completed test verification.
Linked Issues check ✅ Passed The PR implementation aligns with the linked issue #38 requirements by delivering three REST endpoints (transaction comparison, safety summary, price analysis), database infrastructure, complete stack implementation (DTO/DAO/service/controller), and comprehensive test coverage.
Out of Scope Changes check ✅ Passed All code changes are directly aligned with the Phase 2 spring analysis APIs objectives. The GlobalExceptionHandler update for ConstraintViolationException is a necessary supporting change for validation in the new endpoints.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch phase/2-spring-analysis-apis

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 4

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In
`@backend/src/main/java/com/ssafy/salmanhae/controller/price/PriceAnalysisController.java`:
- Around line 24-29: The getPriceAnalysis method in PriceAnalysisController is
deferring validation of the legalDongCode parameter to the service layer, which
violates the project guideline that controllers should handle input validation
at the boundary. Add validation logic or validation annotations (such as
`@NotBlank` or `@NotNull`) for the legalDongCode parameter directly in the
getPriceAnalysis method to ensure invalid input is rejected at the controller
layer before delegation to the propertyService.getPriceAnalysis call.

In
`@backend/src/main/java/com/ssafy/salmanhae/controller/property/PropertyController.java`:
- Around line 68-82: Add input validation constraints to the controller
parameters in both getPropertyTransactions and getPropertySafetySummary methods.
Use validation annotations such as `@NotNull` and `@Positive` (or `@Min/`@Max as
appropriate) on the propertyId `@PathVariable` parameter to ensure it is a valid
positive number, and on the years and radius `@RequestParam` parameters to enforce
appropriate numeric bounds. This ensures the controller layer owns boundary
validation rather than delegating it to the service layer, following the stated
coding guideline that controller methods should handle input validation before
delegation.

In
`@backend/src/main/java/com/ssafy/salmanhae/service/property/PropertyServiceImpl.java`:
- Around line 57-64: The getSafetySummary method accepts a dynamic radius
parameter and echoes it into the response, but the underlying
propertyDao.findSafetySummary query operates on fixed-radius database columns
(cctv_count_300m, bell_count_300m, light_count_300m, police_count_500m). Enforce
validation to only accept radius values that are actually supported by the
database (300 and 500 meters). Update the radius validation logic to reject
unsupported values with an appropriate error, ensuring the response radius value
always matches what was actually queried from the database.

In `@backend/src/test/resources/schema.sql`:
- Around line 79-88: The test schema for property_score_stat table does not
match the production migration contract and is allowing invalid states to pass
in tests. Update the property_score_stat table definition in the test DDL to
include all constraints from the production migration: add the foreign key
constraint on property_id, apply proper null/default constraints to the count
fields (cctv_count_300m, bell_count_300m, light_count_300m, police_count_500m),
and add the missing created_at timestamp column. Reference the production
migration at database/migrations/202606230003_create_property_score_stat.sql to
ensure the test schema exactly matches the production contract.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 8fed3eb7-11df-4d40-9c06-6eb16ec1f938

📥 Commits

Reviewing files that changed from the base of the PR and between fd6642a and 778e9f7.

📒 Files selected for processing (19)
  • backend/src/main/java/com/ssafy/salmanhae/controller/price/PriceAnalysisController.java
  • backend/src/main/java/com/ssafy/salmanhae/controller/property/PropertyController.java
  • backend/src/main/java/com/ssafy/salmanhae/model/dao/property/JdbcPropertyDao.java
  • backend/src/main/java/com/ssafy/salmanhae/model/dao/property/PropertyDao.java
  • backend/src/main/java/com/ssafy/salmanhae/model/dto/property/BuildingPriceStatResponse.java
  • backend/src/main/java/com/ssafy/salmanhae/model/dto/property/PriceAnalysisResponse.java
  • backend/src/main/java/com/ssafy/salmanhae/model/dto/property/PropertySafetySummaryResponse.java
  • backend/src/main/java/com/ssafy/salmanhae/model/dto/property/PropertyTransactionResponse.java
  • backend/src/main/java/com/ssafy/salmanhae/model/dto/property/RegionPriceStatResponse.java
  • backend/src/main/java/com/ssafy/salmanhae/service/property/PropertyService.java
  • backend/src/main/java/com/ssafy/salmanhae/service/property/PropertyServiceImpl.java
  • backend/src/test/java/com/ssafy/salmanhae/controller/price/PriceAnalysisControllerTest.java
  • backend/src/test/java/com/ssafy/salmanhae/controller/property/PropertyControllerTest.java
  • backend/src/test/resources/data.sql
  • backend/src/test/resources/schema.sql
  • database/README.md
  • database/migrations/202606230003_create_property_score_stat.sql
  • docs/07_DOMAIN_MODEL.md
  • docs/08_API_SPEC.md

Comment thread backend/src/test/resources/schema.sql
@HOKAGO-MEMORIES
HOKAGO-MEMORIES merged commit 97c9ad0 into develop Jun 23, 2026
1 check passed
@HOKAGO-MEMORIES
HOKAGO-MEMORIES deleted the phase/2-spring-analysis-apis branch June 25, 2026 07:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ai-generated Created by AI harness automation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Phase 2] spring analysis apis

1 participant