콘텐츠로 이동

users/{uid}/notifications 스키마

사용자별 인앱 알림 목록. FCM 푸시와 함께 Firestore에 저장되어 히스토리/읽음 상태를 관리합니다.

저장 위치

users/{uid}/notifications/{notification_id}

notification_id는 자동 생성되는 Firestore document ID입니다. tools/fcm.py:send_notification 계열 함수에서 write 시 생성됩니다.

상태 흐름

(생성) → read=false, hidden=false
       → read=true (사용자가 읽음)
       → hidden=true (사용자가 숨김)

읽음/숨김 처리는 각각 별도 플래그이며 독립적으로 관리됩니다. 삭제는 하지 않고 hidden 플래그로 가립니다.

문서 필드

필드 타입 설명
title string 알림 제목
body string 알림 본문
type string 아이콘 카테고리 ENUM — approved | rejected | caution | warning | info
notification_type string 라우팅용 시맨틱 키 (자유 문자열, 예: company_assign_approved, site_assign_rejected, equipment_assign_approved)
read bool 읽음 여부 (기본 false)
hidden bool 숨김 여부 (기본 false)
created_at timestamp 생성 시각 (SERVER_TIMESTAMP)
read_at timestamp? 읽음 처리 시각
hidden_at timestamp? 숨김 처리 시각
data object? 알림 메타데이터 (선택, 예: {"company_id": "...", "site_id": "..."})
doc_path string? 원본 문서 경로. 예: companies/{C}/sites/{S}/suspension_works/{X}. 앱에서 푸시 탭 시 딥링크 용도

관련 엔드포인트

  • read_notifications — 읽음 처리 (login/my_info.py:_read_notifications) — notification_ids 배열로 일괄 처리
  • hide_notifications — 숨김 처리 (login/my_info.py:_hide_notifications) — notification_ids 배열로 일괄 처리

생성 경로

tools/fcm.py의 헬퍼 함수에서 Firestore 알림 문서 생성 + FCM 푸시 전송을 동시에 수행합니다.

함수 대상
send_notification(uids, ...) 지정한 UID 리스트
send_notification_to_site(company_id, site_id, ...) 현장의 members + supervisor 전체
send_notification_to_checked_in(company_id, site_id, ...) 해당 현장에 출근 중(check_out_at=null)인 사람들

FCM 푸시 전송 시 data payload에는 doc_path만 포함됩니다(딥링크용). 나머지 메타데이터는 Firestore 알림 문서에만 저장됩니다.

예시 문서

{
  "title": "[입사] 기업 입사 승인",
  "body": "건설주식회사 기업 입사가 승인되었습니다.",
  "type": "approved",
  "notification_type": "company_assign_approved",
  "read": false,
  "hidden": false,
  "data": {
    "company_id": "company_abc"
  },
  "doc_path": "companies/company_abc/members/uid_abc",
  "created_at": "2026-04-20T10:00:00Z"
}