Skip to content

Commit

Permalink
fix getPersonAlbums
Browse files Browse the repository at this point in the history
  • Loading branch information
rikifrank committed Oct 30, 2023
1 parent 4582231 commit c69fb58
Show file tree
Hide file tree
Showing 10 changed files with 44 additions and 8 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.

4 changes: 4 additions & 0 deletions server/immich-openapi-specs.json
Original file line number Diff line number Diff line change
Expand Up @@ -5747,12 +5747,16 @@
"format": "uuid",
"type": "string"
},
"albumName": {
"type": "string"
},
"assetCount": {
"type": "integer"
}
},
"required": [
"albumId",
"albumName",
"assetCount"
],
"type": "object"
Expand Down
3 changes: 3 additions & 0 deletions server/src/domain/album/album-response.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,16 @@ export class AlbumResponseDto {
export class AlbumsForPersonResponseDto {
@ValidateUUID()
albumId!: string;
@ApiProperty({ type: 'string' })
albumName!: string;
@ApiProperty({ type: 'integer' })
assetCount!: number;
}

export function mapAlbumCount(entity: AlbumAssetCount): AlbumsForPersonResponseDto {
return {
albumId: entity.albumId,
albumName: entity.albumName,
assetCount: entity.assetCount,
};
}
Expand Down
1 change: 1 addition & 0 deletions server/src/domain/repositories/album.repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ export const IAlbumRepository = 'IAlbumRepository';

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

Expand Down
1 change: 1 addition & 0 deletions server/src/infra/repositories/album.repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ export class AlbumRepository implements IAlbumRepository {

return countByAlbums.map<AlbumAssetCount>((albumCount) => ({
albumId: albumCount['album_id'],
albumName: '',
assetCount: Number(albumCount['asset_count']),
}));
}
Expand Down
15 changes: 8 additions & 7 deletions server/src/infra/repositories/person.repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -165,17 +165,18 @@ export class PersonRepository implements IPersonRepository {
const countByAlbums = await this.albumRepository
.createQueryBuilder('album')
.select('album.id')
.addSelect('COUNT(albums_assets.assetsId)', 'asset_count')
.innerJoin('albums_assets_assets', 'albums_assets', 'albums_assets.albumsId = album.id')
.innerJoin('asset_faces', 'asset_faces', 'asset_faces.assetId = albums_assets.assetId')
.innerJoin('person', 'person', 'asset_faces.personId = person.id')
.where('person.id = :personId', { personId })
.groupBy('person.id, album.name')
.orderBy('person.id, album.name')
.addSelect('album.albumName')
.addSelect('COUNT(asset.id)', 'asset_count')
.innerJoin('album.assets', 'asset')
.innerJoin('asset.faces', 'face')
.where('face.personId = :personId', { personId })
.groupBy('face.personId, album.id')
.orderBy('face.personId, album.id')
.getRawMany();

return countByAlbums.map<AlbumAssetCount>((albumCount) => ({
albumId: albumCount['album_id'],
albumName: albumCount['album_name'],
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 c69fb58

Please sign in to comment.