|
| 1 | +# SNS API 서비스 다이어그램 |
| 2 | + |
| 3 | +## 전체 시스템 구조 |
| 4 | + |
| 5 | +``` |
| 6 | ++--------------------------------------------+ |
| 7 | +| FastAPI 애플리케이션 | |
| 8 | ++--------------------------------------------+ |
| 9 | +| - title: "Simple SNS API" | |
| 10 | +| - CORS 미들웨어 추가 | |
| 11 | +| - API 라우터 설정 (/api) | |
| 12 | ++--------------------------------------------+ |
| 13 | + | |
| 14 | + | 사용 |
| 15 | + v |
| 16 | ++--------------------------------------------+ |
| 17 | +| 데이터베이스 | |
| 18 | ++--------------------------------------------+ |
| 19 | +| - SQLite | |
| 20 | +| - 테이블: posts, comments, likes | |
| 21 | ++--------------------------------------------+ |
| 22 | + | |
| 23 | + | 포함 |
| 24 | + v |
| 25 | ++--------------------------------------------+ |
| 26 | +| 데이터 모델 | |
| 27 | ++--------------------------------------------+ |
| 28 | +| | | | | |
| 29 | +| v v v | |
| 30 | ++----------+ +------+ +------+ | |
| 31 | +| Post | |Comment| | Like | | |
| 32 | ++----------+ +------+ +------+ | |
| 33 | ++--------------------------------------------+ |
| 34 | + | |
| 35 | + | 구현 |
| 36 | + v |
| 37 | ++--------------------------------------------+ |
| 38 | +| API 엔드포인트 | |
| 39 | ++--------------------------------------------+ |
| 40 | +| 포스트 관련: | |
| 41 | +| - GET /api/posts | |
| 42 | +| - POST /api/posts | |
| 43 | +| - GET /api/posts/{postId} | |
| 44 | +| - PATCH /api/posts/{postId} | |
| 45 | +| - DELETE /api/posts/{postId} | |
| 46 | +| | |
| 47 | +| 댓글 관련: | |
| 48 | +| - GET /api/posts/{postId}/comments | |
| 49 | +| - POST /api/posts/{postId}/comments | |
| 50 | +| - GET /api/posts/{postId}/comments/{id} | |
| 51 | +| - PATCH /api/posts/{postId}/comments/{id} | |
| 52 | +| - DELETE /api/posts/{postId}/comments/{id}| |
| 53 | +| | |
| 54 | +| 좋아요 관련: | |
| 55 | +| - POST /api/posts/{postId}/likes | |
| 56 | +| - DELETE /api/posts/{postId}/likes | |
| 57 | ++--------------------------------------------+ |
| 58 | +``` |
| 59 | + |
| 60 | +## 데이터 모델 상세 다이어그램 |
| 61 | + |
| 62 | +``` |
| 63 | ++----------------+ +----------------+ +----------------+ |
| 64 | +| Post | | Comment | | Like | |
| 65 | ++----------------+ +----------------+ +----------------+ |
| 66 | +| id: int | | id: int | | postId: int | |
| 67 | +| userName: str | | postId: int | | userName: str | |
| 68 | +| content: str | | userName: str | | | |
| 69 | +| createdAt: str | | content: str | | | |
| 70 | +| updatedAt: str | | createdAt: str | | | |
| 71 | +| likeCount: int | | updatedAt: str | | | |
| 72 | +| commentCount:int| | | | | |
| 73 | ++----------------+ +----------------+ +----------------+ |
| 74 | + | | | |
| 75 | + | 1 | * | * |
| 76 | + v v v |
| 77 | ++----------------+ +----------------+ +----------------+ |
| 78 | +| PostCreate | | CommentCreate | | LikeBase | |
| 79 | ++----------------+ +----------------+ +----------------+ |
| 80 | +| userName: str | | userName: str | | userName: str | |
| 81 | +| content: str | | content: str | | | |
| 82 | ++----------------+ +----------------+ +----------------+ |
| 83 | + | | |
| 84 | + v v |
| 85 | ++----------------+ +----------------+ |
| 86 | +| PostUpdate | | CommentUpdate | |
| 87 | ++----------------+ +----------------+ |
| 88 | +| content: str | | content: str | |
| 89 | ++----------------+ +----------------+ |
| 90 | +``` |
| 91 | + |
| 92 | +## 데이터베이스 스키마 다이어그램 |
| 93 | + |
| 94 | +``` |
| 95 | ++----------------+ +----------------+ +----------------+ |
| 96 | +| posts | | comments | | likes | |
| 97 | ++----------------+ +----------------+ +----------------+ |
| 98 | +| id | | id | | postId | |
| 99 | +| userName | | postId | | userName | |
| 100 | +| content | | userName | +----------------+ |
| 101 | +| createdAt | | content | ^ |
| 102 | +| updatedAt | | createdAt | | |
| 103 | +| likeCount | | updatedAt | | |
| 104 | +| commentCount | +----------------+ | |
| 105 | ++----------------+ ^ | |
| 106 | + ^ | | |
| 107 | + | +------------------------+ |
| 108 | + | | | |
| 109 | + +-----------------------+------------------------+ |
| 110 | + 외래 키 관계 |
| 111 | +``` |
| 112 | + |
| 113 | +## API 흐름 다이어그램 |
| 114 | + |
| 115 | +``` |
| 116 | +클라이언트 → HTTP 요청 → FastAPI 애플리케이션 → API 라우터 → 비즈니스 로직 → |
| 117 | +SQLite 데이터베이스 → 결과 → Pydantic 모델 변환 → JSON 응답 → 클라이언트 |
| 118 | +``` |
| 119 | + |
| 120 | +## API 엔드포인트 설명 |
| 121 | + |
| 122 | +1. **포스트 관련 API** |
| 123 | + - `GET /api/posts`: 모든 포스트 목록 조회 |
| 124 | + - `POST /api/posts`: 새 포스트 작성 |
| 125 | + - `GET /api/posts/{postId}`: 특정 포스트 조회 |
| 126 | + - `PATCH /api/posts/{postId}`: 특정 포스트 수정 |
| 127 | + - `DELETE /api/posts/{postId}`: 특정 포스트 삭제 |
| 128 | + |
| 129 | +2. **댓글 관련 API** |
| 130 | + - `GET /api/posts/{postId}/comments`: 특정 포스트의 댓글 목록 조회 |
| 131 | + - `POST /api/posts/{postId}/comments`: 특정 포스트에 댓글 작성 |
| 132 | + - `GET /api/posts/{postId}/comments/{commentId}`: 특정 댓글 조회 |
| 133 | + - `PATCH /api/posts/{postId}/comments/{commentId}`: 특정 댓글 수정 |
| 134 | + - `DELETE /api/posts/{postId}/comments/{commentId}`: 특정 댓글 삭제 |
| 135 | + |
| 136 | +3. **좋아요 관련 API** |
| 137 | + - `POST /api/posts/{postId}/likes`: 특정 포스트에 좋아요 추가 |
| 138 | + - `DELETE /api/posts/{postId}/likes`: 특정 포스트의 좋아요 취소 |
0 commit comments