{{ news.ai_summary or news.summary }}
{% if news.ai_tags %} {% endif %} Czytaj więcejBrak więcej aktualności
'; return; } const newsGrid = document.querySelector('.news-grid'); data.news.forEach(news => { const newsCard = createNewsCard(news); newsGrid.appendChild(newsCard); }); if (!data.has_more) { document.querySelector('.news-load-more').style.display = 'none'; } } catch (error) { console.error('Error loading more news:', error); alert('Błąd podczas ładowania aktualności'); } } function createNewsCard(news) { const card = document.createElement('div'); card.className = 'news-card'; card.innerHTML = `${escapeHtml(news.summary)}
${news.ai_tags ? ` ` : ''} Czytaj więcej `; return card; } ``` --- ## 7. User Notification System ### 7.1 Notification Creation **When to Create Notifications:** 1. **New News Approved** - Notify company owner when their news is approved 2. **News Rejected** - Notify company owner when their news is rejected (optional) 3. **High-Priority News** - Notify NORDA members when high-relevance news appears for companies they follow (future feature) **Implementation:** ```python def create_news_approval_notification(news: CompanyNews, db: Session): """ Create notification when news is approved. Notify company owner (if user account exists). """ # Find company owner company_user = db.query(User).filter_by(company_id=news.company_id).first() if not company_user: return # No user account for this company notification = UserNotification( user_id=company_user.id, title=f"Nowa aktualność o {news.company.name}", message=f"Artykuł '{news.title}' został zatwierdzony i jest widoczny na profilu firmy.", notification_type='news', related_type='company_news', related_id=news.id, action_url=f"/company/{news.company.slug}#news", is_read=False ) db.add(notification) db.commit() ``` ### 7.2 Notification API **Endpoint:** `GET /api/notifications` **Authentication:** Requires logged-in user **Response:** ```json { "notifications": [ { "id": 123, "title": "Nowa aktualność o PIXLAB", "message": "Artykuł 'PIXLAB otwiera nową siedzibę' został zatwierdzony...", "notification_type": "news", "related_type": "company_news", "related_id": 42, "action_url": "/company/pixlab-sp-z-o-o#news", "is_read": false, "created_at": "2026-01-10T14:30:00" } ], "unread_count": 3, "total": 15 } ``` **Implementation:** ```python @app.route('/api/notifications', methods=['GET']) @login_required def api_notifications(): """Get user notifications.""" limit = request.args.get('limit', 20, type=int) offset = request.args.get('offset', 0, type=int) unread_only = request.args.get('unread_only', 'false') == 'true' query = db.session.query(UserNotification).filter_by(user_id=current_user.id) if unread_only: query = query.filter_by(is_read=False) total = query.count() unread_count = db.session.query(UserNotification).filter_by( user_id=current_user.id, is_read=False ).count() notifications = query.order_by(UserNotification.created_at.desc()) \ .limit(limit) \ .offset(offset) \ .all() return jsonify({ 'notifications': [n.to_dict() for n in notifications], 'unread_count': unread_count, 'total': total, 'has_more': (offset + limit) < total }) ``` ### 7.3 Mark as Read **Endpoint:** `POST /api/notifications/