Skip to content

[Feat] - Apple Watch 건강 데이터 연동 API 추가#176

Merged
thingineeer merged 1 commit intodevfrom
feat/health-data
Feb 22, 2026
Merged

[Feat] - Apple Watch 건강 데이터 연동 API 추가#176
thingineeer merged 1 commit intodevfrom
feat/health-data

Conversation

@thingineeer
Copy link
Contributor

@thingineeer thingineeer commented Feb 22, 2026

🔨 무슨 이슈인가요?


iOS v2.5.0에서 Apple Watch 건강 데이터를 서버에 저장/조회하는 기능 추가하려고 API 추가로 뚫었습니다

🛠 어떻게 이슈를 해결했나요?


새 테이블 (기존 테이블 변경 없음)

  • record_health_data: 러닝 기록 1건당 건강 데이터 요약 (1:0..1)
  • heart_rate_samples: 5초 간격 심박수 시계열 데이터 (1:N)

새 API (4개)

Method Path 설명
POST /api/record/{recordId}/health 건강 데이터 저장 (201)
GET /api/record/{recordId}/health 건강 데이터 상세 조회 (심박수 시계열 포함)
GET /api/health/summary?startDate=&endDate= 기간별 건강 통계
DELETE /api/record/{recordId}/health 건강 데이터 삭제 (409 복구용)

기존 API 확장 (1개)

  • GET /api/record/user 응답에 healthData (avgHeartRate, calories) 필드 추가
  • 하위 호환: 건강 데이터 없으면 healthData: null → 기존 앱 정상 동작

설계 원칙

  • 기존 records 테이블 변경 ZERO — 별도 테이블로 분리 (1:0..1)
  • 2-step 저장 — 러닝 기록 저장 후 Watch 데이터 도착 시 별도 저장
  • LEFT JOIN 조회 — 건강 데이터 없는 기록도 정상 조회
  • 소유권 검증 — 모든 health API에서 record 소유자 확인 (403)
  • 중복 방지 — 동일 record에 중복 저장 시 409 반환
  • 심박수 샘플 제한 — 최대 5,000건 (악의적 요청 방어)

파일 구조

health/
├── controller/HealthController.java
├── service/HealthService.java
├── entity/
│   ├── RecordHealthData.java
│   └── HeartRateSample.java
├── repository/
│   ├── RecordHealthDataRepository.java
│   └── HeartRateSampleRepository.java
└── dto/
    ├── request/
    │   ├── HealthDataRequestDto.java
    │   └── HeartRateSampleRequestDto.java
    └── response/
        ├── CreateHealthDataResponseDto.java
        ├── GetHealthDataResponseDto.java
        └── GetHealthSummaryResponseDto.java

⚠️ 주의할 점이 있나요?


  • Records는 hard delete 사용 → ON DELETE CASCADE 정상 동작
  • GET /api/record/{recordId}/health에서 건강 데이터 없으면 200 + null 반환 (404 아님)
  • maxHeartRateConfig 미전송 시 기본값 190 적용 (서비스 레이어에서 처리)
  • 날짜 범위 쿼리: endDate 당일 포함을 위해 endDate + 1일 00:00:00 미만으로 처리
  • HTTPS 전환은 별도 작업 필요 (건강 데이터 = 민감 개인정보)

- RecordHealthData, HeartRateSample 엔티티 및 리포지토리 추가
- POST /api/record/{recordId}/health (건강 데이터 저장)
- GET /api/record/{recordId}/health (건강 데이터 상세 조회)
- GET /api/health/summary (기간별 건강 통계)
- DELETE /api/record/{recordId}/health (건강 데이터 삭제)
- GET /api/record/user 응답에 healthData 필드 추가 (하위 호환)
@thingineeer thingineeer merged commit 0b649e8 into dev Feb 22, 2026
1 of 2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant