Skip to content

PARADOX-BSSM/windeath44.server.nofitication

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Notification API

FastAPI 기반의 알림 관리 시스템입니다. MySQL 데이터베이스를 사용하여 알림 CRUD 기능을 제공합니다.

기술 스택

  • FastAPI: 웹 프레임워크
  • SQLAlchemy 2.0: ORM
  • MySQL: 데이터베이스
  • PyMySQL: MySQL 드라이버
  • Pydantic: 데이터 검증

프로젝트 구조

notification/
├── main.py                     # FastAPI 애플리케이션 진입점
├── requirements.txt            # 의존성 목록
├── .env.example               # 환경변수 예시
├── api/                       # API 라우터
│   └── notification_router.py
├── app/                       # 비즈니스 로직
│   └── notification/
│       ├── model/            # SQLAlchemy 모델
│       │   └── notification.py
│       ├── schema/           # Pydantic 스키마
│       │   └── notification_schema.py
│       ├── repository/       # 데이터 접근 레이어
│       │   └── notification_repository.py
│       └── service/          # 비즈니스 로직 레이어
│           └── notification_service.py
└── core/                      # 핵심 설정
    └── database.py           # 데이터베이스 설정

설치 및 실행

1. 가상환경 활성화 및 의존성 설치

# 가상환경이 이미 있는 경우
source .venv/bin/activate  # Mac/Linux
# .venv\Scripts\activate  # Windows

# 의존성 설치
pip install -r requirements.txt

2. 환경변수 설정

.env.example을 참고하여 .env 파일을 생성합니다:

cp .env .env

.env 파일에서 데이터베이스 연결 정보를 수정합니다:

DATABASE_URL=mysql+pymysql://user:password@localhost:3306/notification_db

3. MySQL 데이터베이스 생성

CREATE DATABASE notification_db CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;

4. 서버 실행

# main.py 실행
python main.py

# 또는 uvicorn 직접 실행
uvicorn main:app --reload --host 0.0.0.0 --port 8000

서버가 실행되면 다음 URL에서 확인할 수 있습니다:

API 엔드포인트

1. 알림 생성

POST /notifications/
Content-Type: application/json

{
  "writer_id": "user123",
  "title": "알림 제목",
  "content": "알림 내용"
}

2. 알림 조회

GET /notifications/{notification_id}

3. 알림 목록 조회

GET /notifications/?skip=0&limit=100

4. 작성자별 알림 조회

GET /notifications/writer/{writer_id}?skip=0&limit=100

5. 알림 수정

PUT /notifications/{notification_id}
Content-Type: application/json

{
  "title": "수정된 제목",
  "content": "수정된 내용"
}

6. 알림 삭제

DELETE /notifications/{notification_id}

7. 알림 통계

# 전체 개수
GET /notifications/stats/count

# 작성자별 개수
GET /notifications/stats/count?writer_id=user123

데이터베이스 스키마

Notification 테이블

컬럼명 타입 설명
notification_id BIGINT 알림 ID (Primary Key, Auto Increment)
writer_id VARCHAR(255) 작성자 ID
title VARCHAR(255) 알림 제목
content TEXT 알림 내용
created_at DATETIME 생성 시간 (자동)
updated_at DATETIME 수정 시간 (자동)

테스트

API 문서 페이지(http://localhost:8000/docs)에서 대화형으로 테스트할 수 있습니다.

또는 curl을 사용한 예시:

# 알림 생성
curl -X POST "http://localhost:8000/notifications/" \
  -H "Content-Type: application/json" \
  -d '{
    "writer_id": "user123",
    "title": "테스트 알림",
    "content": "테스트 내용입니다."
  }'

# 알림 조회
curl -X GET "http://localhost:8000/notifications/1"

개발

코드 스타일

  • Python 3.13+
  • Type hints 사용
  • SQLAlchemy 2.0+ 스타일 (Mapped, mapped_column)

레이어 구조

  1. API Layer (api/): HTTP 요청/응답 처리
  2. Service Layer (service/): 비즈니스 로직
  3. Repository Layer (repository/): 데이터베이스 접근
  4. Model Layer (model/): 데이터베이스 모델

라이선스

MIT

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors