feat(listings): implement Listings module with CRUD, media upload, and moderation

Full DDD/CQRS implementation for the Listings module (TEC-1423):
- Domain: Property, Listing, PropertyMedia entities with status machine
- Value Objects: Address, GeoPoint, Price with validation
- Events: ListingCreated, ListingApproved, ListingSold
- Commands: CreateListing, UpdateListingStatus, UploadMedia, ModerateListing
- Queries: GetListing, SearchListings, GetPendingModeration
- Infrastructure: Prisma repositories with PostGIS support, MinIO media storage
- Presentation: REST controller with JWT auth, role-based moderation
- 21 domain unit tests (all passing)

Co-Authored-By: Paperclip <noreply@paperclip.ing>
This commit is contained in:
Ho Ngoc Hai
2026-04-08 01:47:15 +07:00
parent 6741592cbe
commit 8a33aae026
50 changed files with 2108 additions and 0 deletions

View File

@@ -0,0 +1,63 @@
import { Module } from '@nestjs/common';
import { CqrsModule } from '@nestjs/cqrs';
import { MulterModule } from '@nestjs/platform-express';
// Domain
import { PROPERTY_REPOSITORY } from './domain/repositories/property.repository';
import { LISTING_REPOSITORY } from './domain/repositories/listing.repository';
// Infrastructure
import { PrismaPropertyRepository } from './infrastructure/repositories/prisma-property.repository';
import { PrismaListingRepository } from './infrastructure/repositories/prisma-listing.repository';
import { MEDIA_STORAGE_SERVICE, MinioMediaStorageService } from './infrastructure/services/media-storage.service';
// Application — Commands
import { CreateListingHandler } from './application/commands/create-listing/create-listing.handler';
import { UpdateListingStatusHandler } from './application/commands/update-listing-status/update-listing-status.handler';
import { UploadMediaHandler } from './application/commands/upload-media/upload-media.handler';
import { ModerateListingHandler } from './application/commands/moderate-listing/moderate-listing.handler';
// Application — Queries
import { GetListingHandler } from './application/queries/get-listing/get-listing.handler';
import { SearchListingsHandler } from './application/queries/search-listings/search-listings.handler';
import { GetPendingModerationHandler } from './application/queries/get-pending-moderation/get-pending-moderation.handler';
// Presentation
import { ListingsController } from './presentation/controllers/listings.controller';
const CommandHandlers = [
CreateListingHandler,
UpdateListingStatusHandler,
UploadMediaHandler,
ModerateListingHandler,
];
const QueryHandlers = [
GetListingHandler,
SearchListingsHandler,
GetPendingModerationHandler,
];
@Module({
imports: [
CqrsModule,
MulterModule.register({
limits: { fileSize: 10 * 1024 * 1024 }, // 10 MB
}),
],
controllers: [ListingsController],
providers: [
// Repositories
{ provide: PROPERTY_REPOSITORY, useClass: PrismaPropertyRepository },
{ provide: LISTING_REPOSITORY, useClass: PrismaListingRepository },
// Services
{ provide: MEDIA_STORAGE_SERVICE, useClass: MinioMediaStorageService },
// CQRS
...CommandHandlers,
...QueryHandlers,
],
exports: [LISTING_REPOSITORY, PROPERTY_REPOSITORY],
})
export class ListingsModule {}