-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmock-backend.js
More file actions
346 lines (324 loc) · 9.15 KB
/
mock-backend.js
File metadata and controls
346 lines (324 loc) · 9.15 KB
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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
const express = require('express');
const cors = require('cors');
const app = express();
const PORT = 8080;
// Enable CORS for all routes
app.use(cors({
origin: 'http://localhost:3000',
credentials: true
}));
// Parse JSON bodies
app.use(express.json());
// Health endpoint
app.get('/api/health', (req, res) => {
res.json({
status: 'UP',
timestamp: new Date().toISOString(),
service: 'City Service API (Mock)',
version: '1.0.0'
});
});
// Featured categories endpoint
app.get('/api/categories/featured', (req, res) => {
res.json({
success: true,
data: [
{ id: 1, name: 'Plumbing', description: 'Professional plumbing services', featured: true, icon: '🔧' },
{ id: 2, name: 'Electrical', description: 'Licensed electrical work', featured: true, icon: '⚡' },
{ id: 3, name: 'Cleaning', description: 'Home and office cleaning', featured: true, icon: '🧽' },
{ id: 4, name: 'Landscaping', description: 'Garden and lawn care', featured: true, icon: '🌿' },
{ id: 5, name: 'Painting', description: 'Interior and exterior painting', featured: true, icon: '🎨' }
],
message: 'Featured categories retrieved successfully'
});
});
// Top rated providers endpoint
app.get('/api/providers/top-rated', (req, res) => {
const limit = parseInt(req.query.limit) || 6;
const providers = [
{
id: 1,
businessName: 'Best Plumbing Co.',
description: 'Professional plumbing services with 15+ years experience',
averageRating: 4.8,
totalReviews: 127,
isVerified: true,
isAvailable: true,
city: 'San Francisco',
serviceArea: 'Bay Area',
yearsOfExperience: 15,
profileImageUrl: null
},
{
id: 2,
businessName: 'Elite Electricians',
description: 'Licensed electrical contractors for residential and commercial',
averageRating: 4.9,
totalReviews: 89,
isVerified: true,
isAvailable: true,
city: 'San Francisco',
serviceArea: 'Bay Area',
yearsOfExperience: 12,
profileImageUrl: null
},
{
id: 3,
businessName: 'Clean Masters',
description: 'Eco-friendly cleaning services for homes and offices',
averageRating: 4.7,
totalReviews: 156,
isVerified: true,
isAvailable: false,
city: 'San Francisco',
serviceArea: 'Bay Area',
yearsOfExperience: 8,
profileImageUrl: null
},
{
id: 4,
businessName: 'Green Thumb Landscaping',
description: 'Complete landscaping and garden maintenance services',
averageRating: 4.6,
totalReviews: 73,
isVerified: true,
isAvailable: true,
city: 'San Francisco',
serviceArea: 'Bay Area',
yearsOfExperience: 10,
profileImageUrl: null
},
{
id: 5,
businessName: 'Perfect Paint Pros',
description: 'Interior and exterior painting with premium materials',
averageRating: 4.8,
totalReviews: 94,
isVerified: true,
isAvailable: true,
city: 'San Francisco',
serviceArea: 'Bay Area',
yearsOfExperience: 7,
profileImageUrl: null
},
{
id: 6,
businessName: 'Handyman Heroes',
description: 'General handyman services for all your home repair needs',
averageRating: 4.5,
totalReviews: 112,
isVerified: false,
isAvailable: true,
city: 'San Francisco',
serviceArea: 'Bay Area',
yearsOfExperience: 5,
profileImageUrl: null
}
];
res.json({
success: true,
data: providers.slice(0, limit),
message: 'Top rated providers retrieved successfully'
});
});
// Popular services endpoint
app.get('/api/services/popular', (req, res) => {
const limit = parseInt(req.query.limit) || 6;
const services = [
{
id: 1,
name: 'Pipe Repair',
description: 'Fix leaky pipes and water damage',
category: 'Plumbing',
averagePrice: 150,
duration: '2-3 hours'
},
{
id: 2,
name: 'Wiring Installation',
description: 'New electrical wiring for homes and offices',
category: 'Electrical',
averagePrice: 300,
duration: '4-6 hours'
},
{
id: 3,
name: 'House Cleaning',
description: 'Complete house cleaning service',
category: 'Cleaning',
averagePrice: 120,
duration: '3-4 hours'
},
{
id: 4,
name: 'Garden Design',
description: 'Custom garden design and installation',
category: 'Landscaping',
averagePrice: 500,
duration: '1-2 days'
},
{
id: 5,
name: 'Interior Painting',
description: 'Professional interior painting service',
category: 'Painting',
averagePrice: 400,
duration: '1-2 days'
},
{
id: 6,
name: 'Furniture Assembly',
description: 'Assembly of furniture and fixtures',
category: 'Handyman',
averagePrice: 80,
duration: '1-2 hours'
}
];
res.json({
success: true,
data: services.slice(0, limit),
message: 'Popular services retrieved successfully'
});
});
// Categories endpoint
app.get('/api/categories', (req, res) => {
res.json({
success: true,
data: [
{ id: 1, name: 'Plumbing', description: 'Professional plumbing services', active: true },
{ id: 2, name: 'Electrical', description: 'Licensed electrical work', active: true },
{ id: 3, name: 'Cleaning', description: 'Home and office cleaning', active: true },
{ id: 4, name: 'Landscaping', description: 'Garden and lawn care', active: true },
{ id: 5, name: 'Painting', description: 'Interior and exterior painting', active: true },
{ id: 6, name: 'Handyman', description: 'General repair and maintenance', active: true }
],
message: 'Categories retrieved successfully'
});
});
// Providers endpoint
app.get('/api/providers', (req, res) => {
const providers = [
{
id: 1,
businessName: 'Best Plumbing Co.',
description: 'Professional plumbing services with 15+ years experience',
averageRating: 4.8,
totalReviews: 127,
isVerified: true,
isAvailable: true,
city: 'San Francisco',
serviceArea: 'Bay Area',
yearsOfExperience: 15
},
{
id: 2,
businessName: 'Elite Electricians',
description: 'Licensed electrical contractors for residential and commercial',
averageRating: 4.9,
totalReviews: 89,
isVerified: true,
isAvailable: true,
city: 'San Francisco',
serviceArea: 'Bay Area',
yearsOfExperience: 12
}
];
res.json({
success: true,
data: {
content: providers,
totalElements: providers.length,
totalPages: 1,
size: 10,
number: 0
},
message: 'Providers retrieved successfully'
});
});
// Cities endpoint
app.get('/api/providers/cities', (req, res) => {
res.json({
success: true,
data: ['San Francisco', 'Oakland', 'San Jose', 'Berkeley', 'Palo Alto'],
message: 'Cities retrieved successfully'
});
});
// Authentication endpoints
app.post('/api/auth/login', (req, res) => {
const { usernameOrEmail, password } = req.body;
if (usernameOrEmail === 'admin@serviceapp.com' && password === 'admin123') {
res.json({
success: true,
data: {
accessToken: 'mock-jwt-token-12345',
refreshToken: 'mock-refresh-token-67890',
user: {
id: 1,
email: 'admin@serviceapp.com',
username: 'admin',
firstName: 'Admin',
lastName: 'User',
role: { name: 'ADMIN' }
}
},
message: 'Login successful'
});
} else {
res.status(401).json({
success: false,
message: 'Invalid credentials'
});
}
});
// Register endpoint
app.post('/api/auth/register', (req, res) => {
const { username, email, password, firstName, lastName, phoneNumber } = req.body;
// Simple validation
if (!username || !email || !password) {
return res.status(400).json({
success: false,
message: 'Username, email, and password are required'
});
}
// Check if user already exists (mock check)
if (email === 'admin@serviceapp.com' || username === 'admin') {
return res.status(409).json({
success: false,
message: 'User already exists'
});
}
// Mock successful registration
const accessToken = 'mock-jwt-token-user-' + Date.now();
const refreshToken = 'mock-refresh-token-user-' + Date.now();
res.status(201).json({
success: true,
data: {
accessToken,
refreshToken,
user: {
id: 2,
username,
email,
firstName: firstName || 'User',
lastName: lastName || 'Name',
phoneNumber: phoneNumber || null,
role: { name: 'USER' }
}
},
message: 'Registration successful'
});
});
// Catch all other routes
app.use((req, res) => {
res.status(404).json({
success: false,
message: 'Endpoint not found',
path: req.originalUrl
});
});
// Start server
app.listen(PORT, () => {
console.log(`🚀 Mock Backend Server running on http://localhost:${PORT}`);
console.log(`📱 Frontend should be running on http://localhost:3000`);
console.log(`🔧 API Base URL: http://localhost:${PORT}/api`);
});