From 43fd7737f16b26a4b32d43a8b2bb4e69f8656ddb Mon Sep 17 00:00:00 2001 From: Alex Date: Tue, 7 Feb 2023 15:11:14 -0600 Subject: [PATCH] chore(server): make owner as required response for AlbumResponseDto (#1579) --- mobile/openapi/doc/AlbumResponseDto.md | Bin 896 -> 885 bytes .../openapi/lib/model/album_response_dto.dart | Bin 6572 -> 6143 bytes .../src/api-v1/album/album-repository.ts | 1 + .../src/api-v1/album/album.service.spec.ts | 36 +++++++++++++----- server/immich-openapi-specs.json | 3 +- .../album/response-dto/album-response.dto.ts | 6 +-- web/src/api/open-api/api.ts | 2 +- .../shared-components/immich-thumbnail.svelte | 3 +- 8 files changed, 35 insertions(+), 16 deletions(-) diff --git a/mobile/openapi/doc/AlbumResponseDto.md b/mobile/openapi/doc/AlbumResponseDto.md index 33ab5943b6c1f46160cf5c75820a59f1f92bd1c0..3b65af27603d4145152e3c0f83c7fd903f0eaddd 100644 GIT binary patch delta 11 ScmZo*|H`)EJk#V`Ov?Zr)&&^= delta 22 dcmey$*1*2uJQG)RenClQeqLfu?BsJy%K>Mn2{r%# diff --git a/mobile/openapi/lib/model/album_response_dto.dart b/mobile/openapi/lib/model/album_response_dto.dart index 3616c754902fd8adcea8dcc5d5386124e1a4308c..615206a3c42be2b0b026a0f5f23cdfa7e15d2f5b 100644 GIT binary patch delta 91 zcmV-h0Hpt{GygBJssaddWpQCA$3={?dA+yvH(gqVCASZ8kZe?;OED9hXeLD($3JTkf9f<${ delta 500 zcmZ{gy-ve06oo}A6)8*%9m;gt0a~dvNNlaDBEi6j_!$}8_@=Qib`;yKDpc_h-FO7V zfXJI5R-Of%q%gta<(&KZyZ0-6IevYv<$0~P^%#a>0QeUdl9(YVZE1+>L>Q!*PARiX zm_$3tk+3;oN~C;A9V#a!n@VcqN~nln6M{)860wMw6c77FleI$B8bISTAMB1b8ow10Sl$f&U z4ptZ91)Jf=8Frb{z|R)@<5VjnIAvg*SG_+By!k&XmOuD;AN!*f_bbTNVQ&m&mt<1^ z1D#ntfnIp=QQ!+F+HaG8)NQ?q@wimO1V7~O(9C { email: 'auth@test.com', isAdmin: false, }); + + const albumOwner: UserEntity = Object.freeze({ + ...authUser, + firstName: 'auth', + lastName: 'user', + createdAt: 'date', + updatedAt: 'date', + profileImagePath: '', + shouldChangePassword: false, + oauthId: '', + tags: [], + }); const albumId = 'f19ab956-4761-41ea-a5d6-bae948308d58'; const sharedAlbumOwnerId = '2222'; const sharedAlbumSharedAlsoWithId = '3333'; @@ -28,7 +40,8 @@ describe('Album service', () => { const _getOwnedAlbum = () => { const albumEntity = new AlbumEntity(); - albumEntity.ownerId = authUser.id; + albumEntity.ownerId = albumOwner.id; + albumEntity.owner = albumOwner; albumEntity.id = albumId; albumEntity.albumName = 'name'; albumEntity.createdAt = 'date'; @@ -42,7 +55,8 @@ describe('Album service', () => { const _getOwnedSharedAlbum = () => { const albumEntity = new AlbumEntity(); - albumEntity.ownerId = authUser.id; + albumEntity.ownerId = albumOwner.id; + albumEntity.owner = albumOwner; albumEntity.id = albumId; albumEntity.albumName = 'name'; albumEntity.createdAt = 'date'; @@ -68,6 +82,7 @@ describe('Album service', () => { const _getSharedWithAuthUserAlbum = () => { const albumEntity = new AlbumEntity(); albumEntity.ownerId = sharedAlbumOwnerId; + albumEntity.owner = albumOwner; albumEntity.id = albumId; albumEntity.albumName = 'name'; albumEntity.createdAt = 'date'; @@ -174,22 +189,22 @@ describe('Album service', () => { }); it('gets an owned album', async () => { - const ownerId = authUser.id; const albumId = 'f19ab956-4761-41ea-a5d6-bae948308d58'; const albumEntity = _getOwnedAlbum(); albumRepositoryMock.get.mockImplementation(() => Promise.resolve(albumEntity)); const expectedResult: AlbumResponseDto = { + ownerId: albumOwner.id, + owner: mapUser(albumOwner), + id: albumId, albumName: 'name', - albumThumbnailAssetId: null, createdAt: 'date', updatedAt: 'date', - id: 'f19ab956-4761-41ea-a5d6-bae948308d58', - ownerId, - shared: false, - assets: [], sharedUsers: [], + assets: [], + albumThumbnailAssetId: null, + shared: false, assetCount: 0, }; await expect(sut.getAlbumInfo(authUser, albumId)).resolves.toEqual(expectedResult); @@ -473,6 +488,7 @@ describe('Album service', () => { const albumEntity = new AlbumEntity(); albumEntity.ownerId = authUser.id; + albumEntity.owner = albumOwner; albumEntity.id = albumId; albumEntity.albumName = 'name'; albumEntity.createdAt = 'date'; diff --git a/server/immich-openapi-specs.json b/server/immich-openapi-specs.json index 64484ee9f..bd7442c78 100644 --- a/server/immich-openapi-specs.json +++ b/server/immich-openapi-specs.json @@ -3400,7 +3400,8 @@ "albumThumbnailAssetId", "shared", "sharedUsers", - "assets" + "assets", + "owner" ] }, "SharedLinkResponseDto": { diff --git a/server/libs/domain/src/album/response-dto/album-response.dto.ts b/server/libs/domain/src/album/response-dto/album-response.dto.ts index 7e7458727..b7a52af8c 100644 --- a/server/libs/domain/src/album/response-dto/album-response.dto.ts +++ b/server/libs/domain/src/album/response-dto/album-response.dto.ts @@ -13,7 +13,7 @@ export class AlbumResponseDto { shared!: boolean; sharedUsers!: UserResponseDto[]; assets!: AssetResponseDto[]; - owner?: UserResponseDto; + owner!: UserResponseDto; @ApiProperty({ type: 'integer' }) assetCount!: number; } @@ -35,7 +35,7 @@ export function mapAlbum(entity: AlbumEntity): AlbumResponseDto { updatedAt: entity.updatedAt, id: entity.id, ownerId: entity.ownerId, - owner: entity.owner ? mapUser(entity.owner) : undefined, + owner: mapUser(entity.owner), sharedUsers, shared: sharedUsers.length > 0 || entity.sharedLinks?.length > 0, assets: entity.assets?.map((assetAlbum) => mapAsset(assetAlbum.assetInfo)) || [], @@ -60,7 +60,7 @@ export function mapAlbumExcludeAssetInfo(entity: AlbumEntity): AlbumResponseDto updatedAt: entity.updatedAt, id: entity.id, ownerId: entity.ownerId, - owner: entity.owner ? mapUser(entity.owner) : undefined, + owner: mapUser(entity.owner), sharedUsers, shared: sharedUsers.length > 0 || entity.sharedLinks?.length > 0, assets: [], diff --git a/web/src/api/open-api/api.ts b/web/src/api/open-api/api.ts index 078877269..4789ee960 100644 --- a/web/src/api/open-api/api.ts +++ b/web/src/api/open-api/api.ts @@ -281,7 +281,7 @@ export interface AlbumResponseDto { * @type {UserResponseDto} * @memberof AlbumResponseDto */ - 'owner'?: UserResponseDto; + 'owner': UserResponseDto; } /** * diff --git a/web/src/lib/components/shared-components/immich-thumbnail.svelte b/web/src/lib/components/shared-components/immich-thumbnail.svelte index 0f9390cf4..b4b10e9f3 100644 --- a/web/src/lib/components/shared-components/immich-thumbnail.svelte +++ b/web/src/lib/components/shared-components/immich-thumbnail.svelte @@ -34,6 +34,7 @@ let calculateVideoDurationIntervalHandler: NodeJS.Timer; let videoProgress = '00:00'; let videoUrl: string; + $: isPublicShared = publicSharedKey !== ''; const loadVideoData = async (isLivePhoto: boolean) => { isThumbnailVideoPlaying = false; @@ -183,7 +184,7 @@ {/if} - {#if asset.isFavorite} + {#if asset.isFavorite && !isPublicShared}