File size: 5,718 Bytes
3c8be80
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Tuwaiq CodeHub API</title>
    <script src="https://cdn.tailwindcss.com"></script>
    <script src="https://unpkg.com/feather-icons"></script>
</head>
<body class="bg-gray-900 text-gray-100 min-h-screen">
    <div class="container mx-auto px-4 py-12">
        <div class="text-center mb-12">
            <h1 class="text-4xl font-bold mb-2">Tuwaiq CodeHub API</h1>
            <p class="text-xl text-gray-400">Backend service for the student code sharing platform</p>
        </div>

        <div class="bg-gray-800 rounded-lg shadow-lg p-6 mb-8">
            <h2 class="text-2xl font-bold mb-4 text-purple-400">API Endpoints</h2>
            
            <div class="space-y-6">
                <!-- Projects API -->
                <div class="bg-gray-700 rounded-lg p-4">
                    <div class="flex items-center mb-2">
                        <span class="bg-green-500 text-xs px-2 py-1 rounded mr-2">GET</span>
                        <code class="text-purple-300">/api/projects</code>
                    </div>
                    <p class="text-gray-300 mb-3">Get all student projects</p>
                    <button onclick="testEndpoint('/api/projects')" class="bg-purple-600 hover:bg-purple-700 text-white px-3 py-1 rounded text-sm">
                        Test Endpoint
                    </button>
                </div>

                <!-- Code Snippets API -->
                <div class="bg-gray-700 rounded-lg p-4">
                    <div class="flex items-center mb-2">
                        <span class="bg-blue-500 text-xs px-2 py-1 rounded mr-2">POST</span>
                        <code class="text-purple-300">/api/snippets</code>
                    </div>
                    <p class="text-gray-300 mb-3">Submit a new code snippet</p>
                    <button onclick="testEndpoint('/api/snippets')" class="bg-purple-600 hover:bg-purple-700 text-white px-3 py-1 rounded text-sm">
                        Test Endpoint
                    </button>
                </div>

                <!-- Chat API -->
                <div class="bg-gray-700 rounded-lg p-4">
                    <div class="flex items-center mb-2">
                        <span class="bg-yellow-500 text-xs px-2 py-1 rounded mr-2">GET</span>
                        <code class="text-purple-300">/api/chat</code>
                    </div>
                    <p class="text-gray-300 mb-3">Get chat messages</p>
                    <button onclick="testEndpoint('/api/chat')" class="bg-purple-600 hover:bg-purple-700 text-white px-3 py-1 rounded text-sm">
                        Test Endpoint
                    </button>
                </div>

                <!-- Users API -->
                <div class="bg-gray-700 rounded-lg p-4">
                    <div class="flex items-center mb-2">
                        <span class="bg-red-500 text-xs px-2 py-1 rounded mr-2">GET</span>
                        <code class="text-purple-300">/api/users</code>
                    </div>
                    <p class="text-gray-300 mb-3">Get user information</p>
                    <button onclick="testEndpoint('/api/users')" class="bg-purple-600 hover:bg-purple-700 text-white px-3 py-1 rounded text-sm">
                        Test Endpoint
                    </button>
                </div>
            </div>
        </div>

        <div class="bg-gray-800 rounded-lg shadow-lg p-6">
            <h2 class="text-2xl font-bold mb-4 text-purple-400">API Response</h2>
            <div id="apiResponse" class="bg-gray-900 rounded-lg p-4 min-h-32">
                <p class="text-gray-500">Response will appear here...</p>
            </div>
        </div>
    </div>

    <script>
        feather.replace();

        async function testEndpoint(endpoint) {
            const responseDiv = document.getElementById('apiResponse');
            responseDiv.innerHTML = '<p class="text-purple-400">Loading...</p>';
            
            try {
                // Simulate API call with mock data
                const mockData = {
                    '/api/projects': {
                        status: 'success',
                        data: [
                            { id: 1, title: 'Sentiment Analysis Tool', author: 'Ali R.' },
                            { id: 2, title: 'E-commerce Platform', author: 'Sarah K.' }
                        ]
                    },
                    '/api/snippets': {
                        status: 'success',
                        message: 'Code snippet submitted successfully'
                    },
                    '/api/chat': {
                        status: 'success',
                        messages: [
                            { id: 1, user: 'Moha_Dev', text: 'Check out this awesome resource...' }
                        ]
                    },
                    '/api/users': {
                        status: 'success',
                        user: { id: 1, name: 'Ahmed Al-Mansour', role: 'Student' }
                    }
                };

                // Simulate network delay
                await new Promise(resolve => setTimeout(resolve, 800));
                
                const response = mockData[endpoint] || { status: 'error', message: 'Endpoint not found' };
                responseDiv.innerHTML = `<pre class="text-green-400">${JSON.stringify(response, null, 2)}</pre>`;
            } catch (error) {
                responseDiv.innerHTML = `<p class="text-red-400">Error: ${error.message}</p>`;
            }
        }
    </script>
</body>
</html>