mirror of
https://github.com/immich-app/immich.git
synced 2025-07-31 15:08:44 -04:00
fix(server): use UserMetadataKey enum instead of string (#20209)
* fix(server): use UserMetadataKey enum instead of string * fix: mobile
This commit is contained in:
parent
ed5759fe07
commit
25e2d37490
@ -20,8 +20,8 @@ import 'package:immich_mobile/infrastructure/entities/user.entity.drift.dart';
|
|||||||
import 'package:immich_mobile/infrastructure/entities/user_metadata.entity.drift.dart';
|
import 'package:immich_mobile/infrastructure/entities/user_metadata.entity.drift.dart';
|
||||||
import 'package:immich_mobile/infrastructure/repositories/db.repository.dart';
|
import 'package:immich_mobile/infrastructure/repositories/db.repository.dart';
|
||||||
import 'package:logging/logging.dart';
|
import 'package:logging/logging.dart';
|
||||||
import 'package:openapi/api.dart' as api show AssetVisibility, AlbumUserRole;
|
import 'package:openapi/api.dart' as api show AssetVisibility, AlbumUserRole, UserMetadataKey;
|
||||||
import 'package:openapi/api.dart' hide AssetVisibility, AlbumUserRole;
|
import 'package:openapi/api.dart' hide AssetVisibility, AlbumUserRole, UserMetadataKey;
|
||||||
|
|
||||||
class SyncStreamRepository extends DriftDatabaseRepository {
|
class SyncStreamRepository extends DriftDatabaseRepository {
|
||||||
final Logger _logger = Logger('DriftSyncStreamRepository');
|
final Logger _logger = Logger('DriftSyncStreamRepository');
|
||||||
@ -647,11 +647,11 @@ extension on api.AssetVisibility {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
extension on String {
|
extension on api.UserMetadataKey {
|
||||||
UserMetadataKey toUserMetadataKey() => switch (this) {
|
UserMetadataKey toUserMetadataKey() => switch (this) {
|
||||||
"onboarding" => UserMetadataKey.onboarding,
|
api.UserMetadataKey.onboarding => UserMetadataKey.onboarding,
|
||||||
"preferences" => UserMetadataKey.preferences,
|
api.UserMetadataKey.preferences => UserMetadataKey.preferences,
|
||||||
"license" => UserMetadataKey.license,
|
api.UserMetadataKey.license => UserMetadataKey.license,
|
||||||
_ => throw Exception('Unknown UserMetadataKey value: $this'),
|
_ => throw Exception('Unknown UserMetadataKey value: $this'),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
1
mobile/openapi/README.md
generated
1
mobile/openapi/README.md
generated
@ -557,6 +557,7 @@ Class | Method | HTTP request | Description
|
|||||||
- [UserAdminUpdateDto](doc//UserAdminUpdateDto.md)
|
- [UserAdminUpdateDto](doc//UserAdminUpdateDto.md)
|
||||||
- [UserAvatarColor](doc//UserAvatarColor.md)
|
- [UserAvatarColor](doc//UserAvatarColor.md)
|
||||||
- [UserLicense](doc//UserLicense.md)
|
- [UserLicense](doc//UserLicense.md)
|
||||||
|
- [UserMetadataKey](doc//UserMetadataKey.md)
|
||||||
- [UserPreferencesResponseDto](doc//UserPreferencesResponseDto.md)
|
- [UserPreferencesResponseDto](doc//UserPreferencesResponseDto.md)
|
||||||
- [UserPreferencesUpdateDto](doc//UserPreferencesUpdateDto.md)
|
- [UserPreferencesUpdateDto](doc//UserPreferencesUpdateDto.md)
|
||||||
- [UserResponseDto](doc//UserResponseDto.md)
|
- [UserResponseDto](doc//UserResponseDto.md)
|
||||||
|
1
mobile/openapi/lib/api.dart
generated
1
mobile/openapi/lib/api.dart
generated
@ -338,6 +338,7 @@ part 'model/user_admin_response_dto.dart';
|
|||||||
part 'model/user_admin_update_dto.dart';
|
part 'model/user_admin_update_dto.dart';
|
||||||
part 'model/user_avatar_color.dart';
|
part 'model/user_avatar_color.dart';
|
||||||
part 'model/user_license.dart';
|
part 'model/user_license.dart';
|
||||||
|
part 'model/user_metadata_key.dart';
|
||||||
part 'model/user_preferences_response_dto.dart';
|
part 'model/user_preferences_response_dto.dart';
|
||||||
part 'model/user_preferences_update_dto.dart';
|
part 'model/user_preferences_update_dto.dart';
|
||||||
part 'model/user_response_dto.dart';
|
part 'model/user_response_dto.dart';
|
||||||
|
2
mobile/openapi/lib/api_client.dart
generated
2
mobile/openapi/lib/api_client.dart
generated
@ -732,6 +732,8 @@ class ApiClient {
|
|||||||
return UserAvatarColorTypeTransformer().decode(value);
|
return UserAvatarColorTypeTransformer().decode(value);
|
||||||
case 'UserLicense':
|
case 'UserLicense':
|
||||||
return UserLicense.fromJson(value);
|
return UserLicense.fromJson(value);
|
||||||
|
case 'UserMetadataKey':
|
||||||
|
return UserMetadataKeyTypeTransformer().decode(value);
|
||||||
case 'UserPreferencesResponseDto':
|
case 'UserPreferencesResponseDto':
|
||||||
return UserPreferencesResponseDto.fromJson(value);
|
return UserPreferencesResponseDto.fromJson(value);
|
||||||
case 'UserPreferencesUpdateDto':
|
case 'UserPreferencesUpdateDto':
|
||||||
|
3
mobile/openapi/lib/api_helper.dart
generated
3
mobile/openapi/lib/api_helper.dart
generated
@ -151,6 +151,9 @@ String parameterToString(dynamic value) {
|
|||||||
if (value is UserAvatarColor) {
|
if (value is UserAvatarColor) {
|
||||||
return UserAvatarColorTypeTransformer().encode(value).toString();
|
return UserAvatarColorTypeTransformer().encode(value).toString();
|
||||||
}
|
}
|
||||||
|
if (value is UserMetadataKey) {
|
||||||
|
return UserMetadataKeyTypeTransformer().encode(value).toString();
|
||||||
|
}
|
||||||
if (value is UserStatus) {
|
if (value is UserStatus) {
|
||||||
return UserStatusTypeTransformer().encode(value).toString();
|
return UserStatusTypeTransformer().encode(value).toString();
|
||||||
}
|
}
|
||||||
|
@ -17,7 +17,7 @@ class SyncUserMetadataDeleteV1 {
|
|||||||
required this.userId,
|
required this.userId,
|
||||||
});
|
});
|
||||||
|
|
||||||
String key;
|
UserMetadataKey key;
|
||||||
|
|
||||||
String userId;
|
String userId;
|
||||||
|
|
||||||
@ -51,7 +51,7 @@ class SyncUserMetadataDeleteV1 {
|
|||||||
final json = value.cast<String, dynamic>();
|
final json = value.cast<String, dynamic>();
|
||||||
|
|
||||||
return SyncUserMetadataDeleteV1(
|
return SyncUserMetadataDeleteV1(
|
||||||
key: mapValueOfType<String>(json, r'key')!,
|
key: UserMetadataKey.fromJson(json[r'key'])!,
|
||||||
userId: mapValueOfType<String>(json, r'userId')!,
|
userId: mapValueOfType<String>(json, r'userId')!,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -18,7 +18,7 @@ class SyncUserMetadataV1 {
|
|||||||
required this.value,
|
required this.value,
|
||||||
});
|
});
|
||||||
|
|
||||||
String key;
|
UserMetadataKey key;
|
||||||
|
|
||||||
String userId;
|
String userId;
|
||||||
|
|
||||||
@ -57,7 +57,7 @@ class SyncUserMetadataV1 {
|
|||||||
final json = value.cast<String, dynamic>();
|
final json = value.cast<String, dynamic>();
|
||||||
|
|
||||||
return SyncUserMetadataV1(
|
return SyncUserMetadataV1(
|
||||||
key: mapValueOfType<String>(json, r'key')!,
|
key: UserMetadataKey.fromJson(json[r'key'])!,
|
||||||
userId: mapValueOfType<String>(json, r'userId')!,
|
userId: mapValueOfType<String>(json, r'userId')!,
|
||||||
value: mapValueOfType<Object>(json, r'value')!,
|
value: mapValueOfType<Object>(json, r'value')!,
|
||||||
);
|
);
|
||||||
|
88
mobile/openapi/lib/model/user_metadata_key.dart
generated
Normal file
88
mobile/openapi/lib/model/user_metadata_key.dart
generated
Normal file
@ -0,0 +1,88 @@
|
|||||||
|
//
|
||||||
|
// AUTO-GENERATED FILE, DO NOT MODIFY!
|
||||||
|
//
|
||||||
|
// @dart=2.18
|
||||||
|
|
||||||
|
// ignore_for_file: unused_element, unused_import
|
||||||
|
// ignore_for_file: always_put_required_named_parameters_first
|
||||||
|
// ignore_for_file: constant_identifier_names
|
||||||
|
// ignore_for_file: lines_longer_than_80_chars
|
||||||
|
|
||||||
|
part of openapi.api;
|
||||||
|
|
||||||
|
|
||||||
|
class UserMetadataKey {
|
||||||
|
/// Instantiate a new enum with the provided [value].
|
||||||
|
const UserMetadataKey._(this.value);
|
||||||
|
|
||||||
|
/// The underlying value of this enum member.
|
||||||
|
final String value;
|
||||||
|
|
||||||
|
@override
|
||||||
|
String toString() => value;
|
||||||
|
|
||||||
|
String toJson() => value;
|
||||||
|
|
||||||
|
static const preferences = UserMetadataKey._(r'preferences');
|
||||||
|
static const license = UserMetadataKey._(r'license');
|
||||||
|
static const onboarding = UserMetadataKey._(r'onboarding');
|
||||||
|
|
||||||
|
/// List of all possible values in this [enum][UserMetadataKey].
|
||||||
|
static const values = <UserMetadataKey>[
|
||||||
|
preferences,
|
||||||
|
license,
|
||||||
|
onboarding,
|
||||||
|
];
|
||||||
|
|
||||||
|
static UserMetadataKey? fromJson(dynamic value) => UserMetadataKeyTypeTransformer().decode(value);
|
||||||
|
|
||||||
|
static List<UserMetadataKey> listFromJson(dynamic json, {bool growable = false,}) {
|
||||||
|
final result = <UserMetadataKey>[];
|
||||||
|
if (json is List && json.isNotEmpty) {
|
||||||
|
for (final row in json) {
|
||||||
|
final value = UserMetadataKey.fromJson(row);
|
||||||
|
if (value != null) {
|
||||||
|
result.add(value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return result.toList(growable: growable);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Transformation class that can [encode] an instance of [UserMetadataKey] to String,
|
||||||
|
/// and [decode] dynamic data back to [UserMetadataKey].
|
||||||
|
class UserMetadataKeyTypeTransformer {
|
||||||
|
factory UserMetadataKeyTypeTransformer() => _instance ??= const UserMetadataKeyTypeTransformer._();
|
||||||
|
|
||||||
|
const UserMetadataKeyTypeTransformer._();
|
||||||
|
|
||||||
|
String encode(UserMetadataKey data) => data.value;
|
||||||
|
|
||||||
|
/// Decodes a [dynamic value][data] to a UserMetadataKey.
|
||||||
|
///
|
||||||
|
/// If [allowNull] is true and the [dynamic value][data] cannot be decoded successfully,
|
||||||
|
/// then null is returned. However, if [allowNull] is false and the [dynamic value][data]
|
||||||
|
/// cannot be decoded successfully, then an [UnimplementedError] is thrown.
|
||||||
|
///
|
||||||
|
/// The [allowNull] is very handy when an API changes and a new enum value is added or removed,
|
||||||
|
/// and users are still using an old app with the old code.
|
||||||
|
UserMetadataKey? decode(dynamic data, {bool allowNull = true}) {
|
||||||
|
if (data != null) {
|
||||||
|
switch (data) {
|
||||||
|
case r'preferences': return UserMetadataKey.preferences;
|
||||||
|
case r'license': return UserMetadataKey.license;
|
||||||
|
case r'onboarding': return UserMetadataKey.onboarding;
|
||||||
|
default:
|
||||||
|
if (!allowNull) {
|
||||||
|
throw ArgumentError('Unknown enum value to decode: $data');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Singleton [UserMetadataKeyTypeTransformer] instance.
|
||||||
|
static UserMetadataKeyTypeTransformer? _instance;
|
||||||
|
}
|
||||||
|
|
@ -14403,7 +14403,11 @@
|
|||||||
"SyncUserMetadataDeleteV1": {
|
"SyncUserMetadataDeleteV1": {
|
||||||
"properties": {
|
"properties": {
|
||||||
"key": {
|
"key": {
|
||||||
"type": "string"
|
"allOf": [
|
||||||
|
{
|
||||||
|
"$ref": "#/components/schemas/UserMetadataKey"
|
||||||
|
}
|
||||||
|
]
|
||||||
},
|
},
|
||||||
"userId": {
|
"userId": {
|
||||||
"type": "string"
|
"type": "string"
|
||||||
@ -14418,7 +14422,11 @@
|
|||||||
"SyncUserMetadataV1": {
|
"SyncUserMetadataV1": {
|
||||||
"properties": {
|
"properties": {
|
||||||
"key": {
|
"key": {
|
||||||
"type": "string"
|
"allOf": [
|
||||||
|
{
|
||||||
|
"$ref": "#/components/schemas/UserMetadataKey"
|
||||||
|
}
|
||||||
|
]
|
||||||
},
|
},
|
||||||
"userId": {
|
"userId": {
|
||||||
"type": "string"
|
"type": "string"
|
||||||
@ -16132,6 +16140,14 @@
|
|||||||
],
|
],
|
||||||
"type": "object"
|
"type": "object"
|
||||||
},
|
},
|
||||||
|
"UserMetadataKey": {
|
||||||
|
"enum": [
|
||||||
|
"preferences",
|
||||||
|
"license",
|
||||||
|
"onboarding"
|
||||||
|
],
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
"UserPreferencesResponseDto": {
|
"UserPreferencesResponseDto": {
|
||||||
"properties": {
|
"properties": {
|
||||||
"albums": {
|
"albums": {
|
||||||
|
@ -301,14 +301,16 @@ export class SyncAssetFaceDeleteV1 {
|
|||||||
@ExtraModel()
|
@ExtraModel()
|
||||||
export class SyncUserMetadataV1 {
|
export class SyncUserMetadataV1 {
|
||||||
userId!: string;
|
userId!: string;
|
||||||
key!: string;
|
@ValidateEnum({ enum: UserMetadataKey, name: 'UserMetadataKey' })
|
||||||
|
key!: UserMetadataKey;
|
||||||
value!: UserMetadata[UserMetadataKey];
|
value!: UserMetadata[UserMetadataKey];
|
||||||
}
|
}
|
||||||
|
|
||||||
@ExtraModel()
|
@ExtraModel()
|
||||||
export class SyncUserMetadataDeleteV1 {
|
export class SyncUserMetadataDeleteV1 {
|
||||||
userId!: string;
|
userId!: string;
|
||||||
key!: string;
|
@ValidateEnum({ enum: UserMetadataKey, name: 'UserMetadataKey' })
|
||||||
|
key!: UserMetadataKey;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ExtraModel()
|
@ExtraModel()
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
import { PrimaryGeneratedUuidV7Column } from 'src/decorators';
|
import { PrimaryGeneratedUuidV7Column } from 'src/decorators';
|
||||||
|
import { UserMetadataKey } from 'src/enum';
|
||||||
import { Column, CreateDateColumn, Generated, Table, Timestamp } from 'src/sql-tools';
|
import { Column, CreateDateColumn, Generated, Table, Timestamp } from 'src/sql-tools';
|
||||||
|
|
||||||
@Table('user_metadata_audit')
|
@Table('user_metadata_audit')
|
||||||
@ -10,7 +11,7 @@ export class UserMetadataAuditTable {
|
|||||||
userId!: string;
|
userId!: string;
|
||||||
|
|
||||||
@Column({ indexName: 'IDX_user_metadata_audit_key' })
|
@Column({ indexName: 'IDX_user_metadata_audit_key' })
|
||||||
key!: string;
|
key!: UserMetadataKey;
|
||||||
|
|
||||||
@CreateDateColumn({ default: () => 'clock_timestamp()', indexName: 'IDX_user_metadata_audit_deleted_at' })
|
@CreateDateColumn({ default: () => 'clock_timestamp()', indexName: 'IDX_user_metadata_audit_deleted_at' })
|
||||||
deletedAt!: Generated<Timestamp>;
|
deletedAt!: Generated<Timestamp>;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user