-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(diec_repository): ♻️ extract repository
- Loading branch information
1 parent
8707377
commit 61abd65
Showing
10 changed files
with
65 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import 'dart:convert' show json; | ||
|
||
import 'package:flutter/foundation.dart' show debugPrint, immutable; | ||
import 'package:http/http.dart' as http; | ||
|
||
import '../model/search_condition.dart'; | ||
|
||
@immutable | ||
final class DIECRepository { | ||
final String authority; | ||
|
||
const DIECRepository({this.authority = 'dlc.iec.cat'}); | ||
|
||
Future<Map<String, dynamic>> autocompleteEntries( | ||
String query, { | ||
required SearchCondition searchCondition, | ||
}) async { | ||
final response = await http.post( | ||
Uri.https( | ||
authority, | ||
'/Results/CompleteEntradaText', | ||
{ | ||
'EntradaText': query, | ||
'OperEntrada': '${searchCondition.index}', | ||
}, | ||
), | ||
headers: const {'Content-Type': 'application/json'}, | ||
); | ||
|
||
return _parseResponse(response); | ||
} | ||
|
||
Future<Map<String, dynamic>> definitionEntries(String id) async { | ||
final response = await http.post( | ||
Uri.https(authority, '/Results/Accepcio', {'id': id}), | ||
headers: const {'Content-Type': 'application/json'}, | ||
); | ||
|
||
return _parseResponse(response); | ||
} | ||
|
||
Map<String, dynamic> _parseResponse(http.Response response) { | ||
if (response.statusCode != 200) { | ||
debugPrint("Can't find definition"); | ||
} | ||
|
||
return json.decode(response.body) as Map<String, dynamic>; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters