Social Service - Dịch Vụ Quản Lý Quan Hệ Xã Hội
Microservice .NET 10 quản lý quan hệ xã hội giữa users: kết bạn, theo dõi và block.
Tổng Quan
Social Service là microservice quản lý tất cả các mối quan hệ xã hội giữa users trong GoodGo Platform:
- Kết bạn (Friendship) - Gửi/chấp nhận/từ chối yêu cầu kết bạn, hủy kết bạn
- Theo dõi (Following) - Follow/unfollow users
- Block (User Blocking) - Block/unblock users với lý do tùy chọn
- User Profile - Đồng bộ thông tin user từ IAM Service
Kiến Trúc & Patterns
| Pattern |
Triển khai |
| DDD |
Aggregates, Entities, Value Objects, Domain Events |
| CQRS |
Commands/Queries tách biệt với MediatR |
| Clean Architecture |
3-layer: Domain, Infrastructure, API |
| EF Core 10 |
PostgreSQL với connection resilience |
| Structured Logging |
Serilog với console và Seq |
Yêu Cầu
| Yêu cầu |
Phiên bản |
| .NET SDK |
10.0.101+ |
| Docker |
24.0+ |
| PostgreSQL |
15+ |
Bắt Đầu Nhanh
Chạy với Docker
Chạy Local
Domain Model
Aggregates
1. Relationship Aggregate
Quản lý quan hệ kết bạn và theo dõi giữa users.
Business Rules:
- Following tự động được chấp nhận
- Friendship yêu cầu xác nhận từ người nhận
- Không thể tạo quan hệ với chính mình
- Chỉ Pending requests mới có thể Accept/Reject/Cancel
- Chỉ Accepted relationships mới có thể Remove
2. UserBlock Aggregate
Quản lý việc block users.
| Field |
Mô tả |
BlockerId |
ID user thực hiện block |
BlockedId |
ID user bị block |
Reason |
Lý do block (tùy chọn) |
CreatedAt |
Thời gian block |
3. UserProfile Aggregate
Cache thông tin user được đồng bộ từ IAM Service.
| Field |
Mô tả |
UserId |
ID user từ IAM |
DisplayName |
Tên hiển thị |
AvatarUrl |
URL avatar |
Bio |
Tiểu sử |
LastSyncedAt |
Thời gian sync cuối |
API Endpoints
Relationships - Kết Bạn
| Method |
Endpoint |
Mô Tả |
GET |
/api/v1/relationships/users/{userId}/friends |
Lấy danh sách bạn bè |
POST |
/api/v1/relationships/friend-requests |
Gửi yêu cầu kết bạn |
PUT |
/api/v1/relationships/friend-requests/{id} |
Phản hồi yêu cầu (accept/reject) |
GET |
/api/v1/relationships/users/{id1}/mutual-friends/{id2} |
Lấy bạn chung |
GET |
/api/v1/relationships/users/{userId}/suggestions |
Gợi ý kết bạn |
Relationships - Theo Dõi
| Method |
Endpoint |
Mô Tả |
POST |
/api/v1/relationships/follow |
Theo dõi user |
DELETE |
/api/v1/relationships/follow |
Bỏ theo dõi user |
Block Users
| Method |
Endpoint |
Mô Tả |
POST |
/api/v1/blocks |
Block user |
DELETE |
/api/v1/blocks |
Unblock user |
GET |
/api/v1/blocks/users/{userId} |
Lấy danh sách blocked users |
Admin Backoffice
| Method |
Endpoint |
Mô Tả |
GET |
/api/v1/admin/social/relationships |
Lấy tất cả relationships (filter, phân trang) |
GET |
/api/v1/admin/social/relationships/{id} |
Chi tiết relationship |
DELETE |
/api/v1/admin/social/relationships/{id} |
Admin xóa relationship |
GET |
/api/v1/admin/social/blocks |
Lấy tất cả blocks (phân trang) |
DELETE |
/api/v1/admin/social/blocks/{id} |
Admin xóa block |
GET |
/api/v1/admin/social/statistics |
Thống kê tổng quan |
Health Endpoints
| Endpoint |
Mục Đích |
/health |
Trạng thái health đầy đủ |
/health/live |
Kiểm tra sống |
/health/ready |
Kiểm tra sẵn sàng |
Cấu Trúc Dự Án
CQRS Pattern
Commands (Thao Tác Ghi)
| Command |
Mô Tả |
SendFriendRequestCommand |
Gửi yêu cầu kết bạn |
RespondToFriendRequestCommand |
Accept/Reject friend request |
FollowUserCommand |
Theo dõi user |
UnfollowUserCommand |
Bỏ theo dõi |
BlockUserCommand |
Block user với lý do tùy chọn |
UnblockUserCommand |
Unblock user |
Queries (Thao Tác Đọc)
| Query |
Mô Tả |
GetFriendsQuery |
Danh sách bạn bè với phân trang |
GetMutualFriendsQuery |
Bạn chung giữa 2 users |
GetFriendSuggestionsQuery |
Gợi ý kết bạn |
GetBlockedUsersQuery |
Danh sách users bị block |
Domain Events
| Event |
Trigger |
FriendRequestSentDomainEvent |
Khi gửi friend request |
FriendshipCreatedDomainEvent |
Khi friend request được accept |
UserFollowedDomainEvent |
Khi follow user |
RelationshipStatusChangedDomainEvent |
Khi status thay đổi |
RelationshipRemovedDomainEvent |
Khi unfriend/unfollow |
UserBlockedDomainEvent |
Khi block user |
UserUnblockedDomainEvent |
Khi unblock user |
Cấu Hình
Biến Môi Trường
| Biến |
Mô Tả |
Mặc định |
ASPNETCORE_ENVIRONMENT |
Tên môi trường |
Development |
DATABASE_URL |
PostgreSQL connection string |
- |
REDIS_URL |
Redis connection string |
- |
appsettings.json
Kiểm Thử
Triển Khai
Docker Build
Tài Nguyên
Giấy Phép
Độc quyền - GoodGo Platform