From 334a709cc644d97c8ef3a5c7344912bda4b4594e Mon Sep 17 00:00:00 2001 From: Jason Rasmussen Date: Mon, 8 Jul 2024 16:41:39 -0400 Subject: [PATCH] refactor(server): partner search dto (#10902) * refactor(server): partner search dto * fix: missed reference * mobile fix --------- Co-authored-by: Alex Tran --- mobile/lib/services/partner.service.dart | 14 +------------- mobile/lib/services/user.service.dart | 4 ++-- mobile/openapi/README.md | Bin 30890 -> 30938 bytes mobile/openapi/lib/api.dart | Bin 10439 -> 10476 bytes mobile/openapi/lib/api/partners_api.dart | Bin 6518 -> 6558 bytes mobile/openapi/lib/api_client.dart | Bin 27346 -> 27445 bytes mobile/openapi/lib/api_helper.dart | Bin 6162 -> 6272 bytes .../openapi/lib/model/partner_direction.dart | Bin 0 -> 2698 bytes open-api/immich-openapi-specs.json | 13 ++++++++----- open-api/typescript-sdk/src/fetch-client.ts | 6 +++++- server/src/controllers/partner.controller.ts | 6 +++--- server/src/dtos/partner.dto.ts | 10 +++++++++- server/src/services/partner.service.spec.ts | 6 +++--- server/src/services/partner.service.ts | 4 ++-- .../partner-selection-modal.svelte | 4 ++-- .../partner-settings.svelte | 5 +++-- web/src/routes/(user)/sharing/+page.ts | 4 ++-- 17 files changed, 40 insertions(+), 36 deletions(-) create mode 100644 mobile/openapi/lib/model/partner_direction.dart diff --git a/mobile/lib/services/partner.service.dart b/mobile/lib/services/partner.service.dart index 84f37ce7e..8cd2fe424 100644 --- a/mobile/lib/services/partner.service.dart +++ b/mobile/lib/services/partner.service.dart @@ -14,17 +14,6 @@ final partnerServiceProvider = Provider( ), ); -enum PartnerDirection { - sharedWith("shared-with"), - sharedBy("shared-by"); - - const PartnerDirection( - this._value, - ); - - final String _value; -} - class PartnerService { final ApiService _apiService; final Isar _db; @@ -34,8 +23,7 @@ class PartnerService { Future?> getPartners(PartnerDirection direction) async { try { - final userDtos = - await _apiService.partnersApi.getPartners(direction._value); + final userDtos = await _apiService.partnersApi.getPartners(direction); if (userDtos != null) { return userDtos.map((u) => User.fromPartnerDto(u)).toList(); } diff --git a/mobile/lib/services/user.service.dart b/mobile/lib/services/user.service.dart index 0d8d47b10..9631141c4 100644 --- a/mobile/lib/services/user.service.dart +++ b/mobile/lib/services/user.service.dart @@ -73,9 +73,9 @@ class UserService { Future?> getUsersFromServer() async { final List? users = await _getAllUsers(); final List? sharedBy = - await _partnerService.getPartners(PartnerDirection.sharedBy); + await _partnerService.getPartners(PartnerDirection.by); final List? sharedWith = - await _partnerService.getPartners(PartnerDirection.sharedWith); + await _partnerService.getPartners(PartnerDirection.with_); if (users == null || sharedBy == null || sharedWith == null) { _log.warning("Failed to refresh users"); diff --git a/mobile/openapi/README.md b/mobile/openapi/README.md index c3ef247ddcb223e9a0d210b67ae154eccb971992..674409d81de9ac6d12932e87f03397a8f8658d0f 100644 GIT binary patch delta 47 wcmZ4Wk@40?#tmnZ6kIZkQj<$E^YdagQu34a^#c-%O7c>R;KG~tB)t;_0QBh;asU7T delta 14 Wcmcchk#W^W#tmnZHvdVwCkg;S$_PsU diff --git a/mobile/openapi/lib/api.dart b/mobile/openapi/lib/api.dart index cda2bac4c5dc17bc251229778d78b2bcc21b095e..e6a3907a2463920ca214592d4baf5b05847feecd 100644 GIT binary patch delta 26 icmX>e_$F|}88Ob3%%arflFa6;rla+siE@{{Gb)uG~(8#yE=KM)h&+{!J< F2LL8<5&i%G diff --git a/mobile/openapi/lib/api_client.dart b/mobile/openapi/lib/api_client.dart index 32490a6820bc1545175aadab7cd4f42f14832afe..2645a328133ab3753768d94dd89064fc0f4c94c4 100644 GIT binary patch delta 46 tcmca~m2vAe#tr{%IbAY~Qj<$E^YbPrI*3k|w_`&RX;jtU{KNK^4gkz&6AAzT delta 14 Wcmdmbjq%b|#tr{%Hz(O$)&T%Jxd(Fq diff --git a/mobile/openapi/lib/api_helper.dart b/mobile/openapi/lib/api_helper.dart index 762b728869c128d357d2a9a98b8268b6f84c73a0..db8af0bfc27697456f4ce2006747c32f102c18e6 100644 GIT binary patch delta 62 zcmbPa&|tVBm`As$BrmndC9^0sxg;|`Pg9|qO92RqQcFsU@)QCRQKctuV6)#G$a9bz E0JgLiYXATM delta 12 TcmZoLoMf;em}m1rp8ebaAIJpF diff --git a/mobile/openapi/lib/model/partner_direction.dart b/mobile/openapi/lib/model/partner_direction.dart new file mode 100644 index 0000000000000000000000000000000000000000..c43c0df75daba7a46e98ab1464b696c17b05fca7 GIT binary patch literal 2698 zcmai0ZExC05dO}um`GJaBx>&NQ$>%`NRYdndP#L9A1Z{b#U8_6?OosQI>@T>-*0Bu zc8Gx{Qm~EZZJ%f68OGzmcnsGM%lmhKEbbQnTrU@MxVinj7{UA=?(UcH_x=3#=Gz6C zvE`>!7&rYb`t|*QALUkQgK?%!oXH#~P^rpd8e@(HDmQAMWl?J5PI`!ZFKQc?m5UAj zS4l(eN)+^23PV?i#!_%&PrD~tStpc>Wl9NUCee6zdoo!r71}u0YD;ErCsh3YmpIu8 zV+R9D=RjwmOH`ti5&eG{37{T80u=56RaL-V zx*fP3LTU6Pm6pQlQREe_Bl7b#ABBwKq1#CtdAlo09TF@lNTpIVc`elz{97)QZ9}dC ziwznMoJl2e`07k&>BD@|k7x{4K_<;hr^C(g3Z@@JP;c73{>y6Be@Q?)nKb2ZYM7on zgSoVXC#LT<^(CDG;Ds0C62IceHtgB}@L5{Vi^y{*wY74SW2o4IQ~`$-gT7w%S@LMV z$nW8^RKV|j+m9>C2e7F}{^|?m+qEyG3DS3(L1uK}u}W*|T0$q#$Efy=mvxCtBb23a zDbNhBq7)OI;_!g+CJ&$axI)P3>zjVUe~GCP{Mcxn!`A4%V0@;KiQMAo>B@I%+ZqOK zmAli&r-L#8GJ_$91Zpo2{oA*|&ylou+AWIG)oo0QstpW7*HLDsgH4~`w|PU?p6Hhj zK63Zn!X<V>){pA*DFVdbQ+zF+F z)fVQG4ol-ldyN#pU_l!uWwm5P*q(j`7_u-(@-IoaE6Xd10_&WDmF4q-Wtt92cpBxlTKCv~h~YzRl%VM*1KU3hz_D2cELhl^{{FnLr_w5fwkvfjLO z^K0w8qhBb`zA0vcq { - return this.service.getAll(auth, direction); + getPartners(@Auth() auth: AuthDto, @Query() dto: PartnerSearchDto): Promise { + return this.service.search(auth, dto); } @Post(':id') diff --git a/server/src/dtos/partner.dto.ts b/server/src/dtos/partner.dto.ts index 187f8f341..38573998d 100644 --- a/server/src/dtos/partner.dto.ts +++ b/server/src/dtos/partner.dto.ts @@ -1,11 +1,19 @@ -import { IsNotEmpty } from 'class-validator'; +import { ApiProperty } from '@nestjs/swagger'; +import { IsEnum, IsNotEmpty } from 'class-validator'; import { UserResponseDto } from 'src/dtos/user.dto'; +import { PartnerDirection } from 'src/interfaces/partner.interface'; export class UpdatePartnerDto { @IsNotEmpty() inTimeline!: boolean; } +export class PartnerSearchDto { + @IsEnum(PartnerDirection) + @ApiProperty({ enum: PartnerDirection, enumName: 'PartnerDirection' }) + direction!: PartnerDirection; +} + export class PartnerResponseDto extends UserResponseDto { inTimeline?: boolean; } diff --git a/server/src/services/partner.service.spec.ts b/server/src/services/partner.service.spec.ts index 043b8ae71..b2b340125 100644 --- a/server/src/services/partner.service.spec.ts +++ b/server/src/services/partner.service.spec.ts @@ -21,16 +21,16 @@ describe(PartnerService.name, () => { expect(sut).toBeDefined(); }); - describe('getAll', () => { + describe('search', () => { it("should return a list of partners with whom I've shared my library", async () => { partnerMock.getAll.mockResolvedValue([partnerStub.adminToUser1, partnerStub.user1ToAdmin1]); - await expect(sut.getAll(authStub.user1, PartnerDirection.SharedBy)).resolves.toBeDefined(); + await expect(sut.search(authStub.user1, { direction: PartnerDirection.SharedBy })).resolves.toBeDefined(); expect(partnerMock.getAll).toHaveBeenCalledWith(authStub.user1.user.id); }); it('should return a list of partners who have shared their libraries with me', async () => { partnerMock.getAll.mockResolvedValue([partnerStub.adminToUser1, partnerStub.user1ToAdmin1]); - await expect(sut.getAll(authStub.user1, PartnerDirection.SharedWith)).resolves.toBeDefined(); + await expect(sut.search(authStub.user1, { direction: PartnerDirection.SharedWith })).resolves.toBeDefined(); expect(partnerMock.getAll).toHaveBeenCalledWith(authStub.user1.user.id); }); }); diff --git a/server/src/services/partner.service.ts b/server/src/services/partner.service.ts index e1d4e9738..d26149dce 100644 --- a/server/src/services/partner.service.ts +++ b/server/src/services/partner.service.ts @@ -1,7 +1,7 @@ import { BadRequestException, Inject, Injectable } from '@nestjs/common'; import { AccessCore, Permission } from 'src/cores/access.core'; import { AuthDto } from 'src/dtos/auth.dto'; -import { PartnerResponseDto, UpdatePartnerDto } from 'src/dtos/partner.dto'; +import { PartnerResponseDto, PartnerSearchDto, UpdatePartnerDto } from 'src/dtos/partner.dto'; import { mapUser } from 'src/dtos/user.dto'; import { PartnerEntity } from 'src/entities/partner.entity'; import { IAccessRepository } from 'src/interfaces/access.interface'; @@ -38,7 +38,7 @@ export class PartnerService { await this.repository.remove(partner); } - async getAll(auth: AuthDto, direction: PartnerDirection): Promise { + async search(auth: AuthDto, { direction }: PartnerSearchDto): Promise { const partners = await this.repository.getAll(auth.user.id); const key = direction === PartnerDirection.SharedBy ? 'sharedById' : 'sharedWithId'; return partners diff --git a/web/src/lib/components/user-settings-page/partner-selection-modal.svelte b/web/src/lib/components/user-settings-page/partner-selection-modal.svelte index 88cda3cc0..3cff1cd1d 100644 --- a/web/src/lib/components/user-settings-page/partner-selection-modal.svelte +++ b/web/src/lib/components/user-settings-page/partner-selection-modal.svelte @@ -1,5 +1,5 @@