diff --git a/src/modules/atproto/infrastructure/services/RepositoryCollectionIds.ts b/src/modules/atproto/infrastructure/services/RepositoryCollectionIds.ts new file mode 100644 index 00000000..75cad95f --- /dev/null +++ b/src/modules/atproto/infrastructure/services/RepositoryCollectionIds.ts @@ -0,0 +1,5 @@ +export const REPOSITORY_COLLECTION_IDS = { + COLLECTIONS: 'network.cosmik.collection', + CARDS: 'network.cosmik.card', + COLLECTION_LINKS: 'network.cosmik.collectionLink', +}; diff --git a/src/modules/cards/application/useCases/queries/GetCollectionPageByAtUriUseCase.ts b/src/modules/cards/application/useCases/queries/GetCollectionPageByAtUriUseCase.ts index 4f04fe1d..7d1e59d0 100644 --- a/src/modules/cards/application/useCases/queries/GetCollectionPageByAtUriUseCase.ts +++ b/src/modules/cards/application/useCases/queries/GetCollectionPageByAtUriUseCase.ts @@ -1,16 +1,19 @@ -import { err, ok, Result } from 'src/shared/core/Result'; +import { err, Result } from 'src/shared/core/Result'; import { UseCase } from 'src/shared/core/UseCase'; import { IAtUriResolutionService } from '../../../domain/services/IAtUriResolutionService'; import { IIdentityResolutionService } from '../../../../atproto/domain/services/IIdentityResolutionService'; import { DIDOrHandle } from '../../../../atproto/domain/DIDOrHandle'; import { ATUri } from '../../../../atproto/domain/ATUri'; -import { - GetCollectionPageUseCase, +import { + GetCollectionPageUseCase, GetCollectionPageResult, CollectionNotFoundError, - CardSortField, - SortOrder } from './GetCollectionPageUseCase'; +import { + CardSortField, + SortOrder, +} from 'src/modules/cards/domain/ICardQueryRepository'; +import { REPOSITORY_COLLECTION_IDS } from 'src/modules/atproto/infrastructure/services/RepositoryCollectionIds'; export interface GetCollectionPageByAtUriQuery { handle: string; @@ -23,7 +26,8 @@ export interface GetCollectionPageByAtUriQuery { } export class GetCollectionPageByAtUriUseCase - implements UseCase> + implements + UseCase> { constructor( private identityResolutionService: IIdentityResolutionService, @@ -37,34 +41,48 @@ export class GetCollectionPageByAtUriUseCase // First resolve the handle to a DID const identifierResult = DIDOrHandle.create(query.handle); if (identifierResult.isErr()) { - return err(new Error(`Invalid handle: ${identifierResult.error.message}`)); + return err( + new Error(`Invalid handle: ${identifierResult.error.message}`), + ); } - const didResult = await this.identityResolutionService.resolveToDID(identifierResult.value); + const didResult = await this.identityResolutionService.resolveToDID( + identifierResult.value, + ); if (didResult.isErr()) { - return err(new Error(`Failed to resolve handle to DID: ${didResult.error.message}`)); + return err( + new Error( + `Failed to resolve handle to DID: ${didResult.error.message}`, + ), + ); } // Construct the AT URI using the resolved DID const atUriResult = ATUri.fromParts( didResult.value, - 'network.cosmik.collection', - query.recordKey + REPOSITORY_COLLECTION_IDS.COLLECTIONS, + query.recordKey, ); if (atUriResult.isErr()) { - return err(new Error(`Failed to construct AT URI: ${atUriResult.error.message}`)); + return err( + new Error(`Failed to construct AT URI: ${atUriResult.error.message}`), + ); } // Resolve the AT URI to a collection ID - const collectionIdResult = await this.atUriResolutionService - .resolveCollectionId(atUriResult.value.value); + const collectionIdResult = + await this.atUriResolutionService.resolveCollectionId( + atUriResult.value.value, + ); if (collectionIdResult.isErr()) { return err(collectionIdResult.error); } if (!collectionIdResult.value) { - return err(new CollectionNotFoundError('Collection not found for AT URI')); + return err( + new CollectionNotFoundError('Collection not found for AT URI'), + ); } // Delegate to the existing use case