-
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
c391733
commit 1d41d6f
Showing
11 changed files
with
170 additions
and
207 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,16 @@ | ||
import 'package:aranduapp/core/log/log.dart'; | ||
import 'package:aranduapp/core/network/studio_maker_api.dart'; | ||
import 'package:aranduapp/ui/subjects/model/subject_model.dart'; | ||
import 'package:dio/dio.dart'; | ||
import 'package:aranduapp/core/network/auth_api.dart'; | ||
import 'package:aranduapp/core/network/token_manager/repository/auth_repository.dart'; | ||
import 'package:get_it/get_it.dart'; | ||
|
||
class JoinSubjectsService { | ||
Future<bool> isUsersubscribe(String subjectId) async { | ||
try { | ||
Response response = await StudioMakerApi.getInstance().get( | ||
path: '/users/{userId}/subscribedSubjects'); | ||
return response.data['isSubscribe'] ?? false; | ||
} catch (e) { | ||
Log.d('Erro ao verificar inscrição: $e'); | ||
return false; | ||
} | ||
} | ||
Future<void> joinSubjects(String subjectId) async { | ||
|
||
//TODO: isso está errado | ||
String userId = (await GetIt.I<AuthRepository>().getUser()).id; | ||
|
||
Future<SubjectModel> getJoinSubjects(String subjectId) async { | ||
Response response = | ||
await StudioMakerApi.getInstance().get(path:'/subjects/$subjectId'); | ||
await AuthApi.getInstance(auth: true) | ||
.post(path: '/users/$userId/subjects/subscribe/$subjectId'); | ||
|
||
return SubjectModel.fromJson(response.data); | ||
return; | ||
} | ||
} |
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
25 changes: 5 additions & 20 deletions
25
lib/ui/join_subjects/viewmodel/join_subjects_viewmodel.dart
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,33 +1,18 @@ | ||
import 'package:aranduapp/core/state/command.dart'; | ||
import 'package:aranduapp/ui/join_subjects/service/join_subjects_service.dart'; | ||
import 'package:aranduapp/ui/subjects/model/subject_model.dart'; | ||
import 'package:async/async.dart'; | ||
import 'package:flutter/material.dart'; | ||
import 'package:get_it/get_it.dart'; | ||
|
||
class JoinSubjectsViewmodel extends ChangeNotifier { | ||
late Command0<SubjectModel> joinsubjectsCommand; | ||
|
||
final bool _isSubscribe = false; | ||
SubjectModel? _subject; | ||
|
||
bool get isSubscribe => _isSubscribe; | ||
SubjectModel? get subject => _subject; | ||
late Command1<void, String> joinsubjectsCommand; | ||
|
||
JoinSubjectsViewmodel() { | ||
joinsubjectsCommand = Command0<SubjectModel>(joinsubjects); | ||
} | ||
|
||
Future<void> subjectDetails(String subjectId) async { | ||
_subject = await GetIt.instance<JoinSubjectsService>() | ||
.getJoinSubjects(subjectId); | ||
notifyListeners(); | ||
joinsubjectsCommand = Command1(joinsubjects); | ||
} | ||
|
||
Future<Result<SubjectModel>> joinsubjects() async { | ||
if (_subject == null) { | ||
return Result.error('sem disciplina.'); | ||
} | ||
return Result.value(_subject!); | ||
Future<Result<void>> joinsubjects(String subjectId) async { | ||
await GetIt.instance<JoinSubjectsService>().joinSubjects(subjectId); | ||
return Result.value(null); | ||
} | ||
} |
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
Oops, something went wrong.