Skip to content

Commit a7e30c0

Browse files
committed
feat(#64): Adiciona request, response e service ao conteúdo
1 parent 59de765 commit a7e30c0

File tree

4 files changed

+76
-2
lines changed

4 files changed

+76
-2
lines changed
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import 'dart:convert';
2+
3+
class ContentRequest {
4+
final String title;
5+
final String content;
6+
final String trailID;
7+
8+
ContentRequest(
9+
{required this.title, required this.content, required this.trailID});
10+
11+
Map<String, dynamic> toJson() {
12+
return <String, dynamic>{
13+
'title': title,
14+
'content': content,
15+
'trailID': trailID,
16+
};
17+
}
18+
19+
factory ContentRequest.fromJsonString(String jsonString) {
20+
final json = jsonDecode(jsonString);
21+
22+
return ContentRequest(
23+
title: json['title']! as String,
24+
content: json['content'] as String,
25+
trailID: json['trailID'] as String,
26+
);
27+
}
28+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import 'dart:convert';
2+
3+
class ContentResponse {
4+
final String title;
5+
final String content;
6+
final String trailID;
7+
8+
ContentResponse(this.title, this.content, this.trailID);
9+
factory ContentResponse.fromJsonString(String jsonString) {
10+
Map<String, dynamic> json = jsonDecode(jsonString);
11+
12+
return ContentResponse(
13+
json['title'] as String,
14+
json['content'] as String,
15+
json['trailID'] as String,
16+
);
17+
}
18+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import 'package:aranduapp/core/log/log.dart';
2+
import 'package:aranduapp/core/network/base_api.dart';
3+
import 'package:aranduapp/ui/content/model/content_request.dart';
4+
import 'package:aranduapp/ui/content/model/content_response.dart';
5+
import 'package:dio/dio.dart';
6+
7+
class ContentService {
8+
Future<List<ContentResponse>?> getContents(
9+
ContentRequest contentRequest) async {
10+
Log.d(
11+
'Request Content: ${contentRequest.title}, ${contentRequest.content}, ${contentRequest.trailID}');
12+
13+
Response response = await BaseApi.getInstance(auth: true)
14+
.get(path: '/contents/trail/{id}', data: contentRequest.toJson());
15+
16+
Log.d('Response Content: ${response.toString()}');
17+
18+
if (response.data != null) {
19+
List<dynamic> contentList = response.data as List<dynamic>;
20+
return contentList
21+
.map((contentJson) => ContentResponse.fromJsonString(contentJson))
22+
.toList();
23+
} else {
24+
Log.e('Não é um conteúdo');
25+
return null;
26+
}
27+
}
28+
}

lib/ui/content/view/content_view.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ import 'package:aranduapp/ui/content/viewmodel/content_viewmodel.dart';
44
import 'package:flutter_html/flutter_html.dart'; // Pacote para renderizar HTML
55
import 'package:aranduapp/ui/home/view/home_view.dart';
66

7-
class Content extends StatelessWidget {
8-
const Content({super.key});
7+
class ContentView extends StatelessWidget {
8+
const ContentView({super.key});
99

1010
@override
1111
Widget build(BuildContext context) {

0 commit comments

Comments
 (0)