OpenMediacenterMobileFlutter/lib/api/actor_api.dart
lukas-heiligenbrunner 9ef317f0ba outsourced lots of api calls to api folder
centered error message when failed loading video feed
display server url on settings page
2022-10-15 20:28:31 +02:00

37 lines
952 B
Dart

import 'dart:convert';
import '../log/log.dart';
import '../types/actor.dart';
import 'api.dart';
Future<List<Actor>> loadAllActors() async {
final data = await API.query("actor", "getAllActors", {});
final d = (jsonDecode(data) ?? []) as List<dynamic>;
final actors = d.map((e) => Actor.fromJson(e)).toList(growable: false);
return actors;
}
Future<List<Actor>> loadActorsOfVideo(int movieId) async {
final data =
await API.query("actor", "getActorsOfVideo", {'MovieId': movieId});
if (data == 'null') {
return [];
}
final d = jsonDecode(data);
List<Actor> dta = (d as List).map((e) => Actor.fromJson(e)).toList();
return dta;
}
Future<void> addActorToVideo(int actorId, int movieId) async {
final data = await API.query(
"actor", "addActorToVideo", {'ActorId': actorId, 'MovieId': movieId});
final d = jsonDecode(data);
if (d["result"] != "success") {
Log.w("couldn't add actor to video");
}
}