Skip to content

Commit

Permalink
Merge pull request #3 from caions/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
caions authored Apr 17, 2024
2 parents 728ed99 + bd999fd commit 77de133
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 deletions.
11 changes: 5 additions & 6 deletions lib/api/api_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -102,12 +102,11 @@ class ApiService {
}

Future<void> deleteHabit(String habitId) async {
final body = jsonEncode({'id': habitId});
final response = await http.delete(_habitsUrl,
headers: {
'Content-Type': 'application/json; charset=UTF-8',
},
body: body);
final String deleteUrl = '$_habitsUrl/$habitId';

final response = await http.delete(Uri.parse(deleteUrl), headers: {
'Content-Type': 'application/json; charset=UTF-8',
});
if (response.statusCode != 200) {
throw Exception('Erro na requisição: ${response.body}');
}
Expand Down
11 changes: 9 additions & 2 deletions lib/registered_habits.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import 'package:flutter/material.dart';
import 'package:habit_tracker_frontend/api/api_service.dart';
import 'package:intl/intl.dart';

class RegisteredHabits extends ChangeNotifier {
List<HabitModel> memoryHabits = [];
Expand All @@ -11,9 +12,15 @@ class RegisteredHabits extends ChangeNotifier {
try {
memoryHabits = await apiService.getAllHabits();
memoryCompletedHabits = await apiService.getCompletedHabits();
final today = DateTime.now();
final brDateFormat = DateFormat('dd/MM/yyyy');
final formatedDateToday = brDateFormat.format(today);

for (var habit in memoryHabits) {
habit.completed = memoryCompletedHabits
.any((completedHabit) => completedHabit.habitId == habit.id);
habit.completed = memoryCompletedHabits.any((completedHabit) =>
completedHabit.habitId == habit.id &&
brDateFormat.format(completedHabit.completedDate) ==
formatedDateToday);
}
notifyListeners();
return memoryHabits;
Expand Down

0 comments on commit 77de133

Please sign in to comment.