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

fix(web): No EXIF info on stack navigation #15533

Merged
merged 5 commits into from
Jan 23, 2025
Merged
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
27 changes: 27 additions & 0 deletions e2e/src/api/specs/stack.e2e-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -172,4 +172,31 @@ describe('/stacks', () => {
);
});
});

describe('GET /stacks/:id', () => {
it('should include exifInfo in stack assets', async () => {
const [asset1, asset2] = await Promise.all([
utils.createAsset(user1.accessToken),
utils.createAsset(user1.accessToken),
]);

const stack = await utils.createStack(user1.accessToken, [asset1.id, asset2.id]);

const { status, body } = await request(app)
.get(`/stacks/${stack.id}`)
.set('Authorization', `Bearer ${user1.accessToken}`);

expect(status).toBe(200);
expect(body).toEqual(
expect.objectContaining({
id: stack.id,
primaryAssetId: asset1.id,
assets: expect.arrayContaining([
expect.objectContaining({ id: asset1.id, exifInfo: expect.any(Object) }),
expect.objectContaining({ id: asset2.id, exifInfo: expect.any(Object) }),
]),
}),
);
});
});
});
37 changes: 32 additions & 5 deletions server/src/queries/stack.repository.sql
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,18 @@ select
from
(
select
*
"assets".*,
to_json("exifInfo") as "exifInfo"
from
"assets"
inner join lateral (
select
"exif".*
from
"exif"
where
"exif"."assetId" = "assets"."id"
) as "exifInfo" on true
where
"assets"."deletedAt" is null
and "assets"."stackId" = "asset_stack"."id"
Expand All @@ -31,7 +40,7 @@ select
from
(
select
*,
"assets".*,
(
select
coalesce(json_agg(agg), '[]')
Expand All @@ -45,9 +54,18 @@ select
where
"tag_asset"."assetsId" = "assets"."id"
) as agg
) as "tags"
) as "tags",
to_json("exifInfo") as "exifInfo"
from
"assets"
inner join lateral (
select
"exif".*
from
"exif"
where
"exif"."assetId" = "assets"."id"
) as "exifInfo" on true
where
"assets"."deletedAt" is null
and "assets"."stackId" = "asset_stack"."id"
Expand All @@ -67,7 +85,7 @@ select
from
(
select
*,
"assets".*,
(
select
coalesce(json_agg(agg), '[]')
Expand All @@ -81,9 +99,18 @@ select
where
"tag_asset"."assetsId" = "assets"."id"
) as agg
) as "tags"
) as "tags",
to_json("exifInfo") as "exifInfo"
from
"assets"
inner join lateral (
select
"exif".*
from
"exif"
where
"exif"."assetId" = "assets"."id"
) as "exifInfo" on true
where
"assets"."deletedAt" is null
and "assets"."stackId" = "asset_stack"."id"
Expand Down
7 changes: 6 additions & 1 deletion server/src/repositories/stack.repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,11 @@ const withAssets = (eb: ExpressionBuilder<DB, 'asset_stack'>, withTags = false)
return jsonArrayFrom(
eb
.selectFrom('assets')
.selectAll()
.selectAll('assets')
.innerJoinLateral(
(eb) => eb.selectFrom('exif').selectAll('exif').whereRef('exif.assetId', '=', 'assets.id').as('exifInfo'),
(join) => join.onTrue(),
)
.$if(withTags, (eb) =>
eb.select((eb) =>
jsonArrayFrom(
Expand All @@ -24,6 +28,7 @@ const withAssets = (eb: ExpressionBuilder<DB, 'asset_stack'>, withTags = false)
).as('tags'),
),
)
.select((eb) => eb.fn.toJson('exifInfo').as('exifInfo'))
.where('assets.deletedAt', 'is', null)
.whereRef('assets.stackId', '=', 'asset_stack.id'),
).as('assets');
Expand Down
Loading