fix: Update codegen of hive adapters

This commit is contained in:
Anton Stubenbord
2023-10-06 12:09:03 +02:00
parent 0616ca2ffc
commit 29b7c8bdc0
4 changed files with 64 additions and 76 deletions

View File

@@ -192,25 +192,15 @@ class AuthenticationCubit extends Cubit<AuthenticationState> {
final sessionManager = SessionManager([ final sessionManager = SessionManager([
LanguageHeaderInterceptor(locale), LanguageHeaderInterceptor(locale),
]); ]);
try { await _addUser(
await _addUser( localUserId,
localUserId, serverUrl,
serverUrl, credentials,
credentials, clientCertificate,
clientCertificate, sessionManager,
sessionManager, );
// onPerformLogin: () async {
// emit(AuthenticatingState(AuthenticatingStage.authenticating));
// await Future.delayed(const Duration(milliseconds: 500));
// },
);
return localUserId; return localUserId;
} catch (error, stackTrace) {
print(error);
debugPrintStack(stackTrace: stackTrace);
rethrow;
}
} }
Future<void> removeAccount(String userId) async { Future<void> removeAccount(String userId) async {

View File

@@ -232,53 +232,51 @@ class _GoRouterShellState extends State<GoRouterShell> {
initialLocation: "/login", initialLocation: "/login",
routes: [ routes: [
ShellRoute( ShellRoute(
pageBuilder: (context, state, child) { builder: (context, state, child) {
return MaterialPage( return BlocListener<AuthenticationCubit, AuthenticationState>(
child: BlocListener<AuthenticationCubit, AuthenticationState>( listener: (context, state) {
listener: (context, state) { switch (state) {
switch (state) { case UnauthenticatedState(
case UnauthenticatedState( redirectToAccountSelection: var shouldRedirect
redirectToAccountSelection: var shouldRedirect ):
): if (shouldRedirect) {
if (shouldRedirect) { const LoginToExistingAccountRoute().go(context);
const LoginToExistingAccountRoute().go(context); } else {
} else { const LoginRoute().go(context);
const LoginRoute().go(context); }
} break;
break; case RestoringSessionState():
case RestoringSessionState(): const RestoringSessionRoute().go(context);
const RestoringSessionRoute().go(context); break;
break; case VerifyIdentityState(userId: var userId):
case VerifyIdentityState(userId: var userId): VerifyIdentityRoute(userId: userId).go(context);
VerifyIdentityRoute(userId: userId).go(context); break;
break; case SwitchingAccountsState():
case SwitchingAccountsState(): const SwitchingAccountsRoute().push(context);
const SwitchingAccountsRoute().push(context); break;
break; case AuthenticatedState():
case AuthenticatedState(): const LandingRoute().go(context);
const LandingRoute().go(context); break;
break; case AuthenticatingState state:
case AuthenticatingState state: AuthenticatingRoute(state.currentStage.name).push(context);
AuthenticatingRoute(state.currentStage.name).push(context); break;
break; case LoggingOutState():
case LoggingOutState(): const LoggingOutRoute().go(context);
const LoggingOutRoute().go(context); break;
break; case AuthenticationErrorState():
case AuthenticationErrorState(): if (context.canPop()) {
if (context.canPop()) { context.pop();
context.pop(); }
} // LoginRoute(
// LoginRoute( // $extra: errorState.clientCertificate,
// $extra: errorState.clientCertificate, // password: errorState.password,
// password: errorState.password, // serverUrl: errorState.serverUrl,
// serverUrl: errorState.serverUrl, // username: errorState.username,
// username: errorState.username, // ).go(context);
// ).go(context); break;
break; }
} },
}, child: child,
child: child,
),
); );
}, },
navigatorKey: rootNavigatorKey, navigatorKey: rootNavigatorKey,

View File

@@ -1,6 +1,5 @@
import 'package:hive/hive.dart'; import 'package:hive/hive.dart';
import 'package:paperless_api/paperless_api.dart'; import 'package:paperless_api/paperless_api.dart';
import 'package:paperless_api/src/models/query_parameters/date_range_queries/date_range_unit.dart';
class PaperlessApiHiveTypeIds { class PaperlessApiHiveTypeIds {
PaperlessApiHiveTypeIds._(); PaperlessApiHiveTypeIds._();
@@ -37,9 +36,9 @@ class PaperlessApiHiveTypeIds {
void registerPaperlessApiHiveTypeAdapters() { void registerPaperlessApiHiveTypeAdapters() {
Hive.registerAdapter(DocumentFilterAdapter()); Hive.registerAdapter(DocumentFilterAdapter());
// TagsQuery // TagsQuery
Hive.registerAdapter(AnyAssignedTagsQueryAdapter()); Hive.registerAdapter(AnyAssignedTagsQueryImplAdapter());
Hive.registerAdapter(NotAssignedTagsQueryAdapter()); Hive.registerAdapter(NotAssignedTagsQueryImplAdapter());
Hive.registerAdapter(IdsTagsQueryAdapter()); Hive.registerAdapter(IdsTagsQueryImplAdapter());
Hive.registerAdapter(SortFieldAdapter()); Hive.registerAdapter(SortFieldAdapter());
Hive.registerAdapter(SortOrderAdapter()); Hive.registerAdapter(SortOrderAdapter());
@@ -50,13 +49,13 @@ void registerPaperlessApiHiveTypeAdapters() {
Hive.registerAdapter(TextQueryAdapter()); Hive.registerAdapter(TextQueryAdapter());
Hive.registerAdapter(QueryTypeAdapter()); Hive.registerAdapter(QueryTypeAdapter());
// IdQueryParameter // IdQueryParameter
Hive.registerAdapter(SetIdQueryParameterAdapter()); Hive.registerAdapter(SetIdQueryParameterImplAdapter());
Hive.registerAdapter(UnsetIdQueryParameterAdapter()); Hive.registerAdapter(UnsetIdQueryParameterImplAdapter());
Hive.registerAdapter(AnyAssignedIdQueryParameterAdapter()); Hive.registerAdapter(AnyAssignedIdQueryParameterImplAdapter());
Hive.registerAdapter(NotAssignedIdQueryParameterAdapter()); Hive.registerAdapter(NotAssignedIdQueryParameterImplAdapter());
// Users and permissions // Users and permissions
Hive.registerAdapter(UserModelV3Adapter()); Hive.registerAdapter(UserModelV3ImplAdapter());
Hive.registerAdapter(UserModelV2Adapter()); Hive.registerAdapter(UserModelV2ImplAdapter());
Hive.registerAdapter(GroupModelAdapter()); Hive.registerAdapter(GroupModelAdapter());
Hive.registerAdapter(PermissionsAdapter()); Hive.registerAdapter(PermissionsAdapter());
} }

View File

@@ -36,7 +36,8 @@ class UserModel with _$UserModel {
@HiveField(2) String? displayName, @HiveField(2) String? displayName,
}) = UserModelV2; }) = UserModelV2;
factory UserModel.fromJson(Map<String, dynamic> json) => _$UserModelFromJson(json); factory UserModel.fromJson(Map<String, dynamic> json) =>
_$UserModelFromJson(json);
String? get fullName => map( String? get fullName => map(
v2: (value) => value.displayName, v2: (value) => value.displayName,