1
0
forked from Cutlery/immich

Compare commits

...

13 Commits

Author SHA1 Message Date
Alex Tran
2076e8f595 closure table 2024-04-03 23:08:01 -05:00
Alex Tran
683a56fc07 crud implementation 2024-04-03 11:57:04 -05:00
Alex Tran
ca06105d00 better relationship 2024-04-03 09:51:03 -05:00
Alex Tran
0d1c45316c sql 2024-04-03 00:12:37 -05:00
Alex Tran
ac2a2e408f actually simplify migration 2024-04-02 23:44:02 -05:00
Alex Tran
27421c908b simplify migration 2024-04-02 23:40:23 -05:00
Alex Tran
6e868184aa migration fix 2024-04-02 22:48:58 -05:00
Alex Tran
81f80a87f7 clean up migration 2024-04-02 22:44:06 -05:00
Alex Tran
569d579743 album tree 2024-04-02 22:41:02 -05:00
Alex Tran
7aa98162af response dto 2024-04-02 21:57:21 -05:00
Alex Tran
a28330adf6 migration 2024-04-02 18:32:24 -05:00
Alex Tran
09dce3815b remove previous relationship 2024-04-02 18:15:09 -05:00
Alex Tran
f70386ddfe create migration 2024-04-02 17:46:02 -05:00
28 changed files with 1100 additions and 8 deletions

View File

@ -54,6 +54,7 @@ doc/Colorspace.md
doc/CreateAlbumDto.md
doc/CreateLibraryDto.md
doc/CreateProfileImageResponseDto.md
doc/CreateSubAlbumDto.md
doc/CreateTagDto.md
doc/CreateUserDto.md
doc/CuratedLocationsResponseDto.md
@ -149,6 +150,7 @@ doc/SharedLinkType.md
doc/SignUpDto.md
doc/SmartInfoResponseDto.md
doc/SmartSearchDto.md
doc/SubAlbumResponseDto.md
doc/SystemConfigApi.md
doc/SystemConfigDto.md
doc/SystemConfigFFmpegDto.md
@ -276,6 +278,7 @@ lib/model/cq_mode.dart
lib/model/create_album_dto.dart
lib/model/create_library_dto.dart
lib/model/create_profile_image_response_dto.dart
lib/model/create_sub_album_dto.dart
lib/model/create_tag_dto.dart
lib/model/create_user_dto.dart
lib/model/curated_locations_response_dto.dart
@ -360,6 +363,7 @@ lib/model/shared_link_type.dart
lib/model/sign_up_dto.dart
lib/model/smart_info_response_dto.dart
lib/model/smart_search_dto.dart
lib/model/sub_album_response_dto.dart
lib/model/system_config_dto.dart
lib/model/system_config_f_fmpeg_dto.dart
lib/model/system_config_image_dto.dart
@ -457,6 +461,7 @@ test/cq_mode_test.dart
test/create_album_dto_test.dart
test/create_library_dto_test.dart
test/create_profile_image_response_dto_test.dart
test/create_sub_album_dto_test.dart
test/create_tag_dto_test.dart
test/create_user_dto_test.dart
test/curated_locations_response_dto_test.dart
@ -552,6 +557,7 @@ test/shared_link_type_test.dart
test/sign_up_dto_test.dart
test/smart_info_response_dto_test.dart
test/smart_search_dto_test.dart
test/sub_album_response_dto_test.dart
test/system_config_api_test.dart
test/system_config_dto_test.dart
test/system_config_f_fmpeg_dto_test.dart

View File

@ -84,11 +84,14 @@ Class | Method | HTTP request | Description
*AlbumApi* | [**addAssetsToAlbum**](doc//AlbumApi.md#addassetstoalbum) | **PUT** /album/{id}/assets |
*AlbumApi* | [**addUsersToAlbum**](doc//AlbumApi.md#adduserstoalbum) | **PUT** /album/{id}/users |
*AlbumApi* | [**createAlbum**](doc//AlbumApi.md#createalbum) | **POST** /album |
*AlbumApi* | [**createSubAlbum**](doc//AlbumApi.md#createsubalbum) | **POST** /album/sub-album |
*AlbumApi* | [**deleteAlbum**](doc//AlbumApi.md#deletealbum) | **DELETE** /album/{id} |
*AlbumApi* | [**getAlbumCount**](doc//AlbumApi.md#getalbumcount) | **GET** /album/count |
*AlbumApi* | [**getAlbumInfo**](doc//AlbumApi.md#getalbuminfo) | **GET** /album/{id} |
*AlbumApi* | [**getAlbumTree**](doc//AlbumApi.md#getalbumtree) | **GET** /album/{id}/sub-album |
*AlbumApi* | [**getAllAlbums**](doc//AlbumApi.md#getallalbums) | **GET** /album |
*AlbumApi* | [**removeAssetFromAlbum**](doc//AlbumApi.md#removeassetfromalbum) | **DELETE** /album/{id}/assets |
*AlbumApi* | [**removeSubAlbum**](doc//AlbumApi.md#removesubalbum) | **DELETE** /album/{id}/sub-album/{childAlbumId} |
*AlbumApi* | [**removeUserFromAlbum**](doc//AlbumApi.md#removeuserfromalbum) | **DELETE** /album/{id}/user/{userId} |
*AlbumApi* | [**updateAlbumInfo**](doc//AlbumApi.md#updatealbuminfo) | **PATCH** /album/{id} |
*AssetApi* | [**checkBulkUpload**](doc//AssetApi.md#checkbulkupload) | **POST** /asset/bulk-upload-check |
@ -268,6 +271,7 @@ Class | Method | HTTP request | Description
- [CreateAlbumDto](doc//CreateAlbumDto.md)
- [CreateLibraryDto](doc//CreateLibraryDto.md)
- [CreateProfileImageResponseDto](doc//CreateProfileImageResponseDto.md)
- [CreateSubAlbumDto](doc//CreateSubAlbumDto.md)
- [CreateTagDto](doc//CreateTagDto.md)
- [CreateUserDto](doc//CreateUserDto.md)
- [CuratedLocationsResponseDto](doc//CuratedLocationsResponseDto.md)
@ -352,6 +356,7 @@ Class | Method | HTTP request | Description
- [SignUpDto](doc//SignUpDto.md)
- [SmartInfoResponseDto](doc//SmartInfoResponseDto.md)
- [SmartSearchDto](doc//SmartSearchDto.md)
- [SubAlbumResponseDto](doc//SubAlbumResponseDto.md)
- [SystemConfigDto](doc//SystemConfigDto.md)
- [SystemConfigFFmpegDto](doc//SystemConfigFFmpegDto.md)
- [SystemConfigImageDto](doc//SystemConfigImageDto.md)

View File

@ -12,11 +12,14 @@ Method | HTTP request | Description
[**addAssetsToAlbum**](AlbumApi.md#addassetstoalbum) | **PUT** /album/{id}/assets |
[**addUsersToAlbum**](AlbumApi.md#adduserstoalbum) | **PUT** /album/{id}/users |
[**createAlbum**](AlbumApi.md#createalbum) | **POST** /album |
[**createSubAlbum**](AlbumApi.md#createsubalbum) | **POST** /album/sub-album |
[**deleteAlbum**](AlbumApi.md#deletealbum) | **DELETE** /album/{id} |
[**getAlbumCount**](AlbumApi.md#getalbumcount) | **GET** /album/count |
[**getAlbumInfo**](AlbumApi.md#getalbuminfo) | **GET** /album/{id} |
[**getAlbumTree**](AlbumApi.md#getalbumtree) | **GET** /album/{id}/sub-album |
[**getAllAlbums**](AlbumApi.md#getallalbums) | **GET** /album |
[**removeAssetFromAlbum**](AlbumApi.md#removeassetfromalbum) | **DELETE** /album/{id}/assets |
[**removeSubAlbum**](AlbumApi.md#removesubalbum) | **DELETE** /album/{id}/sub-album/{childAlbumId} |
[**removeUserFromAlbum**](AlbumApi.md#removeuserfromalbum) | **DELETE** /album/{id}/user/{userId} |
[**updateAlbumInfo**](AlbumApi.md#updatealbuminfo) | **PATCH** /album/{id} |
@ -192,6 +195,60 @@ Name | Type | Description | Notes
[[Back to top]](#) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to Model list]](../README.md#documentation-for-models) [[Back to README]](../README.md)
# **createSubAlbum**
> createSubAlbum(createSubAlbumDto)
### Example
```dart
import 'package:openapi/api.dart';
// TODO Configure API key authorization: cookie
//defaultApiClient.getAuthentication<ApiKeyAuth>('cookie').apiKey = 'YOUR_API_KEY';
// uncomment below to setup prefix (e.g. Bearer) for API key, if needed
//defaultApiClient.getAuthentication<ApiKeyAuth>('cookie').apiKeyPrefix = 'Bearer';
// TODO Configure API key authorization: api_key
//defaultApiClient.getAuthentication<ApiKeyAuth>('api_key').apiKey = 'YOUR_API_KEY';
// uncomment below to setup prefix (e.g. Bearer) for API key, if needed
//defaultApiClient.getAuthentication<ApiKeyAuth>('api_key').apiKeyPrefix = 'Bearer';
// TODO Configure HTTP Bearer authorization: bearer
// Case 1. Use String Token
//defaultApiClient.getAuthentication<HttpBearerAuth>('bearer').setAccessToken('YOUR_ACCESS_TOKEN');
// Case 2. Use Function which generate token.
// String yourTokenGeneratorFunction() { ... }
//defaultApiClient.getAuthentication<HttpBearerAuth>('bearer').setAccessToken(yourTokenGeneratorFunction);
final api_instance = AlbumApi();
final createSubAlbumDto = CreateSubAlbumDto(); // CreateSubAlbumDto |
try {
api_instance.createSubAlbum(createSubAlbumDto);
} catch (e) {
print('Exception when calling AlbumApi->createSubAlbum: $e\n');
}
```
### Parameters
Name | Type | Description | Notes
------------- | ------------- | ------------- | -------------
**createSubAlbumDto** | [**CreateSubAlbumDto**](CreateSubAlbumDto.md)| |
### Return type
void (empty response body)
### Authorization
[cookie](../README.md#cookie), [api_key](../README.md#api_key), [bearer](../README.md#bearer)
### HTTP request headers
- **Content-Type**: application/json
- **Accept**: Not defined
[[Back to top]](#) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to Model list]](../README.md#documentation-for-models) [[Back to README]](../README.md)
# **deleteAlbum**
> deleteAlbum(id)
@ -356,6 +413,60 @@ Name | Type | Description | Notes
[[Back to top]](#) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to Model list]](../README.md#documentation-for-models) [[Back to README]](../README.md)
# **getAlbumTree**
> getAlbumTree(id)
### Example
```dart
import 'package:openapi/api.dart';
// TODO Configure API key authorization: cookie
//defaultApiClient.getAuthentication<ApiKeyAuth>('cookie').apiKey = 'YOUR_API_KEY';
// uncomment below to setup prefix (e.g. Bearer) for API key, if needed
//defaultApiClient.getAuthentication<ApiKeyAuth>('cookie').apiKeyPrefix = 'Bearer';
// TODO Configure API key authorization: api_key
//defaultApiClient.getAuthentication<ApiKeyAuth>('api_key').apiKey = 'YOUR_API_KEY';
// uncomment below to setup prefix (e.g. Bearer) for API key, if needed
//defaultApiClient.getAuthentication<ApiKeyAuth>('api_key').apiKeyPrefix = 'Bearer';
// TODO Configure HTTP Bearer authorization: bearer
// Case 1. Use String Token
//defaultApiClient.getAuthentication<HttpBearerAuth>('bearer').setAccessToken('YOUR_ACCESS_TOKEN');
// Case 2. Use Function which generate token.
// String yourTokenGeneratorFunction() { ... }
//defaultApiClient.getAuthentication<HttpBearerAuth>('bearer').setAccessToken(yourTokenGeneratorFunction);
final api_instance = AlbumApi();
final id = 38400000-8cf0-11bd-b23e-10b96e4ef00d; // String |
try {
api_instance.getAlbumTree(id);
} catch (e) {
print('Exception when calling AlbumApi->getAlbumTree: $e\n');
}
```
### Parameters
Name | Type | Description | Notes
------------- | ------------- | ------------- | -------------
**id** | **String**| |
### Return type
void (empty response body)
### Authorization
[cookie](../README.md#cookie), [api_key](../README.md#api_key), [bearer](../README.md#bearer)
### HTTP request headers
- **Content-Type**: Not defined
- **Accept**: Not defined
[[Back to top]](#) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to Model list]](../README.md#documentation-for-models) [[Back to README]](../README.md)
# **getAllAlbums**
> List<AlbumResponseDto> getAllAlbums(assetId, shared)
@ -470,6 +581,62 @@ Name | Type | Description | Notes
[[Back to top]](#) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to Model list]](../README.md#documentation-for-models) [[Back to README]](../README.md)
# **removeSubAlbum**
> removeSubAlbum(childAlbumId, id)
### Example
```dart
import 'package:openapi/api.dart';
// TODO Configure API key authorization: cookie
//defaultApiClient.getAuthentication<ApiKeyAuth>('cookie').apiKey = 'YOUR_API_KEY';
// uncomment below to setup prefix (e.g. Bearer) for API key, if needed
//defaultApiClient.getAuthentication<ApiKeyAuth>('cookie').apiKeyPrefix = 'Bearer';
// TODO Configure API key authorization: api_key
//defaultApiClient.getAuthentication<ApiKeyAuth>('api_key').apiKey = 'YOUR_API_KEY';
// uncomment below to setup prefix (e.g. Bearer) for API key, if needed
//defaultApiClient.getAuthentication<ApiKeyAuth>('api_key').apiKeyPrefix = 'Bearer';
// TODO Configure HTTP Bearer authorization: bearer
// Case 1. Use String Token
//defaultApiClient.getAuthentication<HttpBearerAuth>('bearer').setAccessToken('YOUR_ACCESS_TOKEN');
// Case 2. Use Function which generate token.
// String yourTokenGeneratorFunction() { ... }
//defaultApiClient.getAuthentication<HttpBearerAuth>('bearer').setAccessToken(yourTokenGeneratorFunction);
final api_instance = AlbumApi();
final childAlbumId = childAlbumId_example; // String |
final id = 38400000-8cf0-11bd-b23e-10b96e4ef00d; // String |
try {
api_instance.removeSubAlbum(childAlbumId, id);
} catch (e) {
print('Exception when calling AlbumApi->removeSubAlbum: $e\n');
}
```
### Parameters
Name | Type | Description | Notes
------------- | ------------- | ------------- | -------------
**childAlbumId** | **String**| |
**id** | **String**| |
### Return type
void (empty response body)
### Authorization
[cookie](../README.md#cookie), [api_key](../README.md#api_key), [bearer](../README.md#bearer)
### HTTP request headers
- **Content-Type**: Not defined
- **Accept**: Not defined
[[Back to top]](#) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to Model list]](../README.md#documentation-for-models) [[Back to README]](../README.md)
# **removeUserFromAlbum**
> removeUserFromAlbum(id, userId)

View File

@ -12,6 +12,7 @@ Name | Type | Description | Notes
**albumThumbnailAssetId** | **String** | |
**assetCount** | **int** | |
**assets** | [**List<AssetResponseDto>**](AssetResponseDto.md) | | [default to const []]
**childAlbums** | [**List<SubAlbumResponseDto>**](SubAlbumResponseDto.md) | | [optional] [default to const []]
**createdAt** | [**DateTime**](DateTime.md) | |
**description** | **String** | |
**endDate** | [**DateTime**](DateTime.md) | | [optional]
@ -22,6 +23,7 @@ Name | Type | Description | Notes
**order** | [**AssetOrder**](AssetOrder.md) | | [optional]
**owner** | [**UserResponseDto**](UserResponseDto.md) | |
**ownerId** | **String** | |
**parentAlbums** | [**List<SubAlbumResponseDto>**](SubAlbumResponseDto.md) | | [optional] [default to const []]
**shared** | **bool** | |
**sharedUsers** | [**List<UserResponseDto>**](UserResponseDto.md) | | [default to const []]
**startDate** | [**DateTime**](DateTime.md) | | [optional]

16
mobile/openapi/doc/CreateSubAlbumDto.md generated Normal file
View File

@ -0,0 +1,16 @@
# openapi.model.CreateSubAlbumDto
## Load the model package
```dart
import 'package:openapi/api.dart';
```
## Properties
Name | Type | Description | Notes
------------ | ------------- | ------------- | -------------
**childrenId** | **String** | |
**parentId** | **String** | |
[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md)

View File

@ -0,0 +1,17 @@
# openapi.model.SubAlbumResponseDto
## Load the model package
```dart
import 'package:openapi/api.dart';
```
## Properties
Name | Type | Description | Notes
------------ | ------------- | ------------- | -------------
**albumName** | **String** | |
**albumThumbnailAssetId** | **String** | |
**id** | **String** | |
[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md)

View File

@ -97,6 +97,7 @@ part 'model/colorspace.dart';
part 'model/create_album_dto.dart';
part 'model/create_library_dto.dart';
part 'model/create_profile_image_response_dto.dart';
part 'model/create_sub_album_dto.dart';
part 'model/create_tag_dto.dart';
part 'model/create_user_dto.dart';
part 'model/curated_locations_response_dto.dart';
@ -181,6 +182,7 @@ part 'model/shared_link_type.dart';
part 'model/sign_up_dto.dart';
part 'model/smart_info_response_dto.dart';
part 'model/smart_search_dto.dart';
part 'model/sub_album_response_dto.dart';
part 'model/system_config_dto.dart';
part 'model/system_config_f_fmpeg_dto.dart';
part 'model/system_config_image_dto.dart';

View File

@ -178,6 +178,45 @@ class AlbumApi {
return null;
}
/// Performs an HTTP 'POST /album/sub-album' operation and returns the [Response].
/// Parameters:
///
/// * [CreateSubAlbumDto] createSubAlbumDto (required):
Future<Response> createSubAlbumWithHttpInfo(CreateSubAlbumDto createSubAlbumDto,) async {
// ignore: prefer_const_declarations
final path = r'/album/sub-album';
// ignore: prefer_final_locals
Object? postBody = createSubAlbumDto;
final queryParams = <QueryParam>[];
final headerParams = <String, String>{};
final formParams = <String, String>{};
const contentTypes = <String>['application/json'];
return apiClient.invokeAPI(
path,
'POST',
queryParams,
postBody,
headerParams,
formParams,
contentTypes.isEmpty ? null : contentTypes.first,
);
}
/// Parameters:
///
/// * [CreateSubAlbumDto] createSubAlbumDto (required):
Future<void> createSubAlbum(CreateSubAlbumDto createSubAlbumDto,) async {
final response = await createSubAlbumWithHttpInfo(createSubAlbumDto,);
if (response.statusCode >= HttpStatus.badRequest) {
throw ApiException(response.statusCode, await _decodeBodyBytes(response));
}
}
/// Performs an HTTP 'DELETE /album/{id}' operation and returns the [Response].
/// Parameters:
///
@ -322,6 +361,46 @@ class AlbumApi {
return null;
}
/// Performs an HTTP 'GET /album/{id}/sub-album' operation and returns the [Response].
/// Parameters:
///
/// * [String] id (required):
Future<Response> getAlbumTreeWithHttpInfo(String id,) async {
// ignore: prefer_const_declarations
final path = r'/album/{id}/sub-album'
.replaceAll('{id}', id);
// ignore: prefer_final_locals
Object? postBody;
final queryParams = <QueryParam>[];
final headerParams = <String, String>{};
final formParams = <String, String>{};
const contentTypes = <String>[];
return apiClient.invokeAPI(
path,
'GET',
queryParams,
postBody,
headerParams,
formParams,
contentTypes.isEmpty ? null : contentTypes.first,
);
}
/// Parameters:
///
/// * [String] id (required):
Future<void> getAlbumTree(String id,) async {
final response = await getAlbumTreeWithHttpInfo(id,);
if (response.statusCode >= HttpStatus.badRequest) {
throw ApiException(response.statusCode, await _decodeBodyBytes(response));
}
}
/// Performs an HTTP 'GET /album' operation and returns the [Response].
/// Parameters:
///
@ -440,6 +519,51 @@ class AlbumApi {
return null;
}
/// Performs an HTTP 'DELETE /album/{id}/sub-album/{childAlbumId}' operation and returns the [Response].
/// Parameters:
///
/// * [String] childAlbumId (required):
///
/// * [String] id (required):
Future<Response> removeSubAlbumWithHttpInfo(String childAlbumId, String id,) async {
// ignore: prefer_const_declarations
final path = r'/album/{id}/sub-album/{childAlbumId}'
.replaceAll('{childAlbumId}', childAlbumId)
.replaceAll('{id}', id);
// ignore: prefer_final_locals
Object? postBody;
final queryParams = <QueryParam>[];
final headerParams = <String, String>{};
final formParams = <String, String>{};
const contentTypes = <String>[];
return apiClient.invokeAPI(
path,
'DELETE',
queryParams,
postBody,
headerParams,
formParams,
contentTypes.isEmpty ? null : contentTypes.first,
);
}
/// Parameters:
///
/// * [String] childAlbumId (required):
///
/// * [String] id (required):
Future<void> removeSubAlbum(String childAlbumId, String id,) async {
final response = await removeSubAlbumWithHttpInfo(childAlbumId, id,);
if (response.statusCode >= HttpStatus.badRequest) {
throw ApiException(response.statusCode, await _decodeBodyBytes(response));
}
}
/// Performs an HTTP 'DELETE /album/{id}/user/{userId}' operation and returns the [Response].
/// Parameters:
///

View File

@ -272,6 +272,8 @@ class ApiClient {
return CreateLibraryDto.fromJson(value);
case 'CreateProfileImageResponseDto':
return CreateProfileImageResponseDto.fromJson(value);
case 'CreateSubAlbumDto':
return CreateSubAlbumDto.fromJson(value);
case 'CreateTagDto':
return CreateTagDto.fromJson(value);
case 'CreateUserDto':
@ -440,6 +442,8 @@ class ApiClient {
return SmartInfoResponseDto.fromJson(value);
case 'SmartSearchDto':
return SmartSearchDto.fromJson(value);
case 'SubAlbumResponseDto':
return SubAlbumResponseDto.fromJson(value);
case 'SystemConfigDto':
return SystemConfigDto.fromJson(value);
case 'SystemConfigFFmpegDto':

View File

@ -17,6 +17,7 @@ class AlbumResponseDto {
required this.albumThumbnailAssetId,
required this.assetCount,
this.assets = const [],
this.childAlbums = const [],
required this.createdAt,
required this.description,
this.endDate,
@ -27,6 +28,7 @@ class AlbumResponseDto {
this.order,
required this.owner,
required this.ownerId,
this.parentAlbums = const [],
required this.shared,
this.sharedUsers = const [],
this.startDate,
@ -41,6 +43,8 @@ class AlbumResponseDto {
List<AssetResponseDto> assets;
List<SubAlbumResponseDto> childAlbums;
DateTime createdAt;
String description;
@ -79,6 +83,8 @@ class AlbumResponseDto {
String ownerId;
List<SubAlbumResponseDto> parentAlbums;
bool shared;
List<UserResponseDto> sharedUsers;
@ -99,6 +105,7 @@ class AlbumResponseDto {
other.albumThumbnailAssetId == albumThumbnailAssetId &&
other.assetCount == assetCount &&
_deepEquality.equals(other.assets, assets) &&
_deepEquality.equals(other.childAlbums, childAlbums) &&
other.createdAt == createdAt &&
other.description == description &&
other.endDate == endDate &&
@ -109,6 +116,7 @@ class AlbumResponseDto {
other.order == order &&
other.owner == owner &&
other.ownerId == ownerId &&
_deepEquality.equals(other.parentAlbums, parentAlbums) &&
other.shared == shared &&
_deepEquality.equals(other.sharedUsers, sharedUsers) &&
other.startDate == startDate &&
@ -121,6 +129,7 @@ class AlbumResponseDto {
(albumThumbnailAssetId == null ? 0 : albumThumbnailAssetId!.hashCode) +
(assetCount.hashCode) +
(assets.hashCode) +
(childAlbums.hashCode) +
(createdAt.hashCode) +
(description.hashCode) +
(endDate == null ? 0 : endDate!.hashCode) +
@ -131,13 +140,14 @@ class AlbumResponseDto {
(order == null ? 0 : order!.hashCode) +
(owner.hashCode) +
(ownerId.hashCode) +
(parentAlbums.hashCode) +
(shared.hashCode) +
(sharedUsers.hashCode) +
(startDate == null ? 0 : startDate!.hashCode) +
(updatedAt.hashCode);
@override
String toString() => 'AlbumResponseDto[albumName=$albumName, albumThumbnailAssetId=$albumThumbnailAssetId, assetCount=$assetCount, assets=$assets, createdAt=$createdAt, description=$description, endDate=$endDate, hasSharedLink=$hasSharedLink, id=$id, isActivityEnabled=$isActivityEnabled, lastModifiedAssetTimestamp=$lastModifiedAssetTimestamp, order=$order, owner=$owner, ownerId=$ownerId, shared=$shared, sharedUsers=$sharedUsers, startDate=$startDate, updatedAt=$updatedAt]';
String toString() => 'AlbumResponseDto[albumName=$albumName, albumThumbnailAssetId=$albumThumbnailAssetId, assetCount=$assetCount, assets=$assets, childAlbums=$childAlbums, createdAt=$createdAt, description=$description, endDate=$endDate, hasSharedLink=$hasSharedLink, id=$id, isActivityEnabled=$isActivityEnabled, lastModifiedAssetTimestamp=$lastModifiedAssetTimestamp, order=$order, owner=$owner, ownerId=$ownerId, parentAlbums=$parentAlbums, shared=$shared, sharedUsers=$sharedUsers, startDate=$startDate, updatedAt=$updatedAt]';
Map<String, dynamic> toJson() {
final json = <String, dynamic>{};
@ -149,6 +159,7 @@ class AlbumResponseDto {
}
json[r'assetCount'] = this.assetCount;
json[r'assets'] = this.assets;
json[r'childAlbums'] = this.childAlbums;
json[r'createdAt'] = this.createdAt.toUtc().toIso8601String();
json[r'description'] = this.description;
if (this.endDate != null) {
@ -171,6 +182,7 @@ class AlbumResponseDto {
}
json[r'owner'] = this.owner;
json[r'ownerId'] = this.ownerId;
json[r'parentAlbums'] = this.parentAlbums;
json[r'shared'] = this.shared;
json[r'sharedUsers'] = this.sharedUsers;
if (this.startDate != null) {
@ -194,6 +206,7 @@ class AlbumResponseDto {
albumThumbnailAssetId: mapValueOfType<String>(json, r'albumThumbnailAssetId'),
assetCount: mapValueOfType<int>(json, r'assetCount')!,
assets: AssetResponseDto.listFromJson(json[r'assets']),
childAlbums: SubAlbumResponseDto.listFromJson(json[r'childAlbums']),
createdAt: mapDateTime(json, r'createdAt', r'')!,
description: mapValueOfType<String>(json, r'description')!,
endDate: mapDateTime(json, r'endDate', r''),
@ -204,6 +217,7 @@ class AlbumResponseDto {
order: AssetOrder.fromJson(json[r'order']),
owner: UserResponseDto.fromJson(json[r'owner'])!,
ownerId: mapValueOfType<String>(json, r'ownerId')!,
parentAlbums: SubAlbumResponseDto.listFromJson(json[r'parentAlbums']),
shared: mapValueOfType<bool>(json, r'shared')!,
sharedUsers: UserResponseDto.listFromJson(json[r'sharedUsers']),
startDate: mapDateTime(json, r'startDate', r''),

View File

@ -0,0 +1,106 @@
//
// AUTO-GENERATED FILE, DO NOT MODIFY!
//
// @dart=2.12
// 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 CreateSubAlbumDto {
/// Returns a new [CreateSubAlbumDto] instance.
CreateSubAlbumDto({
required this.childrenId,
required this.parentId,
});
String childrenId;
String parentId;
@override
bool operator ==(Object other) => identical(this, other) || other is CreateSubAlbumDto &&
other.childrenId == childrenId &&
other.parentId == parentId;
@override
int get hashCode =>
// ignore: unnecessary_parenthesis
(childrenId.hashCode) +
(parentId.hashCode);
@override
String toString() => 'CreateSubAlbumDto[childrenId=$childrenId, parentId=$parentId]';
Map<String, dynamic> toJson() {
final json = <String, dynamic>{};
json[r'childrenId'] = this.childrenId;
json[r'parentId'] = this.parentId;
return json;
}
/// Returns a new [CreateSubAlbumDto] instance and imports its values from
/// [value] if it's a [Map], null otherwise.
// ignore: prefer_constructors_over_static_methods
static CreateSubAlbumDto? fromJson(dynamic value) {
if (value is Map) {
final json = value.cast<String, dynamic>();
return CreateSubAlbumDto(
childrenId: mapValueOfType<String>(json, r'childrenId')!,
parentId: mapValueOfType<String>(json, r'parentId')!,
);
}
return null;
}
static List<CreateSubAlbumDto> listFromJson(dynamic json, {bool growable = false,}) {
final result = <CreateSubAlbumDto>[];
if (json is List && json.isNotEmpty) {
for (final row in json) {
final value = CreateSubAlbumDto.fromJson(row);
if (value != null) {
result.add(value);
}
}
}
return result.toList(growable: growable);
}
static Map<String, CreateSubAlbumDto> mapFromJson(dynamic json) {
final map = <String, CreateSubAlbumDto>{};
if (json is Map && json.isNotEmpty) {
json = json.cast<String, dynamic>(); // ignore: parameter_assignments
for (final entry in json.entries) {
final value = CreateSubAlbumDto.fromJson(entry.value);
if (value != null) {
map[entry.key] = value;
}
}
}
return map;
}
// maps a json object with a list of CreateSubAlbumDto-objects as value to a dart map
static Map<String, List<CreateSubAlbumDto>> mapListFromJson(dynamic json, {bool growable = false,}) {
final map = <String, List<CreateSubAlbumDto>>{};
if (json is Map && json.isNotEmpty) {
// ignore: parameter_assignments
json = json.cast<String, dynamic>();
for (final entry in json.entries) {
map[entry.key] = CreateSubAlbumDto.listFromJson(entry.value, growable: growable,);
}
}
return map;
}
/// The list of required keys that must be present in a JSON.
static const requiredKeys = <String>{
'childrenId',
'parentId',
};
}

View File

@ -0,0 +1,118 @@
//
// AUTO-GENERATED FILE, DO NOT MODIFY!
//
// @dart=2.12
// 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 SubAlbumResponseDto {
/// Returns a new [SubAlbumResponseDto] instance.
SubAlbumResponseDto({
required this.albumName,
required this.albumThumbnailAssetId,
required this.id,
});
String albumName;
String? albumThumbnailAssetId;
String id;
@override
bool operator ==(Object other) => identical(this, other) || other is SubAlbumResponseDto &&
other.albumName == albumName &&
other.albumThumbnailAssetId == albumThumbnailAssetId &&
other.id == id;
@override
int get hashCode =>
// ignore: unnecessary_parenthesis
(albumName.hashCode) +
(albumThumbnailAssetId == null ? 0 : albumThumbnailAssetId!.hashCode) +
(id.hashCode);
@override
String toString() => 'SubAlbumResponseDto[albumName=$albumName, albumThumbnailAssetId=$albumThumbnailAssetId, id=$id]';
Map<String, dynamic> toJson() {
final json = <String, dynamic>{};
json[r'albumName'] = this.albumName;
if (this.albumThumbnailAssetId != null) {
json[r'albumThumbnailAssetId'] = this.albumThumbnailAssetId;
} else {
// json[r'albumThumbnailAssetId'] = null;
}
json[r'id'] = this.id;
return json;
}
/// Returns a new [SubAlbumResponseDto] instance and imports its values from
/// [value] if it's a [Map], null otherwise.
// ignore: prefer_constructors_over_static_methods
static SubAlbumResponseDto? fromJson(dynamic value) {
if (value is Map) {
final json = value.cast<String, dynamic>();
return SubAlbumResponseDto(
albumName: mapValueOfType<String>(json, r'albumName')!,
albumThumbnailAssetId: mapValueOfType<String>(json, r'albumThumbnailAssetId'),
id: mapValueOfType<String>(json, r'id')!,
);
}
return null;
}
static List<SubAlbumResponseDto> listFromJson(dynamic json, {bool growable = false,}) {
final result = <SubAlbumResponseDto>[];
if (json is List && json.isNotEmpty) {
for (final row in json) {
final value = SubAlbumResponseDto.fromJson(row);
if (value != null) {
result.add(value);
}
}
}
return result.toList(growable: growable);
}
static Map<String, SubAlbumResponseDto> mapFromJson(dynamic json) {
final map = <String, SubAlbumResponseDto>{};
if (json is Map && json.isNotEmpty) {
json = json.cast<String, dynamic>(); // ignore: parameter_assignments
for (final entry in json.entries) {
final value = SubAlbumResponseDto.fromJson(entry.value);
if (value != null) {
map[entry.key] = value;
}
}
}
return map;
}
// maps a json object with a list of SubAlbumResponseDto-objects as value to a dart map
static Map<String, List<SubAlbumResponseDto>> mapListFromJson(dynamic json, {bool growable = false,}) {
final map = <String, List<SubAlbumResponseDto>>{};
if (json is Map && json.isNotEmpty) {
// ignore: parameter_assignments
json = json.cast<String, dynamic>();
for (final entry in json.entries) {
map[entry.key] = SubAlbumResponseDto.listFromJson(entry.value, growable: growable,);
}
}
return map;
}
/// The list of required keys that must be present in a JSON.
static const requiredKeys = <String>{
'albumName',
'albumThumbnailAssetId',
'id',
};
}

View File

@ -32,6 +32,11 @@ void main() {
// TODO
});
//Future createSubAlbum(CreateSubAlbumDto createSubAlbumDto) async
test('test createSubAlbum', () async {
// TODO
});
//Future deleteAlbum(String id) async
test('test deleteAlbum', () async {
// TODO
@ -47,6 +52,11 @@ void main() {
// TODO
});
//Future getAlbumTree(String id) async
test('test getAlbumTree', () async {
// TODO
});
//Future<List<AlbumResponseDto>> getAllAlbums({ String assetId, bool shared }) async
test('test getAllAlbums', () async {
// TODO
@ -57,6 +67,11 @@ void main() {
// TODO
});
//Future removeSubAlbum(String childAlbumId, String id) async
test('test removeSubAlbum', () async {
// TODO
});
//Future removeUserFromAlbum(String id, String userId) async
test('test removeUserFromAlbum', () async {
// TODO

View File

@ -36,6 +36,11 @@ void main() {
// TODO
});
// List<SubAlbumResponseDto> childAlbums (default value: const [])
test('to test the property `childAlbums`', () async {
// TODO
});
// DateTime createdAt
test('to test the property `createdAt`', () async {
// TODO
@ -86,6 +91,11 @@ void main() {
// TODO
});
// List<SubAlbumResponseDto> parentAlbums (default value: const [])
test('to test the property `parentAlbums`', () async {
// TODO
});
// bool shared
test('to test the property `shared`', () async {
// TODO

View File

@ -0,0 +1,32 @@
//
// AUTO-GENERATED FILE, DO NOT MODIFY!
//
// @dart=2.12
// 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
import 'package:openapi/api.dart';
import 'package:test/test.dart';
// tests for CreateSubAlbumDto
void main() {
// final instance = CreateSubAlbumDto();
group('test CreateSubAlbumDto', () {
// String childrenId
test('to test the property `childrenId`', () async {
// TODO
});
// String parentId
test('to test the property `parentId`', () async {
// TODO
});
});
}

View File

@ -0,0 +1,37 @@
//
// AUTO-GENERATED FILE, DO NOT MODIFY!
//
// @dart=2.12
// 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
import 'package:openapi/api.dart';
import 'package:test/test.dart';
// tests for SubAlbumResponseDto
void main() {
// final instance = SubAlbumResponseDto();
group('test SubAlbumResponseDto', () {
// String albumName
test('to test the property `albumName`', () async {
// TODO
});
// String albumThumbnailAssetId
test('to test the property `albumThumbnailAssetId`', () async {
// TODO
});
// String id
test('to test the property `id`', () async {
// TODO
});
});
}

View File

@ -332,6 +332,48 @@
]
}
},
"/album/nested-album": {
"post": {
"operationId": "createNestedAlbum",
"parameters": [],
"requestBody": {
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/CreateNestedAlbumDto"
}
}
},
"required": true
},
"responses": {
"201": {
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/AlbumResponseDto"
}
}
},
"description": ""
}
},
"security": [
{
"bearer": []
},
{
"cookie": []
},
{
"api_key": []
}
],
"tags": [
"Album"
]
}
},
"/album/{id}": {
"delete": {
"operationId": "deleteAlbum",
@ -589,6 +631,98 @@
]
}
},
"/album/{id}/nested-album": {
"get": {
"operationId": "getNestedAlbums",
"parameters": [
{
"name": "id",
"required": true,
"in": "path",
"schema": {
"format": "uuid",
"type": "string"
}
}
],
"responses": {
"200": {
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/NestedAlbumResponseDto"
}
}
},
"description": ""
}
},
"security": [
{
"bearer": []
},
{
"cookie": []
},
{
"api_key": []
}
],
"tags": [
"Album"
]
}
},
"/album/{id}/nested-album/{childAlbumId}": {
"delete": {
"operationId": "removeNestedAlbum",
"parameters": [
{
"name": "childAlbumId",
"required": true,
"in": "path",
"schema": {
"type": "string"
}
},
{
"name": "id",
"required": true,
"in": "path",
"schema": {
"format": "uuid",
"type": "string"
}
}
],
"responses": {
"200": {
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/AlbumResponseDto"
}
}
},
"description": ""
}
},
"security": [
{
"bearer": []
},
{
"cookie": []
},
{
"api_key": []
}
],
"tags": [
"Album"
]
}
},
"/album/{id}/user/{userId}": {
"delete": {
"operationId": "removeUserFromAlbum",
@ -8020,6 +8154,22 @@
],
"type": "object"
},
"CreateNestedAlbumDto": {
"properties": {
"childId": {
"format": "uuid",
"type": "string"
},
"parentId": {
"type": "string"
}
},
"required": [
"childId",
"parentId"
],
"type": "object"
},
"CreateProfileImageDto": {
"properties": {
"file": {
@ -9077,6 +9227,27 @@
],
"type": "string"
},
"NestedAlbumResponseDto": {
"properties": {
"children": {
"items": {
"$ref": "#/components/schemas/AlbumResponseDto"
},
"type": "array"
},
"parents": {
"items": {
"$ref": "#/components/schemas/AlbumResponseDto"
},
"type": "array"
}
},
"required": [
"children",
"parents"
],
"type": "object"
},
"OAuthAuthorizeResponseDto": {
"properties": {
"url": {

View File

@ -141,11 +141,17 @@ export type AssetResponseDto = {
"type": AssetTypeEnum;
updatedAt: string;
};
export type SubAlbumResponseDto = {
albumName: string;
albumThumbnailAssetId: string | null;
id: string;
};
export type AlbumResponseDto = {
albumName: string;
albumThumbnailAssetId: string | null;
assetCount: number;
assets: AssetResponseDto[];
childAlbums?: SubAlbumResponseDto[];
createdAt: string;
description: string;
endDate?: string;
@ -156,6 +162,7 @@ export type AlbumResponseDto = {
order?: AssetOrder;
owner: UserResponseDto;
ownerId: string;
parentAlbums?: SubAlbumResponseDto[];
shared: boolean;
sharedUsers: UserResponseDto[];
startDate?: string;
@ -172,6 +179,10 @@ export type AlbumCountResponseDto = {
owned: number;
shared: number;
};
export type CreateSubAlbumDto = {
childrenId: string;
parentId: string;
};
export type UpdateAlbumDto = {
albumName?: string;
albumThumbnailAssetId?: string;
@ -1123,6 +1134,15 @@ export function getAlbumCount(opts?: Oazapfts.RequestOpts) {
...opts
}));
}
export function createSubAlbum({ createSubAlbumDto }: {
createSubAlbumDto: CreateSubAlbumDto;
}, opts?: Oazapfts.RequestOpts) {
return oazapfts.ok(oazapfts.fetchText("/album/sub-album", oazapfts.json({
...opts,
method: "POST",
body: createSubAlbumDto
})));
}
export function deleteAlbum({ id }: {
id: string;
}, opts?: Oazapfts.RequestOpts) {
@ -1188,6 +1208,22 @@ export function addAssetsToAlbum({ id, key, bulkIdsDto }: {
body: bulkIdsDto
})));
}
export function getAlbumTree({ id }: {
id: string;
}, opts?: Oazapfts.RequestOpts) {
return oazapfts.ok(oazapfts.fetchText(`/album/${encodeURIComponent(id)}/sub-album`, {
...opts
}));
}
export function removeSubAlbum({ childAlbumId, id }: {
childAlbumId: string;
id: string;
}, opts?: Oazapfts.RequestOpts) {
return oazapfts.ok(oazapfts.fetchText(`/album/${encodeURIComponent(id)}/sub-album/${encodeURIComponent(childAlbumId)}`, {
...opts,
method: "DELETE"
}));
}
export function removeUserFromAlbum({ id, userId }: {
id: string;
userId: string;

View File

@ -6,7 +6,9 @@ import {
AlbumInfoDto,
AlbumResponseDto,
CreateAlbumDto,
CreateNestedAlbumDto,
GetAlbumsDto,
NestedAlbumResponseDto,
UpdateAlbumDto,
} from 'src/dtos/album.dto';
import { BulkIdResponseDto, BulkIdsDto } from 'src/dtos/asset-ids.response.dto';
@ -96,4 +98,23 @@ export class AlbumController {
) {
return this.service.removeUser(auth, id, userId);
}
@Post('nested-album')
createNestedAlbum(@Auth() auth: AuthDto, @Body() dto: CreateNestedAlbumDto): Promise<AlbumResponseDto> {
return this.service.createNestedAlbum(auth, dto.parentId, dto.childId);
}
@Delete(':id/nested-album/:childAlbumId')
removeNestedAlbum(
@Auth() auth: AuthDto,
@Param() { id }: UUIDParamDto,
@Param('childAlbumId', new ParseMeUUIDPipe({ version: '4' })) childAlbumId: string,
): Promise<AlbumResponseDto> {
return this.service.removeNestedAlbum(auth, id, childAlbumId);
}
@Get(':id/nested-album')
getNestedAlbums(@Auth() auth: AuthDto, @Param() { id }: UUIDParamDto): Promise<NestedAlbumResponseDto> {
return this.service.getNestedAlbums(auth, id);
}
}

View File

@ -107,6 +107,22 @@ export class AlbumResponseDto {
order?: AssetOrder;
}
export class CreateNestedAlbumDto {
@IsString()
parentId!: string;
@ValidateUUID()
childId!: string;
}
export class NestedAlbumResponseDto {
@ApiProperty()
parents!: AlbumResponseDto[];
@ApiProperty()
children!: AlbumResponseDto[];
}
export const mapAlbum = (entity: AlbumEntity, withAssets: boolean, auth?: AuthDto): AlbumResponseDto => {
const sharedUsers: UserResponseDto[] = [];

View File

@ -10,7 +10,11 @@ import {
ManyToMany,
ManyToOne,
OneToMany,
PrimaryColumn,
PrimaryGeneratedColumn,
Tree,
TreeChildren,
TreeParent,
UpdateDateColumn,
} from 'typeorm';
@ -21,6 +25,7 @@ export enum AssetOrder {
}
@Entity('albums')
@Tree('closure-table')
export class AlbumEntity {
@PrimaryGeneratedColumn('uuid')
id!: string;
@ -68,4 +73,19 @@ export class AlbumEntity {
@Column({ type: 'varchar', default: AssetOrder.DESC })
order!: AssetOrder;
@TreeChildren()
children!: AlbumEntity[];
@TreeParent()
parents!: AlbumEntity[];
}
@Entity('nested_albums')
export class NestedAlbumEntity {
@PrimaryColumn('uuid')
parentId!: string;
@PrimaryColumn('uuid')
childId!: string;
}

View File

@ -1,5 +1,5 @@
import { ActivityEntity } from 'src/entities/activity.entity';
import { AlbumEntity } from 'src/entities/album.entity';
import { AlbumEntity, NestedAlbumEntity } from 'src/entities/album.entity';
import { APIKeyEntity } from 'src/entities/api-key.entity';
import { AssetFaceEntity } from 'src/entities/asset-face.entity';
import { AssetJobStatusEntity } from 'src/entities/asset-job-status.entity';
@ -40,6 +40,7 @@ export const entities = [
SharedLinkEntity,
SmartInfoEntity,
SmartSearchEntity,
NestedAlbumEntity,
SystemConfigEntity,
SystemMetadataEntity,
TagEntity,

View File

@ -24,6 +24,11 @@ export interface AlbumAssets {
assetIds: string[];
}
export interface NestedAlbums {
parents: AlbumEntity[];
children: AlbumEntity[];
}
export interface IAlbumRepository extends IBulkAsset {
getById(id: string, options: AlbumInfoOptions): Promise<AlbumEntity | null>;
getByIds(ids: string[]): Promise<AlbumEntity[]>;
@ -45,4 +50,8 @@ export interface IAlbumRepository extends IBulkAsset {
update(album: Partial<AlbumEntity>): Promise<AlbumEntity>;
delete(album: AlbumEntity): Promise<void>;
updateThumbnails(): Promise<number | undefined>;
createNestedAlbum(parentId: string, childId: string): Promise<AlbumEntity>;
removeNestedAlbum(parentId: string, childId: string): Promise<AlbumEntity>;
getNestedAlbums(id: string): Promise<NestedAlbums>;
}

View File

@ -0,0 +1,14 @@
import { MigrationInterface, QueryRunner } from "typeorm";
export class AddNestedAlbumTable1712161154542 implements MigrationInterface {
name = 'AddNestedAlbumTable1712161154542'
public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`CREATE TABLE "nested_albums" ("parentId" uuid NOT NULL, "childId" uuid NOT NULL, CONSTRAINT "PK_702e1e5d9ed4b85d3bdffc934bd" PRIMARY KEY ("parentId", "childId"))`);
}
public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`DROP TABLE "nested_albums"`);
}
}

View File

@ -0,0 +1,33 @@
import { MigrationInterface, QueryRunner } from 'typeorm';
export class AddClosureAlbumTable1712173905900 implements MigrationInterface {
name = 'AddClosureAlbumTable1712173905900';
public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(
`CREATE TABLE "albums_closure" ("id_ancestor" uuid NOT NULL, "id_descendant" uuid NOT NULL, CONSTRAINT "PK_c73b38b33bc7f8a4b2588c573f5" PRIMARY KEY ("id_ancestor", "id_descendant"))`,
);
await queryRunner.query(`CREATE INDEX "IDX_a54149056a7a5da2c44d8a65c2" ON "albums_closure" ("id_ancestor") `);
await queryRunner.query(`CREATE INDEX "IDX_3a2f01ca9d654f90f4a2887a36" ON "albums_closure" ("id_descendant") `);
await queryRunner.query(`ALTER TABLE "albums" ADD "parentsId" uuid`);
await queryRunner.query(
`ALTER TABLE "albums" ADD CONSTRAINT "FK_c619d16fe935e8afd5f9105f31f" FOREIGN KEY ("parentsId") REFERENCES "albums"("id") ON DELETE NO ACTION ON UPDATE NO ACTION`,
);
await queryRunner.query(
`ALTER TABLE "albums_closure" ADD CONSTRAINT "FK_a54149056a7a5da2c44d8a65c22" FOREIGN KEY ("id_ancestor") REFERENCES "albums"("id") ON DELETE CASCADE ON UPDATE NO ACTION`,
);
await queryRunner.query(
`ALTER TABLE "albums_closure" ADD CONSTRAINT "FK_3a2f01ca9d654f90f4a2887a362" FOREIGN KEY ("id_descendant") REFERENCES "albums"("id") ON DELETE CASCADE ON UPDATE NO ACTION`,
);
}
public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`ALTER TABLE "albums_closure" DROP CONSTRAINT "FK_3a2f01ca9d654f90f4a2887a362"`);
await queryRunner.query(`ALTER TABLE "albums_closure" DROP CONSTRAINT "FK_a54149056a7a5da2c44d8a65c22"`);
await queryRunner.query(`ALTER TABLE "albums" DROP CONSTRAINT "FK_c619d16fe935e8afd5f9105f31f"`);
await queryRunner.query(`ALTER TABLE "albums" DROP COLUMN "parentsId"`);
await queryRunner.query(`DROP INDEX "public"."IDX_3a2f01ca9d654f90f4a2887a36"`);
await queryRunner.query(`DROP INDEX "public"."IDX_a54149056a7a5da2c44d8a65c2"`);
await queryRunner.query(`DROP TABLE "albums_closure"`);
}
}

View File

@ -3,12 +3,27 @@ import { InjectDataSource, InjectRepository } from '@nestjs/typeorm';
import _ from 'lodash';
import { dataSource } from 'src/database.config';
import { Chunked, ChunkedArray, DATABASE_PARAMETER_CHUNK_SIZE, DummyValue, GenerateSql } from 'src/decorators';
import { AlbumEntity } from 'src/entities/album.entity';
import { AlbumEntity, NestedAlbumEntity } from 'src/entities/album.entity';
import { AssetEntity } from 'src/entities/asset.entity';
import { AlbumAsset, AlbumAssetCount, AlbumInfoOptions, IAlbumRepository } from 'src/interfaces/album.interface';
import {
AlbumAsset,
AlbumAssetCount,
AlbumInfoOptions,
IAlbumRepository,
NestedAlbums,
} from 'src/interfaces/album.interface';
import { Instrumentation } from 'src/utils/instrumentation';
import { setUnion } from 'src/utils/set';
import { DataSource, FindOptionsOrder, FindOptionsRelations, In, IsNull, Not, Repository } from 'typeorm';
import {
DataSource,
FindOptionsOrder,
FindOptionsRelations,
In,
IsNull,
Not,
Repository,
TreeRepository,
} from 'typeorm';
@Instrumentation()
@Injectable()
@ -16,6 +31,8 @@ export class AlbumRepository implements IAlbumRepository {
constructor(
@InjectRepository(AssetEntity) private assetRepository: Repository<AssetEntity>,
@InjectRepository(AlbumEntity) private repository: Repository<AlbumEntity>,
@InjectRepository(NestedAlbumEntity) private nestedAlbumRepository: Repository<NestedAlbumEntity>,
@InjectRepository(AlbumEntity) private albumTreeRepository: TreeRepository<AlbumEntity>,
@InjectDataSource() private dataSource: DataSource,
) {}
@ -331,4 +348,55 @@ export class AlbumRepository implements IAlbumRepository {
return result.affected;
}
@GenerateSql()
async createNestedAlbum(parentId: string, childId: string): Promise<AlbumEntity> {
const nestedAlbum = new NestedAlbumEntity();
nestedAlbum.parentId = parentId;
nestedAlbum.childId = childId;
await this.nestedAlbumRepository.save(nestedAlbum);
return this.repository.findOneOrFail({
where: { id: childId },
});
}
@GenerateSql()
async removeNestedAlbum(parentId: string, childId: string): Promise<AlbumEntity> {
await this.nestedAlbumRepository.delete({ parentId, childId });
return this.repository.findOneOrFail({
where: { id: childId },
});
}
@GenerateSql()
async getNestedAlbums(id: string): Promise<NestedAlbums> {
const album = await this.repository.findOneOrFail({ where: { id } });
const ancestor = await this.albumTreeRepository.findAncestorsTree(album);
console.log('Parents', ancestor);
console.log('-----------------');
const desc = await this.albumTreeRepository.findDescendantsTree(album);
console.log('Children', desc);
const children = await this.repository
.createQueryBuilder('albums')
.innerJoin('nested_albums', 'nested', 'nested.childId = albums.id')
.leftJoinAndSelect('albums.owner', 'owner')
.where('nested.parentId = :id', { id })
.getMany();
const parents = await this.repository
.createQueryBuilder('albums')
.innerJoin('nested_albums', 'nested', 'nested.parentId = albums.id')
.leftJoinAndSelect('albums.owner', 'owner')
.where('nested.childId = :id', { id })
.getMany();
return {
parents,
children,
};
}
}

View File

@ -7,6 +7,7 @@ import {
AlbumResponseDto,
CreateAlbumDto,
GetAlbumsDto,
NestedAlbumResponseDto as NestedAlbumsResponseDto,
UpdateAlbumDto,
mapAlbum,
mapAlbumWithAssets,
@ -266,6 +267,33 @@ export class AlbumService {
});
}
async createNestedAlbum(auth: AuthDto, parentId: string, childId: string): Promise<AlbumResponseDto> {
await this.access.requirePermission(auth, Permission.ALBUM_UPDATE, parentId);
const nestedAlbum = await this.albumRepository.createNestedAlbum(parentId, childId);
return mapAlbumWithoutAssets(nestedAlbum);
}
async removeNestedAlbum(auth: AuthDto, parentId: string, childId: string): Promise<AlbumResponseDto> {
await this.access.requirePermission(auth, Permission.ALBUM_UPDATE, parentId);
const deletedNestedAlbum = await this.albumRepository.removeNestedAlbum(parentId, childId);
return mapAlbumWithoutAssets(deletedNestedAlbum);
}
async getNestedAlbums(auth: AuthDto, id: string): Promise<NestedAlbumsResponseDto> {
await this.access.requirePermission(auth, Permission.ALBUM_READ, id);
const { parents, children } = await this.albumRepository.getNestedAlbums(id);
return {
parents: parents.length > 0 ? parents.map(mapAlbumWithoutAssets) : [],
children: children.length > 0 ? children.map(mapAlbumWithoutAssets) : [],
};
}
private async findOrFail(id: string, options: AlbumInfoOptions) {
const album = await this.albumRepository.getById(id, options);
if (!album) {