refactor(todo): 移除 due_at 字段,改用 order 字段管理象限内顺序
This commit is contained in:
@@ -25,13 +25,13 @@ class TodoApi {
|
||||
Future<TodoResponse> createTodo({
|
||||
required String title,
|
||||
String? description,
|
||||
DateTime? dueAt,
|
||||
int priority = 1,
|
||||
int? order,
|
||||
List<String> scheduleItemIds = const [],
|
||||
}) async {
|
||||
final data = <String, dynamic>{'title': title, 'priority': priority};
|
||||
if (description != null) data['description'] = description;
|
||||
if (dueAt != null) data['due_at'] = dueAt.toIso8601String();
|
||||
if (order != null) data['order'] = order;
|
||||
if (scheduleItemIds.isNotEmpty) data['schedule_item_ids'] = scheduleItemIds;
|
||||
|
||||
final response = await _client.post(_prefix, data: data);
|
||||
@@ -42,16 +42,16 @@ class TodoApi {
|
||||
String id, {
|
||||
String? title,
|
||||
String? description,
|
||||
DateTime? dueAt,
|
||||
int? priority,
|
||||
int? order,
|
||||
String? status,
|
||||
List<String>? scheduleItemIds,
|
||||
}) async {
|
||||
final data = <String, dynamic>{};
|
||||
if (title != null) data['title'] = title;
|
||||
if (description != null) data['description'] = description;
|
||||
if (dueAt != null) data['due_at'] = dueAt.toIso8601String();
|
||||
if (priority != null) data['priority'] = priority;
|
||||
if (order != null) data['order'] = order;
|
||||
if (status != null) data['status'] = status;
|
||||
if (scheduleItemIds != null) data['schedule_item_ids'] = scheduleItemIds;
|
||||
|
||||
@@ -59,12 +59,19 @@ class TodoApi {
|
||||
return TodoResponse.fromJson(response.data);
|
||||
}
|
||||
|
||||
Future<void> updateTodoPriority(String id, int priority) async {
|
||||
try {
|
||||
await _client.patch('$_prefix/$id', data: {'priority': priority});
|
||||
} catch (_) {
|
||||
// Ignore response parsing errors, just need to know if request succeeded
|
||||
}
|
||||
Future<void> reorderTodos(List<TodoReorderItemPayload> items) async {
|
||||
final data = {
|
||||
'items': items
|
||||
.map(
|
||||
(item) => {
|
||||
'id': item.id,
|
||||
'priority': item.priority,
|
||||
'order': item.order,
|
||||
},
|
||||
)
|
||||
.toList(),
|
||||
};
|
||||
await _client.patch('$_prefix/reorder', data: data);
|
||||
}
|
||||
|
||||
Future<TodoResponse> completeTodo(String id) async {
|
||||
@@ -77,6 +84,18 @@ class TodoApi {
|
||||
}
|
||||
}
|
||||
|
||||
class TodoReorderItemPayload {
|
||||
final String id;
|
||||
final int priority;
|
||||
final int order;
|
||||
|
||||
const TodoReorderItemPayload({
|
||||
required this.id,
|
||||
required this.priority,
|
||||
required this.order,
|
||||
});
|
||||
}
|
||||
|
||||
class ScheduleItemBasic {
|
||||
final String id;
|
||||
final String title;
|
||||
@@ -107,7 +126,7 @@ class TodoResponse {
|
||||
final String ownerId;
|
||||
final String title;
|
||||
final String? description;
|
||||
final DateTime? dueAt;
|
||||
final int order;
|
||||
final int priority;
|
||||
final String status;
|
||||
final DateTime? completedAt;
|
||||
@@ -120,8 +139,8 @@ class TodoResponse {
|
||||
required this.ownerId,
|
||||
required this.title,
|
||||
this.description,
|
||||
this.dueAt,
|
||||
required this.priority,
|
||||
required this.order,
|
||||
required this.status,
|
||||
this.completedAt,
|
||||
required this.createdAt,
|
||||
@@ -136,10 +155,8 @@ class TodoResponse {
|
||||
ownerId: json['owner_id'] as String,
|
||||
title: json['title'] as String,
|
||||
description: json['description'] as String?,
|
||||
dueAt: json['due_at'] != null
|
||||
? DateTime.parse(json['due_at'] as String)
|
||||
: null,
|
||||
priority: json['priority'] as int,
|
||||
order: json['order'] as int,
|
||||
status: json['status'] as String,
|
||||
completedAt: json['completed_at'] != null
|
||||
? DateTime.parse(json['completed_at'] as String)
|
||||
@@ -157,8 +174,8 @@ class TodoResponse {
|
||||
String? ownerId,
|
||||
String? title,
|
||||
String? description,
|
||||
DateTime? dueAt,
|
||||
int? priority,
|
||||
int? order,
|
||||
String? status,
|
||||
DateTime? completedAt,
|
||||
DateTime? createdAt,
|
||||
@@ -170,8 +187,8 @@ class TodoResponse {
|
||||
ownerId: ownerId ?? this.ownerId,
|
||||
title: title ?? this.title,
|
||||
description: description ?? this.description,
|
||||
dueAt: dueAt ?? this.dueAt,
|
||||
priority: priority ?? this.priority,
|
||||
order: order ?? this.order,
|
||||
status: status ?? this.status,
|
||||
completedAt: completedAt ?? this.completedAt,
|
||||
createdAt: createdAt ?? this.createdAt,
|
||||
|
||||
Reference in New Issue
Block a user