forked from baron/baron-sso
namecard 연동
This commit is contained in:
38
frontend/lib/core/services/audit_service.dart
Normal file
38
frontend/lib/core/services/audit_service.dart
Normal file
@@ -0,0 +1,38 @@
|
||||
import 'dart:convert';
|
||||
import 'package:http/http.dart' as http;
|
||||
import 'package:flutter_dotenv/flutter_dotenv.dart';
|
||||
|
||||
class AuditService {
|
||||
static final String _baseUrl = dotenv.env['BACKEND_URL'] ?? 'http://localhost:3000';
|
||||
|
||||
static Future<void> logEvent({
|
||||
required String userId,
|
||||
required String eventType,
|
||||
required String status,
|
||||
String? details,
|
||||
}) async {
|
||||
final url = Uri.parse('$_baseUrl/api/v1/audit');
|
||||
|
||||
try {
|
||||
final response = await http.post(
|
||||
url,
|
||||
headers: {'Content-Type': 'application/json'},
|
||||
body: jsonEncode({
|
||||
'user_id': userId,
|
||||
'event_type': eventType,
|
||||
'status': status,
|
||||
'details': details,
|
||||
'timestamp': DateTime.now().toIso8601String(),
|
||||
}),
|
||||
);
|
||||
|
||||
if (response.statusCode >= 200 && response.statusCode < 300) {
|
||||
print("Audit log sent successfully");
|
||||
} else {
|
||||
print("Failed to send audit log: ${response.statusCode} ${response.body}");
|
||||
}
|
||||
} catch (e) {
|
||||
print("Error sending audit log: $e");
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user