feat: Docker部署与CI/CD集成, 搜索栏修复, 上传目录改为data
This commit is contained in:
30
pages/api/v1/users/me.ts
Normal file
30
pages/api/v1/users/me.ts
Normal file
@@ -0,0 +1,30 @@
|
||||
import { NextApiResponse } from 'next';
|
||||
import { AuthenticatedRequest, requireAuth } from '../../../../lib/middleware/authMiddleware';
|
||||
import { UserService } from '../../../../backend/services/userService';
|
||||
|
||||
export default async function handler(req: AuthenticatedRequest, res: NextApiResponse) {
|
||||
if (req.method !== 'PATCH') {
|
||||
return res.status(405).json({ success: false, error: 'Method not allowed' });
|
||||
}
|
||||
|
||||
// Require authentication
|
||||
const isAuthenticated = await requireAuth(req, res);
|
||||
if (!isAuthenticated) {
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
const { username, avatarUrl } = req.body;
|
||||
|
||||
// Update user
|
||||
const updatedUser = await UserService.updateUser(req.user!.id, {
|
||||
username,
|
||||
avatarUrl
|
||||
});
|
||||
|
||||
return res.status(200).json({ success: true, data: updatedUser });
|
||||
} catch (error) {
|
||||
console.error('Error updating user:', error);
|
||||
return res.status(500).json({ success: false, error: 'Failed to update user' });
|
||||
}
|
||||
}
|
||||
23
pages/api/v1/users/me/favorites.ts
Normal file
23
pages/api/v1/users/me/favorites.ts
Normal file
@@ -0,0 +1,23 @@
|
||||
import { NextApiResponse } from 'next';
|
||||
import { AuthenticatedRequest, requireAuth } from '@/lib/middleware/authMiddleware';
|
||||
import { MaterialService } from '@/backend/services/materialService';
|
||||
|
||||
export default async function handler(req: AuthenticatedRequest, res: NextApiResponse) {
|
||||
if (req.method !== 'GET') {
|
||||
return res.status(405).json({ success: false, error: 'Method not allowed' });
|
||||
}
|
||||
|
||||
try {
|
||||
const isAuthenticated = await requireAuth(req, res);
|
||||
if (!isAuthenticated) return;
|
||||
const page = parseInt((req.query.page as string) || '1', 10) || 1;
|
||||
const limit = parseInt((req.query.limit as string) || '20', 10) || 20;
|
||||
const { items, total } = await MaterialService.getFavoritedMaterialsByUser(req.user!.id, page, limit);
|
||||
const hasNext = page * limit < total;
|
||||
|
||||
return res.status(200).json({ success: true, data: { items, total, page, limit, hasNext }, timestamp: new Date().toISOString() });
|
||||
} catch (error: any) {
|
||||
console.error('Get user favorites error:', error);
|
||||
return res.status(500).json({ success: false, error: error.message || 'Failed to get favorites' });
|
||||
}
|
||||
}
|
||||
24
pages/api/v1/users/me/materials.ts
Normal file
24
pages/api/v1/users/me/materials.ts
Normal file
@@ -0,0 +1,24 @@
|
||||
import { NextApiResponse } from 'next';
|
||||
import { AuthenticatedRequest, requireAuth } from '@/lib/middleware/authMiddleware';
|
||||
import { MaterialService } from '@/backend/services/materialService';
|
||||
|
||||
export default async function handler(req: AuthenticatedRequest, res: NextApiResponse) {
|
||||
if (req.method !== 'GET') {
|
||||
return res.status(405).json({ success: false, error: 'Method not allowed' });
|
||||
}
|
||||
|
||||
try {
|
||||
const isAuthenticated = await requireAuth(req, res);
|
||||
if (!isAuthenticated) return;
|
||||
const { user } = req;
|
||||
const page = parseInt((req.query.page as string) || '1', 10) || 1;
|
||||
const limit = parseInt((req.query.limit as string) || '20', 10) || 20;
|
||||
const { items, total } = await MaterialService.getMaterialsByAuthor(user!.id, page, limit);
|
||||
const hasNext = page * limit < total;
|
||||
|
||||
return res.status(200).json({ success: true, data: { items, total, page, limit, hasNext }, timestamp: new Date().toISOString() });
|
||||
} catch (error: any) {
|
||||
console.error('Get user materials error:', error);
|
||||
return res.status(500).json({ success: false, error: error.message || 'Failed to get materials' });
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user