48 lines
1.4 KiB
Dart
48 lines
1.4 KiB
Dart
import '../../../domain/models/auth.dart';
|
|
import '../../../domain/models/server_config.dart';
|
|
import 'localiser_client.dart';
|
|
|
|
class OnboardingChecklist {
|
|
const OnboardingChecklist({
|
|
required this.hasAdmin,
|
|
required this.hasFloors,
|
|
required this.hasRooms,
|
|
required this.hasSensorsPlaced,
|
|
required this.hasTags,
|
|
});
|
|
|
|
final bool hasAdmin;
|
|
final bool hasFloors;
|
|
final bool hasRooms;
|
|
final bool hasSensorsPlaced;
|
|
final bool hasTags;
|
|
|
|
factory OnboardingChecklist.fromJson(Map<String, dynamic> json) =>
|
|
OnboardingChecklist(
|
|
hasAdmin: json['has_admin'] as bool,
|
|
hasFloors: json['has_floors'] as bool,
|
|
hasRooms: json['has_rooms'] as bool,
|
|
hasSensorsPlaced: json['has_sensors_placed'] as bool,
|
|
hasTags: json['has_tags'] as bool,
|
|
);
|
|
}
|
|
|
|
class OnboardingClient extends LocaliserdClient {
|
|
OnboardingClient({required super.config});
|
|
|
|
Future<OnboardingChecklist> getChecklist() async {
|
|
final json = await get('/api/onboarding') as Map<String, dynamic>;
|
|
return OnboardingChecklist.fromJson(json);
|
|
}
|
|
|
|
/// Creates the first admin user. Only succeeds when no users exist yet.
|
|
/// Returns the JWT so the caller can immediately authenticate.
|
|
Future<TokenResponse> setup(String username, String password) async {
|
|
final json = await post('/api/setup', {
|
|
'username': username,
|
|
'password': password,
|
|
}) as Map<String, dynamic>;
|
|
return TokenResponse.fromJson(json);
|
|
}
|
|
}
|