👽 Update API to microservices

♻️ Refactor router pushes
This commit is contained in:
2025-07-17 14:35:09 +08:00
parent a7454edec0
commit e6c58b7b63
109 changed files with 9156 additions and 344 deletions

View File

@@ -165,7 +165,7 @@ class ChatRoomListTile extends HookConsumerWidget {
@riverpod
Future<List<SnChatRoom>> chatroomsJoined(Ref ref) async {
final client = ref.watch(apiClientProvider);
final resp = await client.get('/chat');
final resp = await client.get('/sphere/chat');
return resp.data
.map((e) => SnChatRoom.fromJson(e))
.cast<SnChatRoom>()
@@ -233,7 +233,10 @@ class ChatListScreen extends HookConsumerWidget {
if (result == null) return;
final client = ref.read(apiClientProvider);
try {
await client.post('/chat/direct', data: {'related_user_id': result.id});
await client.post(
'/sphere/chat/direct',
data: {'related_user_id': result.id},
);
ref.invalidate(chatroomsJoinedProvider);
} catch (err) {
showErrorAlert(err);
@@ -319,7 +322,7 @@ class ChatListScreen extends HookConsumerWidget {
leading: const Icon(Symbols.add),
onTap: () {
Navigator.pop(context);
context.push('/chat/new').then((value) {
context.pushNamed('chatNew').then((value) {
if (value != null) {
ref.invalidate(chatroomsJoinedProvider);
}
@@ -400,7 +403,10 @@ class ChatListScreen extends HookConsumerWidget {
room: item,
isDirect: item.type == 1,
onTap: () {
context.push('/chat/${item.id}');
context.pushNamed(
'chatRoom',
pathParameters: {'id': item.id},
);
},
);
},
@@ -436,7 +442,7 @@ Future<SnChatRoom?> chatroom(Ref ref, String? identifier) async {
if (identifier == null) return null;
try {
final client = ref.watch(apiClientProvider);
final resp = await client.get('/chat/$identifier');
final resp = await client.get('/sphere/chat/$identifier');
return SnChatRoom.fromJson(resp.data);
} catch (err) {
if (err is DioException && err.response?.statusCode == 404) {
@@ -451,7 +457,7 @@ Future<SnChatMember?> chatroomIdentity(Ref ref, String? identifier) async {
if (identifier == null) return null;
try {
final client = ref.watch(apiClientProvider);
final resp = await client.get('/chat/$identifier/members/me');
final resp = await client.get('/sphere/chat/$identifier/members/me');
return SnChatMember.fromJson(resp.data);
} catch (err) {
if (err is DioException && err.response?.statusCode == 404) {
@@ -575,7 +581,7 @@ class EditChatScreen extends HookConsumerWidget {
try {
final client = ref.watch(apiClientProvider);
final resp = await client.request(
id == null ? '/chat' : '/chat/$id',
id == null ? '/sphere/chat' : '/sphere/chat/$id',
data: {
'name': nameController.text,
'description': descriptionController.text,
@@ -731,7 +737,7 @@ class EditChatScreen extends HookConsumerWidget {
@riverpod
Future<List<SnChatMember>> chatroomInvites(Ref ref) async {
final client = ref.watch(apiClientProvider);
final resp = await client.get('/chat/invites');
final resp = await client.get('/sphere/chat/invites');
return resp.data
.map((e) => SnChatMember.fromJson(e))
.cast<SnChatMember>()
@@ -748,7 +754,7 @@ class _ChatInvitesSheet extends HookConsumerWidget {
Future<void> acceptInvite(SnChatMember invite) async {
try {
final client = ref.read(apiClientProvider);
await client.post('/chat/invites/${invite.chatRoom!.id}/accept');
await client.post('/sphere/chat/invites/${invite.chatRoom!.id}/accept');
ref.invalidate(chatroomInvitesProvider);
ref.invalidate(chatroomsJoinedProvider);
} catch (err) {
@@ -759,7 +765,9 @@ class _ChatInvitesSheet extends HookConsumerWidget {
Future<void> declineInvite(SnChatMember invite) async {
try {
final client = ref.read(apiClientProvider);
await client.post('/chat/invites/${invite.chatRoom!.id}/decline');
await client.post(
'/sphere/chat/invites/${invite.chatRoom!.id}/decline',
);
ref.invalidate(chatroomInvitesProvider);
} catch (err) {
showErrorAlert(err);

View File

@@ -6,7 +6,7 @@ part of 'chat.dart';
// RiverpodGenerator
// **************************************************************************
String _$chatroomsJoinedHash() => r'0c93fd3cb8fe5c87626836ced4f244bfa7598582';
String _$chatroomsJoinedHash() => r'3bb6389af07e81007680484d04bf5fe6f6c10571';
/// See also [chatroomsJoined].
@ProviderFor(chatroomsJoined)
@@ -25,7 +25,7 @@ final chatroomsJoinedProvider =
@Deprecated('Will be removed in 3.0. Use Ref instead')
// ignore: unused_element
typedef ChatroomsJoinedRef = AutoDisposeFutureProviderRef<List<SnChatRoom>>;
String _$chatroomHash() => r'8dac7aaac50932e6dd213039102d43c1cf5f1d4e';
String _$chatroomHash() => r'2b17d94728026420d18d6c383d2400cf4a070913';
/// Copied from Dart SDK
class _SystemHash {
@@ -164,7 +164,7 @@ class _ChatroomProviderElement
String? get identifier => (origin as ChatroomProvider).identifier;
}
String _$chatroomIdentityHash() => r'ad6ad09b6fc4cf7c4abe146ea97f8e364a3d4fd0';
String _$chatroomIdentityHash() => r'35e19a5a3e31752c79b97ba0358a7ec8fb8f6e99';
/// See also [chatroomIdentity].
@ProviderFor(chatroomIdentity)
@@ -286,7 +286,7 @@ class _ChatroomIdentityProviderElement
String? get identifier => (origin as ChatroomIdentityProvider).identifier;
}
String _$chatroomInvitesHash() => r'c15f06c1e9c6074e6159d9d1f4404f31250ce523';
String _$chatroomInvitesHash() => r'5cd6391b09c5517ede19bacce43b45c8d71dd087';
/// See also [chatroomInvites].
@ProviderFor(chatroomInvites)

View File

@@ -687,7 +687,7 @@ class ChatRoomScreen extends HookConsumerWidget {
IconButton(
icon: const Icon(Icons.more_vert),
onPressed: () {
context.push('/chat/$id/detail');
context.pushNamed('chatDetail', pathParameters: {'id': id});
},
),
const Gap(8),

View File

@@ -389,7 +389,7 @@ class _ChatRoomActionMenu extends HookConsumerWidget {
if ((chatIdentity.value?.role ?? 0) >= 50)
PopupMenuItem(
onTap: () {
context.pushReplacement('/chat/$id/edit');
context.pushReplacement('/sphere/chat/$id/edit');
},
child: Row(
children: [
@@ -421,7 +421,7 @@ class _ChatRoomActionMenu extends HookConsumerWidget {
).then((confirm) {
if (confirm) {
final client = ref.watch(apiClientProvider);
client.delete('/chat/$id');
client.delete('/sphere/chat/$id');
ref.invalidate(chatroomsJoinedProvider);
if (context.mounted) {
context.pop();
@@ -454,7 +454,7 @@ class _ChatRoomActionMenu extends HookConsumerWidget {
).then((confirm) {
if (confirm) {
final client = ref.watch(apiClientProvider);
client.delete('/chat/$id/members/me');
client.delete('/sphere/chat/$id/members/me');
ref.invalidate(chatroomsJoinedProvider);
if (context.mounted) {
context.pop();

View File

@@ -1,6 +1,5 @@
// dart format width=80
// coverage:ignore-file
// GENERATED CODE - DO NOT MODIFY BY HAND
// coverage:ignore-file
// ignore_for_file: type=lint
// ignore_for_file: unused_element, deprecated_member_use, deprecated_member_use_from_same_package, use_function_type_syntax_for_parameters, unnecessary_const, avoid_init_to_null, invalid_override_different_default_values_named, prefer_expression_function_bodies, annotate_overrides, invalid_annotation_target, unnecessary_question_mark
@@ -76,6 +75,130 @@ as String?,
}
/// Adds pattern-matching-related methods to [ChatRoomMemberState].
extension ChatRoomMemberStatePatterns on ChatRoomMemberState {
/// A variant of `map` that fallback to returning `orElse`.
///
/// It is equivalent to doing:
/// ```dart
/// switch (sealedClass) {
/// case final Subclass value:
/// return ...;
/// case _:
/// return orElse();
/// }
/// ```
@optionalTypeArgs TResult maybeMap<TResult extends Object?>(TResult Function( _ChatRoomMemberState value)? $default,{required TResult orElse(),}){
final _that = this;
switch (_that) {
case _ChatRoomMemberState() when $default != null:
return $default(_that);case _:
return orElse();
}
}
/// A `switch`-like method, using callbacks.
///
/// Callbacks receives the raw object, upcasted.
/// It is equivalent to doing:
/// ```dart
/// switch (sealedClass) {
/// case final Subclass value:
/// return ...;
/// case final Subclass2 value:
/// return ...;
/// }
/// ```
@optionalTypeArgs TResult map<TResult extends Object?>(TResult Function( _ChatRoomMemberState value) $default,){
final _that = this;
switch (_that) {
case _ChatRoomMemberState():
return $default(_that);}
}
/// A variant of `map` that fallback to returning `null`.
///
/// It is equivalent to doing:
/// ```dart
/// switch (sealedClass) {
/// case final Subclass value:
/// return ...;
/// case _:
/// return null;
/// }
/// ```
@optionalTypeArgs TResult? mapOrNull<TResult extends Object?>(TResult? Function( _ChatRoomMemberState value)? $default,){
final _that = this;
switch (_that) {
case _ChatRoomMemberState() when $default != null:
return $default(_that);case _:
return null;
}
}
/// A variant of `when` that fallback to an `orElse` callback.
///
/// It is equivalent to doing:
/// ```dart
/// switch (sealedClass) {
/// case Subclass(:final field):
/// return ...;
/// case _:
/// return orElse();
/// }
/// ```
@optionalTypeArgs TResult maybeWhen<TResult extends Object?>(TResult Function( List<SnChatMember> members, bool isLoading, int total, String? error)? $default,{required TResult orElse(),}) {final _that = this;
switch (_that) {
case _ChatRoomMemberState() when $default != null:
return $default(_that.members,_that.isLoading,_that.total,_that.error);case _:
return orElse();
}
}
/// A `switch`-like method, using callbacks.
///
/// As opposed to `map`, this offers destructuring.
/// It is equivalent to doing:
/// ```dart
/// switch (sealedClass) {
/// case Subclass(:final field):
/// return ...;
/// case Subclass2(:final field2):
/// return ...;
/// }
/// ```
@optionalTypeArgs TResult when<TResult extends Object?>(TResult Function( List<SnChatMember> members, bool isLoading, int total, String? error) $default,) {final _that = this;
switch (_that) {
case _ChatRoomMemberState():
return $default(_that.members,_that.isLoading,_that.total,_that.error);}
}
/// A variant of `when` that fallback to returning `null`
///
/// It is equivalent to doing:
/// ```dart
/// switch (sealedClass) {
/// case Subclass(:final field):
/// return ...;
/// case _:
/// return null;
/// }
/// ```
@optionalTypeArgs TResult? whenOrNull<TResult extends Object?>(TResult? Function( List<SnChatMember> members, bool isLoading, int total, String? error)? $default,) {final _that = this;
switch (_that) {
case _ChatRoomMemberState() when $default != null:
return $default(_that.members,_that.isLoading,_that.total,_that.error);case _:
return null;
}
}
}
/// @nodoc