1
0
mirror of https://github.com/immich-app/immich.git synced 2025-08-09 23:17:29 +02:00

[WEB] Select album thumbnail (#383)

* Added context menu for album opionts

* choose asset for album thumbnail

* Refactor UpdateAlbumDto to accept albumThumbnailAssetId

* implemented changing album cover on web

* Fixed api change on mobile app
This commit is contained in:
Alex
2022-07-27 11:16:02 -05:00
committed by GitHub
parent 6dbca8d478
commit ef4136d327
14 changed files with 172 additions and 43 deletions

View File

@@ -237,7 +237,8 @@ export class AlbumRepository implements IAlbumRepository {
}
updateAlbum(album: AlbumEntity, updateAlbumDto: UpdateAlbumDto): Promise<AlbumEntity> {
album.albumName = updateAlbumDto.albumName;
album.albumName = updateAlbumDto.albumName || album.albumName;
album.albumThumbnailAssetId = updateAlbumDto.albumThumbnailAssetId || album.albumThumbnailAssetId;
return this.albumRepository.save(album);
}

View File

@@ -104,6 +104,6 @@ export class AlbumController {
@Body(ValidationPipe) updateAlbumInfoDto: UpdateAlbumDto,
@Param('albumId', new ParseUUIDPipe({ version: '4' })) albumId: string,
) {
return this.albumService.updateAlbumTitle(authUser, updateAlbumInfoDto, albumId);
return this.albumService.updateAlbumInfo(authUser, updateAlbumInfoDto, albumId);
}
}

View File

@@ -260,17 +260,16 @@ describe('Album service', () => {
const albumEntity = _getOwnedAlbum();
const albumId = albumEntity.id;
const updatedAlbumName = 'new album name';
const updatedAlbumThumbnailAssetId = '69d2f917-0b31-48d8-9d7d-673b523f1aac';
albumRepositoryMock.get.mockImplementation(() => Promise.resolve<AlbumEntity>(albumEntity));
albumRepositoryMock.updateAlbum.mockImplementation(() =>
Promise.resolve<AlbumEntity>({ ...albumEntity, albumName: updatedAlbumName }),
);
const result = await sut.updateAlbumTitle(
const result = await sut.updateAlbumInfo(
authUser,
{
albumName: updatedAlbumName,
ownerId: 'this is not used and will be removed',
},
albumId,
);
@@ -280,7 +279,7 @@ describe('Album service', () => {
expect(albumRepositoryMock.updateAlbum).toHaveBeenCalledTimes(1);
expect(albumRepositoryMock.updateAlbum).toHaveBeenCalledWith(albumEntity, {
albumName: updatedAlbumName,
ownerId: 'this is not used and will be removed',
thumbnailAssetId: updatedAlbumThumbnailAssetId,
});
});
@@ -291,11 +290,11 @@ describe('Album service', () => {
albumRepositoryMock.get.mockImplementation(() => Promise.resolve<AlbumEntity>(albumEntity));
await expect(
sut.updateAlbumTitle(
sut.updateAlbumInfo(
authUser,
{
albumName: 'new album name',
ownerId: 'this is not used and will be removed',
albumThumbnailAssetId: '69d2f917-0b31-48d8-9d7d-673b523f1aac',
},
albumId,
),
@@ -361,7 +360,7 @@ describe('Album service', () => {
it('removes assets from owned album', async () => {
const albumEntity = _getOwnedAlbum();
albumRepositoryMock.get.mockImplementation(() => Promise.resolve<AlbumEntity>(albumEntity));
albumRepositoryMock.removeAssets.mockImplementation(() => Promise.resolve(true));
albumRepositoryMock.removeAssets.mockImplementation(() => Promise.resolve<AlbumEntity>(albumEntity));
await expect(
sut.removeAssetsFromAlbum(
@@ -381,7 +380,7 @@ describe('Album service', () => {
it('removes assets from shared album (shared with auth user)', async () => {
const albumEntity = _getOwnedSharedAlbum();
albumRepositoryMock.get.mockImplementation(() => Promise.resolve<AlbumEntity>(albumEntity));
albumRepositoryMock.removeAssets.mockImplementation(() => Promise.resolve(true));
albumRepositoryMock.removeAssets.mockImplementation(() => Promise.resolve<AlbumEntity>(albumEntity));
await expect(
sut.removeAssetsFromAlbum(

View File

@@ -103,16 +103,17 @@ export class AlbumService {
return mapAlbum(updatedAlbum);
}
async updateAlbumTitle(
async updateAlbumInfo(
authUser: AuthUserDto,
updateAlbumDto: UpdateAlbumDto,
albumId: string,
): Promise<AlbumResponseDto> {
// TODO: this should not come from request DTO. To be removed from here and DTO
// if (authUser.id != updateAlbumDto.ownerId) {
// throw new BadRequestException('Unauthorized to change album info');
// }
const album = await this._getAlbum({ authUser, albumId });
if (authUser.id != album.ownerId) {
throw new BadRequestException('Unauthorized to change album info');
}
const updatedAlbum = await this._albumRepository.updateAlbum(album, updateAlbumDto);
return mapAlbum(updatedAlbum);
}

View File

@@ -1,9 +1,9 @@
import { IsNotEmpty } from 'class-validator';
import { IsNotEmpty, IsOptional } from 'class-validator';
export class UpdateAlbumDto {
@IsNotEmpty()
albumName!: string;
@IsOptional()
albumName?: string;
@IsNotEmpty()
ownerId!: string;
@IsOptional()
albumThumbnailAssetId?: string;
}