-
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.
- Loading branch information
1 parent
f6f3eb1
commit 4683a6c
Showing
10 changed files
with
181 additions
and
148 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
|
||
import 'package:aranduapp/core/log/log.dart'; | ||
import 'package:dio/dio.dart'; | ||
|
||
class StudioMakerApi { | ||
final Dio _dio; | ||
|
||
static StudioMakerApi? _instance; | ||
|
||
final String url = 'https://arandu-studio-maker.onrender.com'; | ||
|
||
StudioMakerApi._internal() : _dio = Dio() { | ||
_dio.options.baseUrl = url; | ||
_dio.options.connectTimeout = const Duration(seconds: 5); | ||
_dio.options.receiveTimeout = const Duration(seconds: 5); | ||
|
||
|
||
_dio.interceptors.add(LogInterceptor( | ||
requestBody: true, | ||
responseBody: true, | ||
requestHeader: true, | ||
error: true, | ||
responseHeader: true, | ||
request: true)); | ||
} | ||
|
||
static StudioMakerApi getInstance() { | ||
return _instance ??= StudioMakerApi._internal(); | ||
} | ||
|
||
Future<Response> get( | ||
{required String path, Map<String, dynamic>? data}) async { | ||
try { | ||
return await _dio.get(path, data: data); | ||
} catch (e) { | ||
Log.e(e); | ||
rethrow; | ||
} | ||
} | ||
|
||
Future<Response> post({required String path, Object? data}) async { | ||
try { | ||
return await _dio.post(path, data: data); | ||
} catch (e) { | ||
Log.e(e); | ||
rethrow; | ||
} | ||
} | ||
|
||
Future<Response> patch({required String path, Object? data}) async { | ||
try { | ||
return await _dio.patch(path, data: data); | ||
} catch (e) { | ||
Log.e(e); | ||
rethrow; | ||
} | ||
} | ||
|
||
Future<Response> put({required String path, Object? data}) async { | ||
try { | ||
return await _dio.put(path, data: data); | ||
} catch (e) { | ||
Log.e(e); | ||
rethrow; | ||
} | ||
} | ||
} |
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,33 @@ | ||
import 'dart:convert'; | ||
|
||
class Subject { | ||
final String name; | ||
final String shortName; | ||
final String description; | ||
|
||
|
||
Subject({ | ||
required this.name, | ||
required this.shortName, | ||
required this.description, | ||
}); | ||
|
||
Map<String, dynamic> toJson() { | ||
return <String, dynamic>{ | ||
'name': name, | ||
'shortName': shortName, | ||
'description': description , | ||
}; | ||
} | ||
|
||
factory Subject.fromJson(String jsonString) { | ||
final json = jsonDecode(jsonString); | ||
|
||
return Subject( | ||
name: json['name']! as String, | ||
shortName: json['shortName']! as String, | ||
description: json['description']! as String, | ||
); | ||
} | ||
} | ||
|
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -1,28 +1,24 @@ | ||
import 'package:aranduapp/core/log/log.dart'; | ||
import 'package:aranduapp/core/network/base_api.dart'; | ||
import 'package:aranduapp/ui/subjects/model/subjects_request.dart'; | ||
import 'package:aranduapp/ui/subjects/model/subjects_response.dart'; | ||
import 'package:aranduapp/core/network/studio_maker_api.dart'; | ||
import 'package:aranduapp/ui/subjects/model/subject.dart'; | ||
import 'package:dio/dio.dart'; | ||
|
||
class SubjectService { | ||
Future<List<SubjectsResponse>?> getSubjects( | ||
SubjectsRequest subjectRequest) async { | ||
Log.d( | ||
'Request Subject: ${subjectRequest.title}, ${subjectRequest.description}'); | ||
Future<List<Subject>> getSubjects() async { | ||
Response response = | ||
await StudioMakerApi.getInstance().get(path: '/subjects'); | ||
|
||
Response response = await BaseApi.getInstance(auth: true) | ||
.get(path: '/subjects', data: subjectRequest.toJson()); | ||
List<dynamic> subjectList = response.data as List<dynamic>; | ||
|
||
Log.d('Response Subject: ${response.toString()}'); | ||
Log.i(subjectList); | ||
|
||
if (response.data != null) { | ||
List<dynamic> subjectList = response.data as List<dynamic>; | ||
return subjectList | ||
.map((subjectJson) => SubjectsResponse.fromJsonString(subjectJson)) | ||
.toList(); | ||
} else { | ||
Log.e('Não é uma lista'); | ||
return null; | ||
} | ||
return subjectList.map((e) { | ||
final Map<String, dynamic> subjectMap = e as Map<String, dynamic>; | ||
|
||
return Subject( | ||
name: subjectMap['name']!, | ||
shortName: subjectMap['shortName']!, | ||
description: subjectMap['description']!); | ||
}).toList(); | ||
} | ||
} |
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
Oops, something went wrong.