topfans/backend/proto/notification.proto

151 lines
4.9 KiB
Protocol Buffer

syntax = "proto3";
package topfans.notification;
option go_package = "github.com/topfans/backend/pkg/proto/notification;notification";
import "proto/common.proto";
import "google/api/annotations.proto";
import "google/protobuf/struct.proto";
service NotificationService {
rpc CreateNotification(CreateNotificationRequest) returns (CreateNotificationResponse) {
option (google.api.http) = {
post: "/internal/v1/notifications"
body: "*"
};
}
rpc GetNotifications(GetNotificationsRequest) returns (GetNotificationsResponse) {
option (google.api.http) = { get: "/api/v1/notifications" };
}
rpc GetUnreadCount(GetUnreadCountRequest) returns (GetUnreadCountResponse) {
option (google.api.http) = { get: "/api/v1/notifications/unread-count" };
}
rpc MarkAsRead(MarkAsReadRequest) returns (MarkAsReadResponse) {
option (google.api.http) = { post: "/api/v1/notifications/{id}/read" };
}
rpc MarkAsReadByTarget(MarkAsReadByTargetRequest) returns (MarkAsReadByTargetResponse) {
option (google.api.http) = { post: "/api/v1/notifications/targets/{target_id}/read" };
}
rpc MarkAllAsRead(MarkAllAsReadRequest) returns (MarkAllAsReadResponse) {
option (google.api.http) = { post: "/api/v1/notifications/read-all" };
}
rpc DeleteNotification(DeleteNotificationRequest) returns (DeleteNotificationResponse) {
option (google.api.http) = { delete: "/api/v1/notifications/{id}" };
}
rpc DeleteByTarget(DeleteByTargetRequest) returns (DeleteByTargetResponse) {
option (google.api.http) = { delete: "/api/v1/notifications/targets/{target_id}" };
}
// ========== 设备注册(推送 cid 上报) ==========
// 注册/更新当前用户的推送设备 cid;同 cid 重复注册为更新,user 变化时也更新归属。
rpc RegisterDevice(RegisterDeviceRequest) returns (RegisterDeviceResponse) {
option (google.api.http) = {
post: "/api/v1/notifications/devices"
body: "*"
};
}
// 注销指定 cid 的推送(登出 / 客户端主动关闭通知)。
rpc UnregisterDevice(UnregisterDeviceRequest) returns (UnregisterDeviceResponse) {
option (google.api.http) = {
post: "/api/v1/notifications/devices/unregister"
body: "*"
};
}
}
message Notification {
int64 id = 1; int64 user_id = 2; int64 star_id = 3;
string type = 4; string title = 5; string content = 6;
google.protobuf.Struct data = 7;
bool is_read = 8; int64 created_at = 9; int64 read_at = 10;
// 列表层聚合:仅 type=like 且按 target_id 聚合时返回
bool aggregated = 11;
int32 total_count = 12;
repeated ActorPreview actors = 13;
int64 target_id = 14;
}
message ActorPreview {
int64 user_id = 1; string nickname = 2; string avatar = 3;
int64 liked_at = 4;
}
message CreateNotificationRequest {
int64 user_id = 1; int64 star_id = 2;
string type = 3; string title = 4; string content = 5;
google.protobuf.Struct data = 6;
}
message CreateNotificationResponse {
topfans.common.BaseResponse base = 1;
int64 id = 2;
}
message GetNotificationsRequest {
string type = 1;
string tab = 2;
int32 page = 3; int32 page_size = 4;
}
message GetNotificationsResponse {
topfans.common.BaseResponse base = 1;
repeated Notification items = 2;
int64 total = 3;
int32 page = 4; int32 page_size = 5;
}
message GetUnreadCountRequest {}
message UnreadCount {
int32 like = 1; int32 system = 2; int32 activity = 3; int32 total = 4;
}
message GetUnreadCountResponse {
topfans.common.BaseResponse base = 1;
UnreadCount counts = 2;
}
message MarkAsReadRequest { int64 id = 1; }
message MarkAsReadResponse { topfans.common.BaseResponse base = 1; }
message MarkAsReadByTargetRequest { int64 target_id = 1; }
message MarkAsReadByTargetResponse {
topfans.common.BaseResponse base = 1; int32 affected = 2;
}
message MarkAllAsReadRequest { string type = 1; }
message MarkAllAsReadResponse {
topfans.common.BaseResponse base = 1; int32 affected = 2;
}
message DeleteNotificationRequest { int64 id = 1; }
message DeleteNotificationResponse { topfans.common.BaseResponse base = 1; }
message DeleteByTargetRequest { int64 target_id = 1; }
message DeleteByTargetResponse {
topfans.common.BaseResponse base = 1; int32 affected = 2;
}
// ========== 设备注册消息 ==========
// RegisterDeviceRequest 注册/更新推送设备。
// 行为:按 cid 主键 upsert。同 cid 已存在时更新归属(user/platform/version);不存在则插入。
message RegisterDeviceRequest {
string cid = 1;
string platform = 2; // ios / android / harmony
string app_version = 3;
string device_model = 4;
}
message RegisterDeviceResponse {
topfans.common.BaseResponse base = 1;
int64 id = 2; // user_devices.id(便于客户端排错/对账)
}
// UnregisterDeviceRequest 注销指定 cid 的推送。cid 为空时注销当前用户的所有设备。
message UnregisterDeviceRequest {
string cid = 1;
}
message UnregisterDeviceResponse {
topfans.common.BaseResponse base = 1;
int32 affected = 2; // 受影响的行数
}