Skip to content

Commit

Permalink
add albumThumbnailAssetId
Browse files Browse the repository at this point in the history
  • Loading branch information
rikifrank committed Oct 31, 2023
1 parent 8044d9a commit 102982d
Show file tree
Hide file tree
Showing 11 changed files with 50 additions and 9 deletions.
6 changes: 6 additions & 0 deletions cli/src/api/open-api/api.ts

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

1 change: 1 addition & 0 deletions mobile/openapi/doc/AlbumsForPersonResponseDto.md

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

10 changes: 9 additions & 1 deletion mobile/openapi/lib/model/albums_for_person_response_dto.dart

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

5 changes: 5 additions & 0 deletions mobile/openapi/test/albums_for_person_response_dto_test.dart

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

5 changes: 5 additions & 0 deletions server/immich-openapi-specs.json
Original file line number Diff line number Diff line change
Expand Up @@ -5750,13 +5750,18 @@
"albumName": {
"type": "string"
},
"albumThumbnailAssetId": {
"format": "uuid",
"type": "string"
},
"assetCount": {
"type": "integer"
}
},
"required": [
"albumId",
"albumName",
"albumThumbnailAssetId",
"assetCount"
],
"type": "object"
Expand Down
7 changes: 5 additions & 2 deletions server/src/domain/album/album-response.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { ApiProperty } from '@nestjs/swagger';
import { AssetResponseDto, mapAsset } from '../asset';
import { UserResponseDto, mapUser } from '../user';
import { ValidateUUID } from '../domain.util';
import { AlbumAssetCount } from '../repositories/album.repository';
import { AlbumInfoAssetCount } from '../repositories/album.repository';


export class AlbumResponseDto {
Expand Down Expand Up @@ -31,14 +31,17 @@ export class AlbumsForPersonResponseDto {
albumId!: string;
@ApiProperty({ type: 'string' })
albumName!: string;
@ValidateUUID()
albumThumbnailAssetId!: string;
@ApiProperty({ type: 'integer' })
assetCount!: number;
}

export function mapAlbumCount(entity: AlbumAssetCount): AlbumsForPersonResponseDto {
export function mapAlbumCount(entity: AlbumInfoAssetCount): AlbumsForPersonResponseDto {
return {
albumId: entity.albumId,
albumName: entity.albumName,
albumThumbnailAssetId: entity.albumThumbnailAssetId,
assetCount: entity.assetCount,
};
}
Expand Down
6 changes: 6 additions & 0 deletions server/src/domain/repositories/album.repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,14 @@ import { AlbumEntity } from '@app/infra/entities';
export const IAlbumRepository = 'IAlbumRepository';

export interface AlbumAssetCount {
albumId: string;
assetCount: number;
}

export interface AlbumInfoAssetCount {
albumId: string;
albumName: string;
albumThumbnailAssetId: string;
assetCount: number;
}

Expand Down
4 changes: 2 additions & 2 deletions server/src/domain/repositories/person.repository.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { AssetEntity, AssetFaceEntity, PersonEntity } from '@app/infra/entities';
import { AlbumAssetCount } from './album.repository';
import { AlbumInfoAssetCount } from './album.repository';

export const IPersonRepository = 'IPersonRepository';

Expand Down Expand Up @@ -37,7 +37,7 @@ export interface IPersonRepository {
getAssets(personId: string): Promise<AssetEntity[]>;
prepareReassignFaces(data: UpdateFacesData): Promise<string[]>;
reassignFaces(data: UpdateFacesData): Promise<number>;
getAlbums(personId: string): Promise<AlbumAssetCount[]>;
getAlbums(personId: string): Promise<AlbumInfoAssetCount[]>;

create(entity: Partial<PersonEntity>): Promise<PersonEntity>;
update(entity: Partial<PersonEntity>): Promise<PersonEntity>;
Expand Down
1 change: 0 additions & 1 deletion server/src/infra/repositories/album.repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,6 @@ export class AlbumRepository implements IAlbumRepository {

return countByAlbums.map<AlbumAssetCount>((albumCount) => ({
albumId: albumCount['album_id'],
albumName: '',
assetCount: Number(albumCount['asset_count']),
}));
}
Expand Down
8 changes: 5 additions & 3 deletions server/src/infra/repositories/person.repository.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {
AlbumAssetCount,
AlbumInfoAssetCount,
AssetFaceId,
IPersonRepository,
PersonNameSearchOptions,
Expand Down Expand Up @@ -161,11 +161,12 @@ export class PersonRepository implements IPersonRepository {
});
}

async getAlbums(personId: string): Promise<AlbumAssetCount[]> {
async getAlbums(personId: string): Promise<AlbumInfoAssetCount[]> {
const countByAlbums = await this.albumRepository
.createQueryBuilder('album')
.select('album.id')
.addSelect('album.albumName')
.addSelect('album.albumThumbnailAssetId')
.addSelect('COUNT(asset.id)', 'asset_count')
.innerJoin('album.assets', 'asset')
.innerJoin('asset.faces', 'face')
Expand All @@ -174,9 +175,10 @@ export class PersonRepository implements IPersonRepository {
.orderBy('face.personId, album.id')
.getRawMany();

return countByAlbums.map<AlbumAssetCount>((albumCount) => ({
return countByAlbums.map<AlbumInfoAssetCount>((albumCount) => ({
albumId: albumCount['album_id'],
albumName: albumCount['album_albumName'],
albumThumbnailAssetId: albumCount['album_albumThumbnailAssetId'],
assetCount: Number(albumCount['asset_count']),
}));
}
Expand Down
6 changes: 6 additions & 0 deletions web/src/api/open-api/api.ts

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

0 comments on commit 102982d

Please sign in to comment.