Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(server): add album filter to search tab #16979

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions e2e/src/api/specs/search.e2e-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,21 @@ describe('/search', () => {
dto: { [value]: 'immich' },
expected: [`${value} must be a boolean value`],
})),
{
should: 'should reject albumIds null',
dto: { size: 1, albumIds: null },
expected: [
"each value in albumIds must be a UUID",
"albumIds must be an array"
],
},
{
should: 'should reject albumIds invalid format',
dto: { size: 1, albumIds: ['invalid_uuid'] },
expected: [
"each value in albumIds must be a UUID"
],
},
];

for (const { should, dto, expected } of badTests) {
Expand Down Expand Up @@ -434,6 +449,14 @@ describe('/search', () => {
assets: [assetLast],
}),
},
{
should: 'should get my assets with empty albumIds',
deferred: () => ({ dto: { size: 1 }, assets: [assetLast], albumIds: [] }),
},
{
should: 'should get my assets with a valued albumIds',
deferred: () => ({ dto: { size: 1 }, assets: [assetLast], albumIds: ['84010428-5106-42e1-be4d-e66d88fb59c2'] }),
},
];

for (const { should, deferred } of searchTests) {
Expand Down
11 changes: 10 additions & 1 deletion mobile/openapi/lib/model/metadata_search_dto.dart

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

11 changes: 10 additions & 1 deletion mobile/openapi/lib/model/random_search_dto.dart

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

11 changes: 10 additions & 1 deletion mobile/openapi/lib/model/smart_search_dto.dart

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

21 changes: 21 additions & 0 deletions open-api/immich-openapi-specs.json
Original file line number Diff line number Diff line change
Expand Up @@ -10166,6 +10166,13 @@
},
"MetadataSearchDto": {
"properties": {
"albumIds": {
"items": {
"format": "uuid",
"type": "string"
},
"type": "array"
},
"checksum": {
"type": "string"
},
Expand Down Expand Up @@ -10865,6 +10872,13 @@
},
"RandomSearchDto": {
"properties": {
"albumIds": {
"items": {
"format": "uuid",
"type": "string"
},
"type": "array"
},
"city": {
"nullable": true,
"type": "string"
Expand Down Expand Up @@ -11813,6 +11827,13 @@
},
"SmartSearchDto": {
"properties": {
"albumIds": {
"items": {
"format": "uuid",
"type": "string"
},
"type": "array"
},
"city": {
"nullable": true,
"type": "string"
Expand Down
3 changes: 3 additions & 0 deletions open-api/typescript-sdk/src/fetch-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -799,6 +799,7 @@ export type SearchExploreResponseDto = {
items: SearchExploreItem[];
};
export type MetadataSearchDto = {
albumIds?: string[];
checksum?: string;
city?: string | null;
country?: string | null;
Expand Down Expand Up @@ -877,6 +878,7 @@ export type PlacesResponseDto = {
name: string;
};
export type RandomSearchDto = {
albumIds?: string[];
city?: string | null;
country?: string | null;
createdAfter?: string;
Expand Down Expand Up @@ -912,6 +914,7 @@ export type RandomSearchDto = {
withStacked?: boolean;
};
export type SmartSearchDto = {
albumIds?: string[];
city?: string | null;
country?: string | null;
createdAfter?: string;
Expand Down
3 changes: 3 additions & 0 deletions server/src/dtos/search.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,9 @@ class BaseSearchDto {
@ValidateBoolean({ optional: true })
isNotInAlbum?: boolean;

@ValidateUUID({ each: true, optional: true })
albumIds?: string[];

@ValidateUUID({ each: true, optional: true })
personIds?: string[];

Expand Down
10 changes: 10 additions & 0 deletions server/src/entities/asset.entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -440,6 +440,16 @@ export function searchAssetBuilder(kysely: Kysely<DB>, options: AssetSearchBuild
eb.not(eb.exists((eb) => eb.selectFrom('albums_assets_assets').whereRef('assetsId', '=', 'assets.id'))),
),
)
.$if(!!options.albumIds && options.albumIds.length > 0, (qb) =>
qb.where((eb) =>
eb.exists((eb) =>
eb
.selectFrom('albums_assets_assets')
.whereRef('albums_assets_assets.assetsId', '=', 'assets.id')
.where('albums_assets_assets.albumsId', 'in', options.albumIds!),
),
),
)
.$if(!!options.withExif, withExifInner)
.$if(!!(options.withFaces || options.withPeople || options.personIds), (qb) => qb.select(withFacesAndPeople))
.$if(!options.withDeleted, (qb) => qb.where('assets.deletedAt', 'is', null))
Expand Down
1 change: 1 addition & 0 deletions server/src/repositories/search.repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ export interface SearchStatusOptions {
isOffline?: boolean;
isVisible?: boolean;
isNotInAlbum?: boolean;
albumIds?: string[];
type?: AssetType;
status?: AssetStatus;
withArchived?: boolean;
Expand Down