-
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.
Merge pull request #95 from fga-eps-mds/feat#64/Journey-backend
Feat#64/journey backend
- Loading branch information
Showing
8 changed files
with
70 additions
and
72 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,23 @@ | ||
import 'dart:convert'; | ||
|
||
class JourneyModel { | ||
final String id; | ||
final String title; | ||
final String description; | ||
|
||
JourneyModel({ | ||
required this.id, | ||
required this.title, | ||
required this.description, | ||
}); | ||
|
||
factory JourneyModel.fromJsonString(String jsonString) { | ||
Map<String, dynamic> json = jsonDecode(jsonString); | ||
|
||
return JourneyModel( | ||
id: json['_id']! as String, | ||
title: json['title']! as String, | ||
description: json['description']! as String, | ||
); | ||
} | ||
} |
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,31 +1,23 @@ | ||
import 'dart:convert'; | ||
|
||
class JourneyRequest { | ||
final String title; | ||
final String description; | ||
final String pointId; | ||
final String subjectId; | ||
|
||
JourneyRequest({ | ||
required this.title, | ||
required this.description, | ||
required this.pointId, | ||
required this.subjectId, | ||
}); | ||
|
||
Map<String, dynamic> toJson() { | ||
return <String, dynamic>{ | ||
'title': title, | ||
'description': description, | ||
'pointId': pointId, | ||
'subjectId': subjectId, | ||
}; | ||
} | ||
|
||
factory JourneyRequest.fromJsonString(String jsonString) { | ||
final json = jsonDecode(jsonString); | ||
|
||
return JourneyRequest( | ||
title: json['title']! as String, | ||
description: json['description']! as String, | ||
pointId: json['pointId']! as String, | ||
subjectId: json['subjectId']! as String, | ||
); | ||
} | ||
} |
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,27 +1,27 @@ | ||
import 'package:aranduapp/core/log/log.dart'; | ||
import 'package:aranduapp/core/network/base_api.dart'; | ||
import 'package:aranduapp/core/network/studio_maker_api.dart'; | ||
import 'package:aranduapp/ui/journey/model/journey_request.dart'; | ||
import 'package:aranduapp/ui/journey/model/journey_response.dart'; | ||
import 'package:aranduapp/ui/journey/model/journey_model.dart'; | ||
import 'package:dio/dio.dart'; | ||
|
||
class JourneyService { | ||
Future<List<JourneyResponse>?> getJourneys(JourneyRequest journeyRequest) async { | ||
Log.d('Request Journey: ${journeyRequest.title}, ${journeyRequest.description}, ${journeyRequest.pointId}'); | ||
Future<List<JourneyModel>> getJourneys(JourneyRequest journeyRequest) async { | ||
Response response = await StudioMakerApi.getInstance() | ||
.get(path: '/journeys/subjects/${journeyRequest.subjectId}'); | ||
|
||
Response response = await BaseApi.getInstance(auth: true) | ||
.get(path: '/journeys', data: journeyRequest.toJson()); | ||
List<dynamic> subjectList = response.data as List<dynamic>; | ||
|
||
Log.d('Response Journey: ${response.toString()}'); | ||
Log.i(subjectList); | ||
|
||
if (response.data != null) { | ||
List<dynamic> journeyList = response.data as List<dynamic>; | ||
return journeyList | ||
.map((journeyJson) => JourneyResponse.fromJsonString(journeyJson)) | ||
.toList(); | ||
} else { | ||
Log.e('Não é uma lista'); | ||
return null; | ||
} | ||
|
||
var res = subjectList.map((e) { | ||
final Map<String, dynamic> subjectMap = e as Map<String, dynamic>; | ||
|
||
return JourneyModel( | ||
id: subjectMap['_id']! as String, | ||
title: subjectMap['title']! as String, | ||
description: subjectMap['description']! as String); | ||
}).toList(); | ||
|
||
return res; | ||
} | ||
} |
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 |
---|---|---|
@@ -1,30 +1,22 @@ | ||
import 'package:aranduapp/core/state/command.dart'; | ||
import 'package:aranduapp/ui/journey/model/journey_request.dart'; | ||
import 'package:aranduapp/ui/journey/model/journey_response.dart'; | ||
import 'package:aranduapp/ui/journey/model/journey_model.dart'; | ||
import 'package:aranduapp/ui/journey/service/journey_service.dart'; | ||
import 'package:async/async.dart'; | ||
import 'package:flutter/material.dart'; | ||
import 'package:get_it/get_it.dart'; | ||
|
||
class JourneyViewModel extends ChangeNotifier { | ||
List<JourneyResponse> journeys = []; | ||
|
||
late Command0<List<JourneyRequest>> journeyCommand; | ||
late Command1<List<JourneyModel>, String> getJourneyCommand; | ||
|
||
JourneyViewModel() { | ||
journeyCommand = Command0(journey); | ||
|
||
journeyCommand.execute(); | ||
getJourneyCommand = Command1(getJourney); | ||
} | ||
|
||
Future<Result<List<JourneyRequest>>> journey() async { | ||
|
||
await Future.delayed(const Duration(seconds: 1)); | ||
|
||
final journeyRequest = JourneyRequest( | ||
title: "Viagem ao Parque", | ||
description: "Explorar o parque local com os amigos.", | ||
pointId: "123", | ||
); | ||
Future<Result<List<JourneyModel>>> getJourney(String subjectId) async { | ||
List<JourneyModel> res = await GetIt.instance<JourneyService>() | ||
.getJourneys(JourneyRequest(subjectId: subjectId)); | ||
|
||
return Result.value(List.generate(50, (_) => journeyRequest)); | ||
return Result.value(res); | ||
} | ||
} |
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