-
Notifications
You must be signed in to change notification settings - Fork 0
/
dataset.xml
441 lines (388 loc) · 11.6 KB
/
dataset.xml
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
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
<dataset>
<example>
<user_input>How do we handle password reset flows?</user_input>
<snippets>
<snippet><![CDATA[```python auth/password_reset.py
def initiate_password_reset(email):
token = generate_reset_token()
send_reset_email(email, token)
store_reset_token(email, token, expiry=24*hours)
return True
def validate_reset_token(token, new_password):
if is_token_valid(token):
user = get_user_by_token(token)
update_password(user, new_password)
invalidate_token(token)
return True
return False
```]]></snippet>
</snippets>
</example>
<example>
<user_input>Where is the user registration logic implemented?</user_input>
<snippets>
<snippet><![CDATA[```typescript src/services/UserService.ts
export class UserService {
async register(userData: RegisterDTO): Promise<User> {
const existingUser = await this.userRepo.findByEmail(userData.email);
if (existingUser) {
throw new DuplicateUserError();
}
const hashedPassword = await bcrypt.hash(userData.password);
return this.userRepo.create({
...userData,
password: hashedPassword
});
}
}
```]]></snippet>
</snippets>
</example>
<example>
<user_input>How do we process payments?</user_input>
<snippets>
<snippet><![CDATA[```typescript services/PaymentProcessor.ts
class PaymentProcessor {
async processPayment(amount: number, paymentMethod: PaymentMethod): Promise<PaymentResult> {
const transaction = await this.stripeClient.createCharge({
amount,
currency: 'usd',
payment_method: paymentMethod.id,
confirm: true
});
return this.saveTransaction(transaction);
}
}
```]]></snippet>
</snippets>
</example>
<example>
<user_input>Where is the email sending functionality?</user_input>
<snippets>
<snippet><![CDATA[```python utils/mailer.py
from sendgrid import SendGridAPIClient
class EmailService:
def __init__(self, api_key):
self.client = SendGridAPIClient(api_key)
def send_email(self, to_email, subject, content):
message = {
'to': to_email,
'subject': subject,
'content': content,
'from_email': 'noreply@ourapp.com'
}
return self.client.send(message)
```]]></snippet>
</snippets>
</example>
<example>
<user_input>How do we handle file uploads?</user_input>
<snippets>
<snippet><![CDATA[```typescript src/controllers/FileUploadController.ts
@Controller('uploads')
export class FileUploadController {
@Post()
async uploadFile(@UploadedFile() file: Express.Multer.File) {
const result = await this.s3Service.upload(file.buffer, {
bucket: 'user-uploads',
contentType: file.mimetype
});
return { url: result.Location };
}
}
```]]></snippet>
</snippets>
</example>
<example>
<user_input>Where is the database connection configuration?</user_input>
<snippets>
<snippet><![CDATA[```javascript config/database.js
module.exports = {
development: {
client: 'postgresql',
connection: {
host: process.env.DB_HOST,
database: process.env.DB_NAME,
user: process.env.DB_USER,
password: process.env.DB_PASSWORD
},
pool: {
min: 2,
max: 10
}
}
}
```]]></snippet>
</snippets>
</example>
<example>
<user_input>How do we implement rate limiting?</user_input>
<snippets>
<snippet><![CDATA[```typescript middleware/RateLimiter.ts
export class RateLimiter {
constructor(private redis: Redis) {}
async limit(req: Request, res: Response, next: NextFunction) {
const key = `rate_limit:${req.ip}`;
const requests = await this.redis.incr(key);
if (requests === 1) {
await this.redis.expire(key, 60);
}
if (requests > 100) {
return res.status(429).json({ error: 'Too many requests' });
}
next();
}
}
```]]></snippet>
</snippets>
</example>
<example>
<user_input>Where is the search functionality implemented?</user_input>
<snippets>
<snippet><![CDATA[```typescript services/SearchService.ts
export class SearchService {
async search(query: string, filters: SearchFilters): Promise<SearchResult[]> {
const elasticQuery = this.buildElasticQuery(query, filters);
const results = await this.elasticClient.search({
index: 'products',
body: elasticQuery
});
return this.mapResults(results.hits);
}
}
```]]></snippet>
</snippets>
</example>
<example>
<user_input>How do we handle logging?</user_input>
<snippets>
<snippet><![CDATA[```typescript utils/Logger.ts
import winston from 'winston';
export const logger = winston.createLogger({
level: process.env.LOG_LEVEL || 'info',
format: winston.format.json(),
transports: [
new winston.transports.File({ filename: 'error.log', level: 'error' }),
new winston.transports.File({ filename: 'combined.log' })
]
});
```]]></snippet>
</snippets>
</example>
<example>
<user_input>Where is the caching logic?</user_input>
<snippets>
<snippet><![CDATA[```typescript services/CacheService.ts
export class CacheService {
constructor(private redis: Redis) {}
async get<T>(key: string): Promise<T | null> {
const cached = await this.redis.get(key);
return cached ? JSON.parse(cached) : null;
}
async set(key: string, value: any, ttl?: number): Promise<void> {
await this.redis.set(key, JSON.stringify(value), 'EX', ttl || 3600);
}
}
```]]></snippet>
</snippets>
</example>
<example>
<user_input>How do we handle websocket connections?</user_input>
<snippets>
<snippet><![CDATA[```typescript services/WebSocketService.ts
@WebSocketGateway()
export class WebSocketGateway {
@WebSocketServer()
server: Server;
handleConnection(client: Socket) {
const userId = this.getUserFromToken(client.handshake.auth.token);
client.join(`user:${userId}`);
}
@SubscribeMessage('message')
handleMessage(client: Socket, payload: any) {
this.server.to(payload.room).emit('message', payload);
}
}
```]]></snippet>
</snippets>
</example>
<example>
<user_input>Where is the input validation handled?</user_input>
<snippets>
<snippet><![CDATA[```typescript middleware/Validator.ts
export class ValidationMiddleware {
validate(schema: Joi.Schema) {
return (req: Request, res: Response, next: NextFunction) => {
const { error } = schema.validate(req.body);
if (error) {
return res.status(400).json({
error: error.details[0].message
});
}
next();
};
}
}
```]]></snippet>
</snippets>
</example>
<example>
<user_input>How do we implement the shopping cart?</user_input>
<snippets>
<snippet><![CDATA[```typescript services/CartService.ts
export class CartService {
async addToCart(userId: string, productId: string, quantity: number) {
const cart = await this.cartRepo.findByUser(userId);
const product = await this.productRepo.findById(productId);
if (product.stock < quantity) {
throw new InsufficientStockError();
}
return this.cartRepo.addItem(cart.id, {
productId,
quantity,
price: product.price
});
}
}
```]]></snippet>
</snippets>
</example>
<example>
<user_input>Where is the notification system implemented?</user_input>
<snippets>
<snippet><![CDATA[```typescript services/NotificationService.ts
export class NotificationService {
async notify(userId: string, notification: Notification) {
const user = await this.userRepo.findById(userId);
if (user.preferences.email) {
await this.emailService.send(user.email, notification);
}
if (user.preferences.push) {
await this.pushService.send(user.deviceToken, notification);
}
}
}
```]]></snippet>
</snippets>
</example>
<example>
<user_input>How do we handle API errors?</user_input>
<snippets>
<snippet><![CDATA[```typescript middleware/ErrorHandler.ts
export class ErrorHandler {
catch(error: Error, req: Request, res: Response, next: NextFunction) {
if (error instanceof ValidationError) {
return res.status(400).json({
type: 'ValidationError',
message: error.message
});
}
if (error instanceof AuthenticationError) {
return res.status(401).json({
type: 'AuthenticationError',
message: 'Unauthorized'
});
}
// Default error
res.status(500).json({
type: 'ServerError',
message: 'Internal server error'
});
}
}
```]]></snippet>
</snippets>
</example>
<example>
<user_input>Where is the user profile update logic?</user_input>
<snippets>
<snippet><![CDATA[```typescript services/ProfileService.ts
export class ProfileService {
async updateProfile(userId: string, updates: ProfileUpdates): Promise<User> {
const user = await this.userRepo.findById(userId);
if (updates.email && updates.email !== user.email) {
await this.verifyEmailUnique(updates.email);
}
const updatedUser = await this.userRepo.update(userId, updates);
return this.sanitizeUser(updatedUser);
}
}
```]]></snippet>
</snippets>
</example>
<example>
<user_input>How do we generate PDFs?</user_input>
<snippets>
<snippet><![CDATA[```typescript services/PDFGenerator.ts
export class PDFGenerator {
async generatePDF(template: string, data: any): Promise<Buffer> {
const html = await this.templateEngine.render(template, data);
const browser = await puppeteer.launch();
const page = await browser.newPage();
await page.setContent(html);
const pdf = await page.pdf({
format: 'A4',
printBackground: true
});
await browser.close();
return pdf;
}
}
```]]></snippet>
</snippets>
</example>
<example>
<user_input>Where is the background job processing handled?</user_input>
<snippets>
<snippet><![CDATA[```typescript workers/JobProcessor.ts
export class JobProcessor {
@Process('email')
async processEmailJob(job: Job) {
const { to, subject, content } = job.data;
await this.emailService.send(to, subject, content);
}
@Process('image-resize')
async processImageResize(job: Job) {
const { imageUrl, dimensions } = job.data;
const resized = await this.imageService.resize(imageUrl, dimensions);
await this.storageService.upload(resized);
}
}
```]]></snippet>
</snippets>
</example>
<example>
<user_input>How do we implement the recommendation system?</user_input>
<snippets>
<snippet><![CDATA[```python services/recommender.py
class RecommendationEngine:
def generate_recommendations(self, user_id):
user_history = self.get_user_history(user_id)
similar_users = self.find_similar_users(user_history)
recommendations = []
for user in similar_users:
items = self.get_user_items(user)
recommendations.extend(self.filter_unseen_items(items, user_history))
return self.rank_recommendations(recommendations)
```]]></snippet>
</snippets>
</example>
<example>
<user_input>Where is the analytics tracking implemented?</user_input>
<snippets>
<snippet><![CDATA[```typescript services/Analytics.ts
export class AnalyticsService {
async trackEvent(event: AnalyticsEvent) {
await this.segmentClient.track({
userId: event.userId,
event: event.name,
properties: event.properties,
timestamp: new Date()
});
await this.store.incrementEventCount(event.name);
}
}
```]]></snippet>
</snippets>
</example>
</dataset>