| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125 |
- import { Controller, Get, Logger, Param, Query } from '@nestjs/common';
- import {
- ApiOperation,
- ApiResponse,
- ApiTags,
- ApiParam,
- ApiQuery,
- } from '@nestjs/swagger';
- import { RecommendationService } from './recommendation.service';
- import {
- YouMayAlsoLikeVideoResponseDto,
- YouMayAlsoLikeAdResponseDto,
- } from './dto/enriched-recommendation.dto';
- import { AdType as PrismaAdType } from '@prisma/mongo/client';
- @ApiTags('推荐')
- @Controller('recommend')
- export class RecommendPublicController {
- private readonly logger = new Logger(RecommendPublicController.name);
- constructor(private readonly recommendationService: RecommendationService) {}
- @Get('video/:videoId')
- @ApiOperation({
- summary: '获取视频推荐 - 猜你喜欢',
- description:
- '基于当前视频的标签和Redis分数,返回带有完整元数据的相似视频推荐列表。仅返回上架状态的视频。',
- })
- @ApiParam({
- name: 'videoId',
- description: '当前视频ID',
- example: '6756abc123def',
- })
- @ApiQuery({
- name: 'limit',
- required: false,
- description: '返回推荐数量(默认6)',
- example: 6,
- })
- @ApiResponse({
- status: 200,
- description: '成功返回推荐列表',
- type: YouMayAlsoLikeVideoResponseDto,
- })
- async getVideoRecommendations(
- @Param('videoId') videoId: string,
- @Query('limit') limit?: string,
- ): Promise<YouMayAlsoLikeVideoResponseDto> {
- const limitNum = limit ? parseInt(limit, 10) : 6;
- this.logger.debug(
- `GET /api/v1/recommend/video/${videoId}?limit=${limitNum}`,
- );
- const recommendations =
- await this.recommendationService.getEnrichedVideoRecommendations(
- videoId,
- limitNum,
- );
- return {
- currentVideoId: videoId,
- recommendations,
- count: recommendations.length,
- };
- }
- @Get('ad/:adId')
- @ApiOperation({
- summary: '获取广告推荐 - 猜你喜欢',
- description:
- '基于渠道和广告模块过滤,返回带有完整元数据的相似广告推荐列表。仅返回同渠道、同模块、状态启用且在有效期内的广告。',
- })
- @ApiParam({
- name: 'adId',
- description: '当前广告ID',
- example: '6756def456ghi',
- })
- // @ApiQuery({
- // name: 'channelId',
- // required: true,
- // description: '渠道ID(必须匹配)',
- // example: '6756channel123',
- // })
- @ApiQuery({
- name: 'adType',
- required: true,
- enum: PrismaAdType,
- description: '广告类型/模块 (AdType enum)',
- })
- @ApiQuery({
- name: 'limit',
- required: false,
- description: '返回推荐数量(默认3)',
- example: 3,
- })
- @ApiResponse({
- status: 200,
- description: '成功返回推荐列表',
- type: YouMayAlsoLikeAdResponseDto,
- })
- async getAdRecommendations(
- @Param('adId') adId: string,
- @Query('adType') adType: PrismaAdType,
- @Query('limit') limit?: string,
- ): Promise<YouMayAlsoLikeAdResponseDto> {
- const limitNum = limit ? parseInt(limit, 10) : 3;
- this.logger.debug(
- `GET /api/v1/recommend/ad/${adId}?adType=${adType}&limit=${limitNum}`,
- );
- const recommendations =
- await this.recommendationService.getEnrichedAdRecommendations(adId, {
- adType,
- limit: limitNum,
- });
- return {
- currentAdId: adId,
- recommendations,
- count: recommendations.length,
- };
- }
- }
|