diff --git a/src/modules/cards/application/services/ICardLibraryQueryService.ts b/src/modules/cards/application/services/ICardLibraryQueryService.ts deleted file mode 100644 index 36917647..00000000 --- a/src/modules/cards/application/services/ICardLibraryQueryService.ts +++ /dev/null @@ -1,29 +0,0 @@ -import { Result } from '../../../../shared/core/Result'; -import { CardId } from '../../domain/value-objects/CardId'; - -export interface ICardLibraryQueryService { - /** - * Get all user IDs who have this card in their library - */ - getLibrariesForCard(cardId: CardId): Promise>; - - /** - * Get all card IDs in a user's library - */ - getCardsInLibrary(userId: string): Promise>; - - /** - * Check if a specific card is in a user's library - */ - isCardInLibrary(cardId: CardId, userId: string): Promise>; - - /** - * Get library membership count for a card - */ - getLibraryMembershipCount(cardId: CardId): Promise>; - - /** - * Get total number of cards in a user's library - */ - getLibraryCardCount(userId: string): Promise>; -} diff --git a/src/modules/cards/infrastructure/services/DrizzleCardLibraryQueryService.ts b/src/modules/cards/infrastructure/services/DrizzleCardLibraryQueryService.ts deleted file mode 100644 index 499c26cb..00000000 --- a/src/modules/cards/infrastructure/services/DrizzleCardLibraryQueryService.ts +++ /dev/null @@ -1,95 +0,0 @@ -import { eq, and, count } from 'drizzle-orm'; -import { PostgresJsDatabase } from 'drizzle-orm/postgres-js'; -import { ICardLibraryQueryService } from '../../application/services/ICardLibraryQueryService'; -import { CardId } from '../../domain/value-objects/CardId'; -import { libraryMemberships } from '../repositories/schema/libraryMembership.sql'; -import { cards } from '../repositories/schema/card.sql'; -import { Result, ok, err } from '../../../../shared/core/Result'; - -export class DrizzleCardLibraryQueryService - implements ICardLibraryQueryService -{ - constructor(private db: PostgresJsDatabase) {} - - async getLibrariesForCard(cardId: CardId): Promise> { - try { - const results = await this.db - .select({ userId: libraryMemberships.userId }) - .from(libraryMemberships) - .where(eq(libraryMemberships.cardId, cardId.getStringValue())); - - return ok(results.map((r) => r.userId)); - } catch (error) { - return err(error as Error); - } - } - - async getCardsInLibrary(userId: string): Promise> { - try { - const results = await this.db - .select({ id: cards.id }) - .from(cards) - .where(eq(cards.authorId, userId)); - - const cardIds: CardId[] = []; - for (const result of results) { - const cardIdResult = CardId.createFromString(result.id); - if (cardIdResult.isOk()) { - cardIds.push(cardIdResult.value); - } - } - - return ok(cardIds); - } catch (error) { - return err(error as Error); - } - } - - async isCardInLibrary( - cardId: CardId, - userId: string, - ): Promise> { - try { - const result = await this.db - .select({ id: cards.id }) - .from(cards) - .where( - and( - eq(cards.id, cardId.getStringValue()), - eq(cards.authorId, userId), - ), - ) - .limit(1); - - return ok(result.length > 0); - } catch (error) { - return err(error as Error); - } - } - - async getLibraryMembershipCount(cardId: CardId): Promise> { - try { - const results = await this.db - .select({ userId: libraryMemberships.userId }) - .from(libraryMemberships) - .where(eq(libraryMemberships.cardId, cardId.getStringValue())); - - return ok(results.length); - } catch (error) { - return err(error as Error); - } - } - - async getLibraryCardCount(userId: string): Promise> { - try { - const result = await this.db - .select({ count: count() }) - .from(cards) - .where(eq(cards.authorId, userId)); - - return ok(result[0]?.count || 0); - } catch (error) { - return err(error as Error); - } - } -}