Files
contracts/proto/notifications/notifications.proto
Дмитрий 64a51f1b52
All checks were successful
Publish / Publish Job (push) Successful in 2m27s
add notifications proto file
2026-04-16 09:47:01 +03:00

107 lines
4.5 KiB
Protocol Buffer
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
syntax = "proto3";
// Указываем пакет для логической изоляции
package notifications.v1;
// Импортируем стандартные типы Google для работы с датами и произвольным JSON
import "google/protobuf/timestamp.proto";
import "google/protobuf/struct.proto";
// Опции для генерации кода (особенно полезно для Go, если понадобится)
option go_package = "git.lendry.ru/lendry-erp/proto.git/go;pb";
// -----------------------------------------------------------------------------
// Сервис Уведомлений
// -----------------------------------------------------------------------------
service NotificationService {
// --- Публичные методы (Вызываются из API Gateway от лица клиента) ---
// Получить список уведомлений пользователя с пагинацией
rpc GetUserNotifications (GetNotificationsRequest) returns (GetNotificationsResponse);
// Получить количество непрочитанных уведомлений (для бейджика на иконке)
rpc GetUnreadCount (GetUnreadCountRequest) returns (GetUnreadCountResponse);
// Отметить конкретное уведомление как прочитанное
rpc MarkAsRead (MarkAsReadRequest) returns (MarkAsReadResponse);
// Отметить все уведомления пользователя как прочитанные
rpc MarkAllAsRead (MarkAllAsReadRequest) returns (MarkAllAsReadResponse);
// --- Внутренние методы (Вызываются другими микросервисами: CRM, ERP, Auth) ---
// Отправить уведомление (CRM/ERP вызывает этот метод, а NestJS уже кидает в RabbitMQ)
rpc SendNotification (SendNotificationRequest) returns (SendNotificationResponse);
}
// -----------------------------------------------------------------------------
// Базовые модели
// -----------------------------------------------------------------------------
// Структура самого уведомления
message Notification {
string id = 1;
string user_id = 2;
string type = 3; // Например: "SYSTEM_ALERT", "NEW_MESSAGE", "TASK_ASSIGNED"
string title = 4; // Заголовок (опционально)
string text = 5; // Текст уведомления
google.protobuf.Struct payload = 6; // Любая динамическая JSON-нагрузка (например, { "task_id": 123 })
bool is_read = 7;
google.protobuf.Timestamp created_at = 8;
}
// -----------------------------------------------------------------------------
// Запросы и ответы (Requests / Responses)
// -----------------------------------------------------------------------------
message GetNotificationsRequest {
string user_id = 1; // ID пользователя запрашивающего данные (Gateway берет это из JWT)
int32 limit = 2; // Для пагинации (например, 20)
int32 offset = 3; // Для пагинации (например, 0)
optional bool unread_only = 4; // Фильтр: получить только непрочитанные
}
message GetNotificationsResponse {
repeated Notification notifications = 1; // Массив уведомлений
int32 total_count = 2; // Общее количество (для UI пагинации)
}
message GetUnreadCountRequest {
string user_id = 1;
}
message GetUnreadCountResponse {
int32 count = 1;
}
message MarkAsReadRequest {
string user_id = 1;
string notification_id = 2;
}
message MarkAsReadResponse {
bool success = 1;
}
message MarkAllAsReadRequest {
string user_id = 1;
}
message MarkAllAsReadResponse {
bool success = 1;
int32 updated_count = 2; // Сколько уведомлений было обновлено
}
message SendNotificationRequest {
string user_id = 1; // Кому отправляем (если пусто — можно сделать бродкаст, но лучше отдельный метод)
string type = 2;
string title = 3;
string text = 4;
google.protobuf.Struct payload = 5; // Метаданные для UI (ссылки, ID сущностей)
}
message SendNotificationResponse {
bool success = 1;
string notification_id = 2; // ID созданного уведомления в Postgres
}