Skip to content

fix: 약 복용 알림 로직 업데이트#179

Merged
Neibce merged 1 commit intomainfrom
be/fix/pill-reminder-logic
Aug 21, 2025
Merged

fix: 약 복용 알림 로직 업데이트#179
Neibce merged 1 commit intomainfrom
be/fix/pill-reminder-logic

Conversation

@Neibce
Copy link
Owner

@Neibce Neibce commented Aug 21, 2025

Summary by CodeRabbit

  • 새로운 기능

    • 복약 알림을 시간대별로 정밀하게 판별해 발송합니다.
    • 이미 발송된 알림을 기록해 중복 발송을 방지합니다.
    • 알림 메시지 본문을 보강해 더 명확한 안내를 제공합니다.
  • 버그 수정

    • 예정 시간 이전에 잘못 발송되던 알림을 방지했습니다.
    • 동일 시각에 중복으로 도착하던 알림을 줄였습니다.
    • 복약 항목 삭제 시 관련 알림 기록도 함께 정리되어 잔여 알림이 남지 않도록 했습니다.

@coderabbitai
Copy link

coderabbitai bot commented Aug 21, 2025

Walkthrough

새 JPA 엔티티 PillAlarmRecord와 해당 리포지토리를 추가하고, PillService에 알림 전송 로직을 LocalDate/LocalTime 기반으로 재구성했습니다. 스케줄러에서 알림 중복을 PillAlarmRecord로 제어하며, 삭제 시 PillIntakeRecord와 PillAlarmRecord를 함께 정리합니다. 알림 전송/로그 처리도 갱신되었습니다.

Changes

Cohort / File(s) Change Summary
엔티티 추가 (알림 기록)
backend/ongi/src/main/java/ongi/pill/entity/PillAlarmRecord.java
새 엔티티 PillAlarmRecord 추가. Pill와 다대일 연관, 날짜/시간(LocalDate/LocalTime) 저장, pill_id+alarm_date+alarm_time 유니크 제약 설정, BaseEntity 상속 및 Lombok 적용.
리포지토리 추가 (알림 기록용)
backend/ongi/src/main/java/ongi/pill/repository/PillAlarmRecordRepository.java
Spring Data JPA 리포지토리 추가. 존재 여부 확인 existsByPillAndAlarmDateAndAlarmTime, pill 기준 일괄 삭제 deleteByPill 제공.
서비스 로직 개편 (알림/삭제 흐름)
backend/ongi/src/main/java/ongi/pill/service/PillService.java
PillAlarmRecord/Repository 주입. 스케줄러에서 복수 intakeTime에 대해 shouldSendAlarm 판단 후 전송 및 기록. recordAlarmSent로 중복 방지. findMedicationsNeedAlarm 단순화. deletePill 시 PillIntakeRecord와 PillAlarmRecord 정리. LocalDate/LocalTime로 전환. @transactional 추가.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  actor Scheduler as Scheduler(cron)
  participant PillService
  participant PillRepository
  participant PillIntakeRecordRepo as PillIntakeRecordRepository
  participant PillAlarmRecordRepo as PillAlarmRecordRepository
  participant FCM as NotificationService

  Scheduler->>PillService: checkAndSendMedicationAlarms()
  PillService->>PillRepository: find pills where today ∈ intakeDays
  PillRepository-->>PillService: pills[]

  loop for each pill
    loop for each intakeTime
      PillService->>PillService: shouldSendAlarm(pill, today, time)
      rect rgba(200,230,255,0.3)
        PillService->>PillIntakeRecordRepo: existsBy(pill, today, time)?
        PillIntakeRecordRepo-->>PillService: boolean
        PillService->>PillAlarmRecordRepo: existsByPillAndAlarmDateAndAlarmTime(...)
        PillAlarmRecordRepo-->>PillService: boolean
      end
      alt shouldSendAlarm == true
        PillService->>FCM: sendPillAlarmNotification(pill, time)
        alt send success
          PillService->>PillAlarmRecordRepo: save(new PillAlarmRecord(pill, today, time))
          PillAlarmRecordRepo-->>PillService: saved
        else send failed
          PillService->>PillService: log error
        end
      else skip
        PillService->>PillService: continue
      end
    end
  end
Loading
sequenceDiagram
  autonumber
  actor User as API Caller
  participant PillService
  participant PillIntakeRecordRepo as PillIntakeRecordRepository
  participant PillAlarmRecordRepo as PillAlarmRecordRepository
  participant PillRepository

  User->>PillService: deletePill(pillId)
  PillService->>PillRepository: findById(pillId)
  PillRepository-->>PillService: pill
  par cleanup records
    PillService->>PillIntakeRecordRepo: deleteByPill(pill)
    PillService->>PillAlarmRecordRepo: deleteByPill(pill)
  end
  PillService->>PillRepository: delete(pill)
  PillRepository-->>PillService: done
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~60 minutes

Poem

토끼는 종을 톡톡, 시간표를 폴짝 폴짝!
날짜와 시각을 쪽집게처럼 딱!
중복알림? 기록장에 콕!
삭제길도 말끔히 쓸고 닦고 퐁퐁✨
오늘 약 알림, 내일도 정확! 🥕⏰


📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Free

💡 Knowledge Base configuration:

  • Jira integration is disabled
  • Linear integration is disabled

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between 7dea95b and 2a1da72.

📒 Files selected for processing (3)
  • backend/ongi/src/main/java/ongi/pill/entity/PillAlarmRecord.java (1 hunks)
  • backend/ongi/src/main/java/ongi/pill/repository/PillAlarmRecordRepository.java (1 hunks)
  • backend/ongi/src/main/java/ongi/pill/service/PillService.java (6 hunks)

Note

🎁 Summarized by CodeRabbit Free

Your organization is on the Free plan. CodeRabbit will generate a high-level summary and a walkthrough for each pull request. For a comprehensive line-by-line review, please upgrade your subscription to CodeRabbit Pro by visiting https://app.coderabbit.ai/login.

🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Join our Discord community for assistance with any issues or questions.

CodeRabbit Commands (Invoked using PR/Issue comments)

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

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Status, Documentation and Community

  • Visit our Status Page to check the current availability of CodeRabbit.
  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@Neibce Neibce merged commit 9512666 into main Aug 21, 2025
4 checks passed
@Neibce Neibce deleted the be/fix/pill-reminder-logic branch August 21, 2025 20:53
Neibce added a commit to 2025-PNU-SW-Hackathon/PNUSW-2025-OnGi-10 that referenced this pull request Aug 25, 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