1
0
mirror of https://github.com/immich-app/immich.git synced 2024-12-24 10:37:28 +02:00
immich/mobile/lib/shared/services/server_info.service.dart
shenlong b05132a01a
refactor(mobile): server info to use data classes instead of dtos (#4591)
* refactor: server info model to use data classes instead of dtos

* mobile: add return types and refactor private variables in map / stack

---------

Co-authored-by: shalong-tanwen <139912620+shalong-tanwen@users.noreply.github.com>
2023-10-22 15:15:34 -05:00

69 lines
2.0 KiB
Dart

import 'package:flutter/material.dart';
import 'package:hooks_riverpod/hooks_riverpod.dart';
import 'package:immich_mobile/shared/models/server_info/server_config.model.dart';
import 'package:immich_mobile/shared/models/server_info/server_disk_info.model.dart';
import 'package:immich_mobile/shared/models/server_info/server_features.model.dart';
import 'package:immich_mobile/shared/models/server_info/server_version.model.dart';
import 'package:immich_mobile/shared/providers/api.provider.dart';
import 'package:immich_mobile/shared/services/api.service.dart';
final serverInfoServiceProvider = Provider(
(ref) => ServerInfoService(
ref.watch(apiServiceProvider),
),
);
class ServerInfoService {
final ApiService _apiService;
ServerInfoService(this._apiService);
Future<ServerDiskInfo?> getServerInfo() async {
try {
final dto = await _apiService.serverInfoApi.getServerInfo();
if (dto != null) {
return ServerDiskInfo.fromDto(dto);
}
} catch (e) {
debugPrint("Error [getServerInfo] ${e.toString()}");
}
return null;
}
Future<ServerVersion?> getServerVersion() async {
try {
final dto = await _apiService.serverInfoApi.getServerVersion();
if (dto != null) {
return ServerVersion.fromDto(dto);
}
} catch (e) {
debugPrint("Error [getServerVersion] ${e.toString()}");
}
return null;
}
Future<ServerFeatures?> getServerFeatures() async {
try {
final dto = await _apiService.serverInfoApi.getServerFeatures();
if (dto != null) {
return ServerFeatures.fromDto(dto);
}
} catch (e) {
debugPrint("Error [getServerFeatures] ${e.toString()}");
}
return null;
}
Future<ServerConfig?> getServerConfig() async {
try {
final dto = await _apiService.serverInfoApi.getServerConfig();
if (dto != null) {
return ServerConfig.fromDto(dto);
}
} catch (e) {
debugPrint("Error [getServerConfig] ${e.toString()}");
}
return null;
}
}