Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions apps/backend/src/app.module.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { AppModule } from './app.module';

describe('AppModule registration guard', () => {
it('prevents any controllers named test* from being registered in app.module.ts', () => {
// Retrieve registered controllers metadata from AppModule
const controllers =
(Reflect.getMetadata('controllers', AppModule) as unknown[]) || [];

const testControllers = controllers.filter((ctrl: any) => {
const name = typeof ctrl === 'function' ? ctrl.name : String(ctrl);
return name.toLowerCase().startsWith('test');
});

expect(testControllers).toEqual([]);
});
});
4 changes: 1 addition & 3 deletions apps/backend/src/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import { memoryStorage } from 'multer';

import { AppController } from './app.controller';
import { AppService } from './app.service';
import { TestExceptionController } from './test-exception.controller';

import { SentimentModule } from './sentiment/sentiment.module';
import { MetricsModule } from './metrics/metrics.module';
Expand Down Expand Up @@ -40,7 +39,6 @@ import {
createThrottlerOptions,
getRateLimitSettings,
} from './common/rate-limit/rate-limit.config';
import { TestController } from './test/test.controller';
import { UploadModule } from './upload/upload.module';
import { AuthModule } from './auth/auth.module';
import { UsersModule } from './users/users.module';
Expand Down Expand Up @@ -225,7 +223,7 @@ import { DashboardModule } from './dashboard/dashboard.module';
// Aggregated, cached dashboard read model
DashboardModule,
],
controllers: [AppController, TestController, TestExceptionController],
controllers: [AppController],
providers: [
AppService,
StructuredLoggerService,
Expand Down
1 change: 1 addition & 0 deletions apps/backend/src/filters/global-exception.filter.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -198,3 +198,4 @@ describe('GlobalExceptionFilter', () => {
);
});
});

94 changes: 94 additions & 0 deletions apps/backend/src/sentiment/sentiment.controller.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
import {
Controller,
Get,
Post,
Body,
HttpException,
HttpStatus,
} from '@nestjs/common';
import {
ApiTags,
ApiOperation,
ApiResponse,
ApiProperty,
} from '@nestjs/swagger';
import {
SentimentService,
SentimentResponse,
HealthResponse,
} from './sentiment.service';

export class AnalyzeDto {
@ApiProperty({
description: 'The text to run sentiment analysis on',
example: 'Lumenpulse is doing great!',
})
text: string;
}

export class SentimentResponseDto implements SentimentResponse {
@ApiProperty({
description: 'Calculated sentiment polarity score between -1 and 1',
example: 0.85,
})
sentiment: number;
}

export class HealthResponseDto implements HealthResponse {
@ApiProperty({ description: 'Service health status', example: 'healthy' })
status: string;

@ApiProperty({
description: 'Timestamp of health check',
example: '2026-05-27T20:58:35Z',
})
timestamp: string;

@ApiProperty({
description: 'Service name identifier',
example: 'sentiment-analysis',
})
service: string;
}

@ApiTags('sentiment')
@Controller('sentiment')
export class SentimentController {
constructor(private readonly sentimentService: SentimentService) {}

@Post('analyze')
@ApiOperation({
summary: 'Analyze text sentiment polarity',
description: 'Submits text to calculate polarity scores.',
})
@ApiResponse({
status: 200,
description: 'Sentiment calculated successfully',
type: SentimentResponseDto,
})
@ApiResponse({ status: 400, description: 'Bad request (text empty)' })
@ApiResponse({ status: 503, description: 'Sentiment service unavailable' })
async analyzeSentiment(
@Body() analyzeDto: AnalyzeDto,
): Promise<SentimentResponse> {
if (!analyzeDto || analyzeDto.text === undefined || analyzeDto.text === null) {
throw new HttpException('Text cannot be empty', HttpStatus.BAD_REQUEST);
}
return this.sentimentService.analyzeSentiment(analyzeDto.text);
}

@Get('health')
@ApiOperation({
summary: 'Check sentiment service health status',
description: 'Checks health of sentiment analysis service.',
})
@ApiResponse({
status: 200,
description: 'Sentiment service health retrieved successfully',
type: HealthResponseDto,
})
@ApiResponse({ status: 503, description: 'Sentiment service unavailable' })
async checkSentimentHealth(): Promise<HealthResponse> {
return this.sentimentService.checkHealth();
}
}
3 changes: 3 additions & 0 deletions apps/backend/src/sentiment/sentiment.module.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Module } from '@nestjs/common';
import { HttpModule } from '@nestjs/axios';
import { SentimentService } from './sentiment.service';
import { SentimentController } from './sentiment.controller';
import { ConfigModule } from '@nestjs/config';

@Module({
Expand All @@ -13,7 +14,9 @@ import { ConfigModule } from '@nestjs/config';
}),
ConfigModule,
],
controllers: [SentimentController],
providers: [SentimentService],
exports: [SentimentService],
})
export class SentimentModule {}

Loading
Loading