add games
This commit is contained in:
@@ -94,7 +94,7 @@ class BackendApi {
|
||||
if (map == null) {
|
||||
throw Exception('Backend: Unexpected response format');
|
||||
}
|
||||
if (map['ok'] != true) {
|
||||
if (map['ok'] != true && map['success'] != true) {
|
||||
// ignore: avoid_print
|
||||
print('Backend logical error. URL: ${_dio.options.baseUrl}, payload: $payload, data: $map');
|
||||
throw Exception('Backend responded with error: ${map['error']}');
|
||||
@@ -115,6 +115,20 @@ class BackendApi {
|
||||
return (map['items'] as List).cast<Map<String, dynamic>>();
|
||||
}
|
||||
|
||||
Future<List<Map<String, dynamic>>> getGames(
|
||||
{String? status, String? q, int offset = 0, int limit = 50, String? lang}) async {
|
||||
final map = await _post({
|
||||
'action': 'get_list',
|
||||
'type': 'game',
|
||||
if (status != null) 'status': status,
|
||||
if (q != null && q.isNotEmpty) 'q': q,
|
||||
if (lang != null && lang.isNotEmpty) 'lang': lang,
|
||||
'offset': offset,
|
||||
'limit': limit,
|
||||
});
|
||||
return (map['items'] as List).cast<Map<String, dynamic>>();
|
||||
}
|
||||
|
||||
Future<void> setStatus({
|
||||
required String type, // 'movie' | 'episode'
|
||||
required int refId,
|
||||
@@ -264,4 +278,32 @@ class BackendApi {
|
||||
Future<void> deleteShow(int showId) async {
|
||||
await _post({'action': 'delete_show', 'show_id': showId});
|
||||
}
|
||||
|
||||
Future<Map<String, dynamic>> setGameStatus({
|
||||
required int igdbId,
|
||||
required String name,
|
||||
String? originalName,
|
||||
required int status, // 0=Init,1=Progress,2=Done
|
||||
String? note,
|
||||
String? lang,
|
||||
String? title,
|
||||
String? summary,
|
||||
String? storyline,
|
||||
String? coverUrl,
|
||||
}) async {
|
||||
final map = await _post({
|
||||
'action': 'set_game_status',
|
||||
'igdb_id': igdbId,
|
||||
'name': name,
|
||||
if (originalName != null) 'original_name': originalName,
|
||||
'status': status,
|
||||
if (note != null) 'note': note,
|
||||
if (lang != null && lang.isNotEmpty) 'lang': lang,
|
||||
if (title != null) 'title': title,
|
||||
if (summary != null) 'summary': summary,
|
||||
if (storyline != null) 'storyline': storyline,
|
||||
if (coverUrl != null) 'cover_url': coverUrl,
|
||||
});
|
||||
return (map['game'] as Map).cast<String, dynamic>();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,37 @@
|
||||
import 'package:dio/dio.dart';
|
||||
|
||||
import '../../core/config.dart';
|
||||
|
||||
class IgdbApi {
|
||||
final Dio _dio;
|
||||
|
||||
IgdbApi()
|
||||
: _dio = Dio(
|
||||
BaseOptions(
|
||||
baseUrl: AppConfig.backendBaseUrl,
|
||||
headers: const {'Accept': 'application/json'},
|
||||
),
|
||||
);
|
||||
|
||||
Future<List<Map<String, dynamic>>> searchGames(String query,
|
||||
{int limit = 20, String lang = 'de'}) async {
|
||||
final res = await _dio.get(
|
||||
'',
|
||||
queryParameters: {
|
||||
'action': 'search',
|
||||
'query': query,
|
||||
'limit': limit,
|
||||
'lang': lang,
|
||||
'check_external': 1,
|
||||
},
|
||||
);
|
||||
if (res.statusCode != 200) {
|
||||
throw Exception('IGDB search HTTP ${res.statusCode}');
|
||||
}
|
||||
final data = res.data;
|
||||
if (data is Map && data['results'] is List) {
|
||||
return (data['results'] as List).cast<Map<String, dynamic>>();
|
||||
}
|
||||
throw Exception('IGDB search: unerwartetes Antwortformat');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user