39 lines
1.3 KiB
Dart
39 lines
1.3 KiB
Dart
import './calendar_model.dart';
|
|
import '../services/generic_api_service.dart';
|
|
import 'package:intl/intl.dart';
|
|
|
|
class CalendarApiService {
|
|
final GenericApiService _apiService = GenericApiService();
|
|
|
|
// 獲取指定月份或範圍的行程
|
|
Future<List<CalendarEvent>> fetchEvents(String userId, DateTime month) async {
|
|
// 企業實作建議:僅抓取特定月份資料,減少手機負載
|
|
final sDate = DateTime(month.year, month.month, 1);
|
|
final eDate = DateTime(month.year, month.month + 1, 0);
|
|
|
|
String queryFilter = "1^500^start_time^*^personid^=^$userId";
|
|
|
|
return await _apiService.fetchList<CalendarEvent>(
|
|
tableName: "eip_new_calendar",
|
|
pk: "uuid",
|
|
queryFilter: queryFilter,
|
|
fromJson: (json) => CalendarEvent.fromJson(json),
|
|
);
|
|
}
|
|
|
|
// 新增/更新行程
|
|
Future<bool> saveEvent(CalendarEvent event) async {
|
|
final data = {
|
|
"uuid": event.uuid,
|
|
"title": event.title,
|
|
"cal_description": event.description,
|
|
"start_time": event.startTime?.toIso8601String(),
|
|
"end_time": event.endTime?.toIso8601String(),
|
|
"personid": event.personId,
|
|
"cal_finished": event.isFinished ? 'Y' : 'N',
|
|
"update_date": DateFormat('yyyy-MM-dd HH:mm:ss').format(DateTime.now()),
|
|
};
|
|
// return await _apiService.saveData("eip_new_calendar", data);
|
|
return true;
|
|
}
|
|
} |