14th_check
This commit is contained in:
@@ -9,7 +9,7 @@ Modified: 2024-01-28
|
||||
"""
|
||||
|
||||
from flask import Blueprint, jsonify, request, g
|
||||
from flask_jwt_extended import jwt_required, get_jwt_identity
|
||||
from app.utils.decorators import jwt_login_required
|
||||
from sqlalchemy import desc, and_, or_
|
||||
from datetime import datetime, timedelta
|
||||
from app import db
|
||||
@@ -22,12 +22,12 @@ notification_bp = Blueprint('notification', __name__, url_prefix='/notifications
|
||||
|
||||
|
||||
@notification_bp.route('', methods=['GET'])
|
||||
@jwt_required()
|
||||
@jwt_login_required
|
||||
def get_notifications():
|
||||
"""獲取當前用戶的通知列表"""
|
||||
try:
|
||||
# 獲取當前用戶
|
||||
current_user_id = get_jwt_identity()
|
||||
current_user_id = g.current_user_id
|
||||
|
||||
# 獲取查詢參數
|
||||
page = request.args.get('page', 1, type=int)
|
||||
@@ -94,11 +94,11 @@ def get_notifications():
|
||||
|
||||
|
||||
@notification_bp.route('/<notification_id>', methods=['GET'])
|
||||
@jwt_required()
|
||||
@jwt_login_required
|
||||
def get_notification(notification_id):
|
||||
"""獲取單個通知詳情"""
|
||||
try:
|
||||
current_user_id = get_jwt_identity()
|
||||
current_user_id = g.current_user_id
|
||||
|
||||
# 查找通知
|
||||
notification = Notification.query.filter_by(
|
||||
@@ -131,11 +131,11 @@ def get_notification(notification_id):
|
||||
|
||||
|
||||
@notification_bp.route('/<notification_id>/read', methods=['POST'])
|
||||
@jwt_required()
|
||||
@jwt_login_required
|
||||
def mark_notification_read(notification_id):
|
||||
"""標記通知為已讀"""
|
||||
try:
|
||||
current_user_id = get_jwt_identity()
|
||||
current_user_id = g.current_user_id
|
||||
|
||||
# 查找通知
|
||||
notification = Notification.query.filter_by(
|
||||
@@ -166,11 +166,11 @@ def mark_notification_read(notification_id):
|
||||
|
||||
|
||||
@notification_bp.route('/read-all', methods=['POST'])
|
||||
@jwt_required()
|
||||
@jwt_login_required
|
||||
def mark_all_read():
|
||||
"""標記所有通知為已讀"""
|
||||
try:
|
||||
current_user_id = get_jwt_identity()
|
||||
current_user_id = g.current_user_id
|
||||
|
||||
# 取得所有未讀通知
|
||||
unread_notifications = Notification.query.filter_by(
|
||||
@@ -201,11 +201,11 @@ def mark_all_read():
|
||||
|
||||
|
||||
@notification_bp.route('/<notification_id>', methods=['DELETE'])
|
||||
@jwt_required()
|
||||
@jwt_login_required
|
||||
def delete_notification(notification_id):
|
||||
"""刪除通知"""
|
||||
try:
|
||||
current_user_id = get_jwt_identity()
|
||||
current_user_id = g.current_user_id
|
||||
|
||||
# 查找通知
|
||||
notification = Notification.query.filter_by(
|
||||
@@ -237,11 +237,11 @@ def delete_notification(notification_id):
|
||||
|
||||
|
||||
@notification_bp.route('/clear', methods=['POST'])
|
||||
@jwt_required()
|
||||
@jwt_login_required
|
||||
def clear_read_notifications():
|
||||
"""清空所有已讀通知"""
|
||||
try:
|
||||
current_user_id = get_jwt_identity()
|
||||
current_user_id = g.current_user_id
|
||||
|
||||
# 刪除所有已讀通知
|
||||
deleted_count = Notification.query.filter_by(
|
||||
@@ -266,11 +266,11 @@ def clear_read_notifications():
|
||||
|
||||
|
||||
@notification_bp.route('/test', methods=['POST'])
|
||||
@jwt_required()
|
||||
@jwt_login_required
|
||||
def create_test_notification():
|
||||
"""創建測試通知(開發用)"""
|
||||
try:
|
||||
current_user_id = get_jwt_identity()
|
||||
current_user_id = g.current_user_id
|
||||
|
||||
# 創建測試通知
|
||||
test_notification = create_notification(
|
||||
|
@@ -246,7 +246,13 @@ const handleMenuClick = () => {
|
||||
const showNotifications = async () => {
|
||||
notificationDrawerVisible.value = true
|
||||
// 載入最新通知
|
||||
await notificationStore.fetchNotifications()
|
||||
console.log('🔔 正在載入通知...')
|
||||
try {
|
||||
await notificationStore.fetchNotifications()
|
||||
console.log('🔔 通知載入完成:', notificationStore.notifications.length)
|
||||
} catch (error) {
|
||||
console.error('🔔 通知載入失敗:', error)
|
||||
}
|
||||
}
|
||||
|
||||
const handleUserMenuCommand = async (command) => {
|
||||
@@ -331,7 +337,12 @@ onMounted(() => {
|
||||
// initWebSocket()
|
||||
|
||||
// 載入通知
|
||||
notificationStore.fetchNotifications()
|
||||
console.log('🔔 初始化載入通知...')
|
||||
notificationStore.fetchNotifications().then(() => {
|
||||
console.log('🔔 初始化通知載入完成:', notificationStore.notifications.length)
|
||||
}).catch(error => {
|
||||
console.error('🔔 初始化通知載入失敗:', error)
|
||||
})
|
||||
|
||||
// 監聽窗口大小變化
|
||||
window.addEventListener('resize', handleResize)
|
||||
|
@@ -29,14 +29,14 @@ export const notificationAPI = {
|
||||
* @param {string} notificationId - 通知ID
|
||||
*/
|
||||
markAsRead(notificationId) {
|
||||
return request.put(`/notifications/${notificationId}/read`)
|
||||
return request.post(`/notifications/${notificationId}/read`)
|
||||
},
|
||||
|
||||
/**
|
||||
* 標記所有通知為已讀
|
||||
*/
|
||||
markAllAsRead() {
|
||||
return request.put('/notifications/mark-all-read')
|
||||
return request.post('/notifications/read-all')
|
||||
},
|
||||
|
||||
/**
|
||||
|
Reference in New Issue
Block a user