- backend/routes/todos.js: 오늘의 할일 조회 시 KST 기준으로 날짜 계산 - backend/routes/schedules.js: 주간/월간 일정 조회 시 KST 기준으로 날짜 범위 계산 - backend/routes/bible.js: 오늘의 성경 구절 조회 시 KST 기준으로 날짜 계산 - flutter_app: Mock 데이터 사용 시 타임존 관련 주석 추가
90 lines
2.7 KiB
Dart
90 lines
2.7 KiB
Dart
import "../config/api_config.dart";
|
|
import "../models/todo_item.dart";
|
|
import "api_client.dart";
|
|
import "mock_data.dart";
|
|
|
|
class TodoService {
|
|
final ApiClient _client;
|
|
|
|
TodoService(this._client);
|
|
|
|
Future<List<TodoItem>> fetchTodos() async {
|
|
if (ApiConfig.useMockData) {
|
|
return List<TodoItem>.from(MockDataStore.todos);
|
|
}
|
|
final data = await _client.getList(ApiConfig.todos);
|
|
return data
|
|
.map((item) => TodoItem.fromJson(item as Map<String, dynamic>))
|
|
.toList();
|
|
}
|
|
|
|
Future<List<TodoItem>> fetchTodayTodos() async {
|
|
if (ApiConfig.useMockData) {
|
|
// Using device's local timezone (should be Asia/Seoul for Korean users)
|
|
final now = DateTime.now();
|
|
final today = DateTime(now.year, now.month, now.day);
|
|
final tomorrow = today.add(const Duration(days: 1));
|
|
|
|
return MockDataStore.todos.where((todo) {
|
|
if (todo.completed) {
|
|
// If completed, only show if it was due today
|
|
if (todo.dueDate == null) return false;
|
|
return todo.dueDate!.isAfter(today.subtract(const Duration(milliseconds: 1))) &&
|
|
todo.dueDate!.isBefore(tomorrow);
|
|
}
|
|
|
|
// If not completed:
|
|
// 1. No due date -> show
|
|
// 2. Due today or before -> show
|
|
if (todo.dueDate == null) return true;
|
|
return todo.dueDate!.isBefore(tomorrow);
|
|
}).toList();
|
|
}
|
|
final data = await _client.getList("${ApiConfig.todos}/today");
|
|
return data
|
|
.map((item) => TodoItem.fromJson(item as Map<String, dynamic>))
|
|
.toList();
|
|
}
|
|
|
|
Future<TodoItem> createTodo(TodoItem todo) async {
|
|
if (ApiConfig.useMockData) {
|
|
final created = TodoItem(
|
|
id: "todo-${DateTime.now().millisecondsSinceEpoch}",
|
|
familyMemberId: todo.familyMemberId,
|
|
title: todo.title,
|
|
completed: todo.completed,
|
|
dueDate: todo.dueDate,
|
|
);
|
|
MockDataStore.todos.add(created);
|
|
return created;
|
|
}
|
|
final data = await _client.post(ApiConfig.todos, todo.toJson());
|
|
return TodoItem.fromJson(data);
|
|
}
|
|
|
|
Future<TodoItem> updateTodo(TodoItem todo) async {
|
|
if (ApiConfig.useMockData) {
|
|
final index = MockDataStore.todos.indexWhere(
|
|
(item) => item.id == todo.id,
|
|
);
|
|
if (index != -1) {
|
|
MockDataStore.todos[index] = todo;
|
|
}
|
|
return todo;
|
|
}
|
|
final data = await _client.put(
|
|
"${ApiConfig.todos}/${todo.id}",
|
|
todo.toJson(),
|
|
);
|
|
return TodoItem.fromJson(data);
|
|
}
|
|
|
|
Future<void> deleteTodo(String id) async {
|
|
if (ApiConfig.useMockData) {
|
|
MockDataStore.todos.removeWhere((item) => item.id == id);
|
|
return;
|
|
}
|
|
await _client.delete("${ApiConfig.todos}/$id");
|
|
}
|
|
}
|