Skip to content

Commit

Permalink
chore(server): make owner as required response for AlbumResponseDto (i…
Browse files Browse the repository at this point in the history
  • Loading branch information
alextran1502 authored Feb 7, 2023
1 parent fb4969d commit 43fd773
Show file tree
Hide file tree
Showing 8 changed files with 41 additions and 31 deletions.
2 changes: 1 addition & 1 deletion mobile/openapi/doc/AlbumResponseDto.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 5 additions & 14 deletions mobile/openapi/lib/model/album_response_dto.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions server/apps/immich/src/api-v1/album/album-repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ export class AlbumRepository implements IAlbumRepository {
relations: {
sharedLinks: true,
assets: true,
owner: true,
},
where: {
ownerId,
Expand Down
36 changes: 26 additions & 10 deletions server/apps/immich/src/api-v1/album/album.service.spec.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { AlbumService } from './album.service';
import { AuthUserDto } from '../../decorators/auth-user.decorator';
import { BadRequestException, NotFoundException, ForbiddenException } from '@nestjs/common';
import { AlbumEntity } from '@app/infra';
import { AlbumResponseDto, ICryptoRepository } from '@app/domain';
import { AlbumEntity, UserEntity } from '@app/infra';
import { AlbumResponseDto, ICryptoRepository, mapUser } from '@app/domain';
import { AddAssetsResponseDto } from './response-dto/add-assets-response.dto';
import { IAlbumRepository } from './album-repository';
import { DownloadService } from '../../modules/download/download.service';
Expand All @@ -21,14 +21,27 @@ describe('Album service', () => {
email: '[email protected]',
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';
const ownedAlbumSharedWithId = '4444';

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';
Expand All @@ -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';
Expand All @@ -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';
Expand Down Expand Up @@ -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>(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);
Expand Down Expand Up @@ -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';
Expand Down
3 changes: 2 additions & 1 deletion server/immich-openapi-specs.json
Original file line number Diff line number Diff line change
Expand Up @@ -3400,7 +3400,8 @@
"albumThumbnailAssetId",
"shared",
"sharedUsers",
"assets"
"assets",
"owner"
]
},
"SharedLinkResponseDto": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export class AlbumResponseDto {
shared!: boolean;
sharedUsers!: UserResponseDto[];
assets!: AssetResponseDto[];
owner?: UserResponseDto;
owner!: UserResponseDto;
@ApiProperty({ type: 'integer' })
assetCount!: number;
}
Expand All @@ -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)) || [],
Expand All @@ -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: [],
Expand Down
2 changes: 1 addition & 1 deletion web/src/api/open-api/api.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
let calculateVideoDurationIntervalHandler: NodeJS.Timer;
let videoProgress = '00:00';
let videoUrl: string;
$: isPublicShared = publicSharedKey !== '';
const loadVideoData = async (isLivePhoto: boolean) => {
isThumbnailVideoPlaying = false;
Expand Down Expand Up @@ -183,7 +184,7 @@
</div>
{/if}

{#if asset.isFavorite}
{#if asset.isFavorite && !isPublicShared}
<div class="w-full absolute bottom-2 left-2 z-10">
<Star size="24" color={'white'} />
</div>
Expand Down

0 comments on commit 43fd773

Please sign in to comment.