2024-09-24 08:24:48 +02:00
|
|
|
import 'package:immich_mobile/interfaces/activity_api.interface.dart';
|
2024-01-05 07:20:55 +02:00
|
|
|
import 'package:immich_mobile/mixins/error_logger.mixin.dart';
|
2024-05-01 04:36:40 +02:00
|
|
|
import 'package:immich_mobile/models/activities/activity.model.dart';
|
2023-11-06 17:46:26 +02:00
|
|
|
import 'package:logging/logging.dart';
|
|
|
|
|
2024-01-05 07:20:55 +02:00
|
|
|
class ActivityService with ErrorLoggerMixin {
|
2024-09-24 08:24:48 +02:00
|
|
|
final IActivityApiRepository _activityApiRepository;
|
2024-01-05 07:20:55 +02:00
|
|
|
|
|
|
|
@override
|
|
|
|
final Logger logger = Logger("ActivityService");
|
2023-11-06 17:46:26 +02:00
|
|
|
|
2024-09-24 08:24:48 +02:00
|
|
|
ActivityService(this._activityApiRepository);
|
2023-11-06 17:46:26 +02:00
|
|
|
|
|
|
|
Future<List<Activity>> getAllActivities(
|
2024-01-05 07:20:55 +02:00
|
|
|
String albumId, {
|
2023-11-06 17:46:26 +02:00
|
|
|
String? assetId,
|
2024-01-05 07:20:55 +02:00
|
|
|
}) async {
|
|
|
|
return logError(
|
2024-09-24 08:24:48 +02:00
|
|
|
() => _activityApiRepository.getAll(albumId, assetId: assetId),
|
2024-01-05 07:20:55 +02:00
|
|
|
defaultValue: [],
|
2024-02-24 05:38:57 +02:00
|
|
|
errorMessage: "Failed to get all activities for album $albumId",
|
2024-01-05 07:20:55 +02:00
|
|
|
);
|
2023-11-06 17:46:26 +02:00
|
|
|
}
|
|
|
|
|
2024-09-24 08:24:48 +02:00
|
|
|
Future<ActivityStats> getStatistics(String albumId, {String? assetId}) async {
|
2024-01-05 07:20:55 +02:00
|
|
|
return logError(
|
2024-09-24 08:24:48 +02:00
|
|
|
() => _activityApiRepository.getStats(albumId, assetId: assetId),
|
|
|
|
defaultValue: const ActivityStats(comments: 0),
|
2024-02-24 05:38:57 +02:00
|
|
|
errorMessage: "Failed to statistics for album $albumId",
|
2024-01-05 07:20:55 +02:00
|
|
|
);
|
2023-11-06 17:46:26 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
Future<bool> removeActivity(String id) async {
|
2024-01-05 07:20:55 +02:00
|
|
|
return logError(
|
|
|
|
() async {
|
2024-09-24 08:24:48 +02:00
|
|
|
await _activityApiRepository.delete(id);
|
2024-01-05 07:20:55 +02:00
|
|
|
return true;
|
|
|
|
},
|
|
|
|
defaultValue: false,
|
2024-02-24 05:38:57 +02:00
|
|
|
errorMessage: "Failed to delete activity",
|
2024-01-05 07:20:55 +02:00
|
|
|
);
|
2023-11-06 17:46:26 +02:00
|
|
|
}
|
|
|
|
|
2024-01-05 07:20:55 +02:00
|
|
|
AsyncFuture<Activity> addActivity(
|
2023-11-06 17:46:26 +02:00
|
|
|
String albumId,
|
|
|
|
ActivityType type, {
|
|
|
|
String? assetId,
|
|
|
|
String? comment,
|
|
|
|
}) async {
|
2024-02-24 05:38:57 +02:00
|
|
|
return guardError(
|
2024-09-24 08:24:48 +02:00
|
|
|
() => _activityApiRepository.create(
|
|
|
|
albumId,
|
|
|
|
type,
|
|
|
|
assetId: assetId,
|
|
|
|
comment: comment,
|
|
|
|
),
|
2024-02-24 05:38:57 +02:00
|
|
|
errorMessage: "Failed to create $type for album $albumId",
|
|
|
|
);
|
2023-11-06 17:46:26 +02:00
|
|
|
}
|
|
|
|
}
|