34 lines
1,008 B
Dart
34 lines
1,008 B
Dart
|
|
/// 일정 API 서비스
|
||
|
|
library;
|
||
|
|
|
||
|
|
import 'package:intl/intl.dart';
|
||
|
|
import '../models/schedule.dart';
|
||
|
|
import 'api_client.dart';
|
||
|
|
|
||
|
|
/// 오늘 날짜 (KST) 반환
|
||
|
|
String getTodayKST() {
|
||
|
|
final now = DateTime.now();
|
||
|
|
return DateFormat('yyyy-MM-dd').format(now);
|
||
|
|
}
|
||
|
|
|
||
|
|
/// 일정 목록 조회 (월별)
|
||
|
|
Future<List<Schedule>> getSchedules(int year, int month) async {
|
||
|
|
final response = await dio.get('/schedules', queryParameters: {
|
||
|
|
'year': year.toString(),
|
||
|
|
'month': month.toString(),
|
||
|
|
});
|
||
|
|
final List<dynamic> data = response.data;
|
||
|
|
return data.map((json) => Schedule.fromJson(json)).toList();
|
||
|
|
}
|
||
|
|
|
||
|
|
/// 다가오는 일정 N개 조회 (오늘 이후) - 웹과 동일
|
||
|
|
Future<List<Schedule>> getUpcomingSchedules(int limit) async {
|
||
|
|
final todayStr = getTodayKST();
|
||
|
|
final response = await dio.get('/schedules', queryParameters: {
|
||
|
|
'startDate': todayStr,
|
||
|
|
'limit': limit.toString(),
|
||
|
|
});
|
||
|
|
final List<dynamic> data = response.data;
|
||
|
|
return data.map((json) => Schedule.fromJson(json)).toList();
|
||
|
|
}
|