fix: исправлено получение уведомлений из бэкенда

- Фронтенд: добавлена обработка поля 'notifications' (бэкенд возвращает { notifications: [...] })
- Фронтенд: исправлены URL endpoints для отметки прочитанным (/read/ вместо /mark_read/)
- Бэкенд: добавлено поле 'short_message' в ответ API для корректного отображения превью
This commit is contained in:
lizerk 2026-03-09 09:51:00 +03:00
parent 8fee8177ad
commit 1972f89bea
3 changed files with 6 additions and 4 deletions

View File

@ -63,7 +63,8 @@ def get_notifications(request):
{
'id': n.id,
'title': n.title,
'message': n.message, # Полное сообщение для списка
'message': n.message,
'short_message': n.short_message or n.message[:150], # Краткое сообщение для превью
'category': n.notification_type.category.code,
'category_name': n.notification_type.category.name,
'icon': n.notification_type.category.icon,

View File

@ -179,7 +179,8 @@ export function useNotifications() {
async function fetchNotifications() {
try {
const data = await apiClient.getNotifications();
const notifs = data.results || data;
// Бэкенд возвращает { notifications: [...] }
const notifs = data.notifications || data.results || data;
// Убеждаемся что notifs это массив
const notificationsArray = Array.isArray(notifs) ? notifs : [];
setNotifications(notificationsArray);

View File

@ -792,13 +792,13 @@ class ApiClient {
}
async markNotificationAsRead(id: number): Promise<void> {
await this.request(`/api/v1/notifications/${id}/mark_read/`, {
await this.request(`/api/v1/notifications/${id}/read/`, {
method: 'POST',
});
}
async markAllNotificationsAsRead(): Promise<void> {
await this.request('/api/v1/notifications/mark_all_read/', {
await this.request('/api/v1/notifications/read-all/', {
method: 'POST',
});
}