From ef9a06be5c6a06e5875bed6baed4a10920c2300a Mon Sep 17 00:00:00 2001 From: Jason Rasmussen Date: Tue, 20 Aug 2024 07:50:36 -0400 Subject: [PATCH] fix(server): album statistics endpoint (#11924) --- e2e/src/api/specs/album.e2e-spec.ts | 6 +-- mobile/openapi/README.md | Bin 32028 -> 32053 bytes mobile/openapi/lib/api.dart | Bin 10932 -> 10937 bytes mobile/openapi/lib/api/albums_api.dart | Bin 18754 -> 18794 bytes mobile/openapi/lib/api_client.dart | Bin 28336 -> 28346 bytes ...art => album_statistics_response_dto.dart} | Bin 3331 -> 3421 bytes open-api/immich-openapi-specs.json | 44 +++++++++--------- open-api/typescript-sdk/src/fetch-client.ts | 8 ++-- server/src/controllers/album.controller.ts | 14 +++--- server/src/dtos/album.dto.ts | 2 +- server/src/services/album.service.spec.ts | 4 +- server/src/services/album.service.ts | 4 +- .../side-bar/more-information-albums.svelte | 8 ++-- .../side-bar/side-bar.svelte | 4 +- 14 files changed, 47 insertions(+), 47 deletions(-) rename mobile/openapi/lib/model/{album_count_response_dto.dart => album_statistics_response_dto.dart} (63%) diff --git a/e2e/src/api/specs/album.e2e-spec.ts b/e2e/src/api/specs/album.e2e-spec.ts index 2a35eb3c92..9e925c4021 100644 --- a/e2e/src/api/specs/album.e2e-spec.ts +++ b/e2e/src/api/specs/album.e2e-spec.ts @@ -344,16 +344,16 @@ describe('/albums', () => { }); }); - describe('GET /albums/count', () => { + describe('GET /albums/statistics', () => { it('should require authentication', async () => { - const { status, body } = await request(app).get('/albums/count'); + const { status, body } = await request(app).get('/albums/statistics'); expect(status).toBe(401); expect(body).toEqual(errorDto.unauthorized); }); it('should return total count of albums the user has access to', async () => { const { status, body } = await request(app) - .get('/albums/count') + .get('/albums/statistics') .set('Authorization', `Bearer ${user1.accessToken}`); expect(status).toBe(200); diff --git a/mobile/openapi/README.md b/mobile/openapi/README.md index f2effe1c2060bd4d89a21cefdb5ea6813384b2d3..c49b5052d865b64bf072cde0f23aa84821414ff3 100644 GIT binary patch delta 90 zcmbR9i*f5O#tmP2Cx7FYnk>M_F}ak_j3=oyH@GCRB(u0AGkNkxJ{e}9z~qa1;;e}| rAeI-8;^t+1b}p0Uf(<4&rprt=2xbM+qLT}PxF)X&=GYt*d`c4lISV1$ delta 87 zcmdn`i*e2`#tmP2S)KDs^GYTkaWoZb6tuM5T|>0A6!a5wfWpQ4V2Q~K m_@pL(;*H+Ci_g+!vTU~aWcy&&$@bZjlivlIZcYzArwIVU@F58R diff --git a/mobile/openapi/lib/api.dart b/mobile/openapi/lib/api.dart index 6ee06d53042bb0814bb018dca1a522b97cd1e2a8..a6f860dda27e7417e12216704b39268cc731cf43 100644 GIT binary patch delta 23 fcmdlIx-)dcN{-1_In*Yx delta 24 gcmdlPx+QeON)DFf{L;M1j=ai~mvCrr;@qhS0DVmfH2?qr diff --git a/mobile/openapi/lib/api/albums_api.dart b/mobile/openapi/lib/api/albums_api.dart index fb81c04616742e3cbea232c608ad403680bd0ba2..eb2bb7c0bd9cbe839c2ab56d0b569226144d9db3 100644 GIT binary patch delta 189 zcmX>!iSgAW#tq-4HpeS$XXnx{E=erOEH24Ro?Kv{Jy}g!k}DV{Qass3I+_!qV4~)c z$@7imCRZw-HFqm5DJ@F1am-07%|&PkN-ZwP&nr%KDap6DQ%FxOL6g^*%qXHNgeksx XqpUR(vc(_e#gVy&&TgBzHOv(OTt`S7 delta 141 zcmaDgiSf`R#tq-4Sd;Th^GYV$X=qJ;tR%_m4Cb*ZN3(&&)i-|>mtdUiDK~Ypq$&?o zR$o<&4XjRMGNXtpZ+dEpV@^_OE?8)DyQ(#lBA6MJT3nEySDflnlCQ3#sgPK#fKWC$ RRw-!ncd6~{o9#4o6an*;F}VN$ diff --git a/mobile/openapi/lib/api_client.dart b/mobile/openapi/lib/api_client.dart index 935324272d7b5f0b35394fa461eb1e821fcd3e0b..c9ed2a508d78baa9de6f02c8acbbef7803883b2b 100644 GIT binary patch delta 55 zcmdmRmvPr!#tn6{lkdoea0ZtomSh%}WF}7z)KKKhNh-~Sixf}3sH8KwPL5-Vc(Ng*1~NB}Q4X2g$oK|{ySa!-16lLt`OJFA{K=PC zmLMsgT+P~o%w=JFhs^!X7K_Y{WG_SJuICh;{E~esve0A>cVzB;j?>88^_;trx%pgP T$lQHg*~nZy?yJaL4xZltPm*ma delta 193 zcmcaB)hx9^hmqAezcjC8vKgZWl=Xo{baE{tCzLmV@ePEvxs6E!s(AAbW<8j`4=hWd zD(A7bKv_C$@1QId_E;#Zo4pLm;^x=|Wu516hq4qnPeWN>Id?-@ySTidEI#gRD65(K KDwLJP^BVx&{YC=- diff --git a/open-api/immich-openapi-specs.json b/open-api/immich-openapi-specs.json index a9b08fc400..16c25562a6 100644 --- a/open-api/immich-openapi-specs.json +++ b/open-api/immich-openapi-specs.json @@ -660,16 +660,16 @@ ] } }, - "/albums/count": { + "/albums/statistics": { "get": { - "operationId": "getAlbumCount", + "operationId": "getAlbumStatistics", "parameters": [], "responses": { "200": { "content": { "application/json": { "schema": { - "$ref": "#/components/schemas/AlbumCountResponseDto" + "$ref": "#/components/schemas/AlbumStatisticsResponseDto" } } }, @@ -7505,25 +7505,6 @@ ], "type": "object" }, - "AlbumCountResponseDto": { - "properties": { - "notShared": { - "type": "integer" - }, - "owned": { - "type": "integer" - }, - "shared": { - "type": "integer" - } - }, - "required": [ - "notShared", - "owned", - "shared" - ], - "type": "object" - }, "AlbumResponseDto": { "properties": { "albumName": { @@ -7611,6 +7592,25 @@ ], "type": "object" }, + "AlbumStatisticsResponseDto": { + "properties": { + "notShared": { + "type": "integer" + }, + "owned": { + "type": "integer" + }, + "shared": { + "type": "integer" + } + }, + "required": [ + "notShared", + "owned", + "shared" + ], + "type": "object" + }, "AlbumUserAddDto": { "properties": { "role": { diff --git a/open-api/typescript-sdk/src/fetch-client.ts b/open-api/typescript-sdk/src/fetch-client.ts index 8b503821f7..c6d8d3e3ba 100644 --- a/open-api/typescript-sdk/src/fetch-client.ts +++ b/open-api/typescript-sdk/src/fetch-client.ts @@ -268,7 +268,7 @@ export type CreateAlbumDto = { assetIds?: string[]; description?: string; }; -export type AlbumCountResponseDto = { +export type AlbumStatisticsResponseDto = { notShared: number; owned: number; shared: number; @@ -1369,11 +1369,11 @@ export function createAlbum({ createAlbumDto }: { body: createAlbumDto }))); } -export function getAlbumCount(opts?: Oazapfts.RequestOpts) { +export function getAlbumStatistics(opts?: Oazapfts.RequestOpts) { return oazapfts.ok(oazapfts.fetchJson<{ status: 200; - data: AlbumCountResponseDto; - }>("/albums/count", { + data: AlbumStatisticsResponseDto; + }>("/albums/statistics", { ...opts })); } diff --git a/server/src/controllers/album.controller.ts b/server/src/controllers/album.controller.ts index 06f2066c29..49ec5a82ea 100644 --- a/server/src/controllers/album.controller.ts +++ b/server/src/controllers/album.controller.ts @@ -2,9 +2,9 @@ import { Body, Controller, Delete, Get, Param, Patch, Post, Put, Query } from '@ import { ApiTags } from '@nestjs/swagger'; import { AddUsersDto, - AlbumCountResponseDto, AlbumInfoDto, AlbumResponseDto, + AlbumStatisticsResponseDto, CreateAlbumDto, GetAlbumsDto, UpdateAlbumDto, @@ -22,12 +22,6 @@ import { ParseMeUUIDPipe, UUIDParamDto } from 'src/validation'; export class AlbumController { constructor(private service: AlbumService) {} - @Get('count') - @Authenticated({ permission: Permission.ALBUM_STATISTICS }) - getAlbumCount(@Auth() auth: AuthDto): Promise { - return this.service.getCount(auth); - } - @Get() @Authenticated({ permission: Permission.ALBUM_READ }) getAllAlbums(@Auth() auth: AuthDto, @Query() query: GetAlbumsDto): Promise { @@ -40,6 +34,12 @@ export class AlbumController { return this.service.create(auth, dto); } + @Get('statistics') + @Authenticated({ permission: Permission.ALBUM_STATISTICS }) + getAlbumStatistics(@Auth() auth: AuthDto): Promise { + return this.service.getStatistics(auth); + } + @Authenticated({ permission: Permission.ALBUM_READ, sharedLink: true }) @Get(':id') getAlbumInfo( diff --git a/server/src/dtos/album.dto.ts b/server/src/dtos/album.dto.ts index 8f5c996cae..b12847ee62 100644 --- a/server/src/dtos/album.dto.ts +++ b/server/src/dtos/album.dto.ts @@ -95,7 +95,7 @@ export class GetAlbumsDto { assetId?: string; } -export class AlbumCountResponseDto { +export class AlbumStatisticsResponseDto { @ApiProperty({ type: 'integer' }) owned!: number; diff --git a/server/src/services/album.service.spec.ts b/server/src/services/album.service.spec.ts index 406302ece9..16b2d97fdd 100644 --- a/server/src/services/album.service.spec.ts +++ b/server/src/services/album.service.spec.ts @@ -43,12 +43,12 @@ describe(AlbumService.name, () => { expect(sut).toBeDefined(); }); - describe('getCount', () => { + describe('getStatistics', () => { it('should get the album count', async () => { albumMock.getOwned.mockResolvedValue([]); albumMock.getShared.mockResolvedValue([]); albumMock.getNotShared.mockResolvedValue([]); - await expect(sut.getCount(authStub.admin)).resolves.toEqual({ + await expect(sut.getStatistics(authStub.admin)).resolves.toEqual({ owned: 0, shared: 0, notShared: 0, diff --git a/server/src/services/album.service.ts b/server/src/services/album.service.ts index 02dab1a740..b2b5ea32a2 100644 --- a/server/src/services/album.service.ts +++ b/server/src/services/album.service.ts @@ -1,9 +1,9 @@ import { BadRequestException, Inject, Injectable } from '@nestjs/common'; import { AddUsersDto, - AlbumCountResponseDto, AlbumInfoDto, AlbumResponseDto, + AlbumStatisticsResponseDto, CreateAlbumDto, GetAlbumsDto, UpdateAlbumDto, @@ -37,7 +37,7 @@ export class AlbumService { @Inject(IAlbumUserRepository) private albumUserRepository: IAlbumUserRepository, ) {} - async getCount(auth: AuthDto): Promise { + async getStatistics(auth: AuthDto): Promise { const [owned, shared, notShared] = await Promise.all([ this.albumRepository.getOwned(auth.user.id), this.albumRepository.getShared(auth.user.id), diff --git a/web/src/lib/components/shared-components/side-bar/more-information-albums.svelte b/web/src/lib/components/shared-components/side-bar/more-information-albums.svelte index e47daaf86b..68c58ab155 100644 --- a/web/src/lib/components/shared-components/side-bar/more-information-albums.svelte +++ b/web/src/lib/components/shared-components/side-bar/more-information-albums.svelte @@ -1,13 +1,13 @@