Просмотр исходного кода

feat(ad.controller): restore recordAdClick method for ad click event reporting

Dave 2 месяцев назад
Родитель
Сommit
957f6a46c5
1 измененных файлов с 33 добавлено и 33 удалено
  1. 33 33
      apps/box-app-api/src/feature/ads/ad.controller.ts

+ 33 - 33
apps/box-app-api/src/feature/ads/ad.controller.ts

@@ -144,39 +144,39 @@ export class AdController {
    * Record ad click event for analytics.
    * Protected endpoint that requires JWT authentication.
    */
-  // @Post('click')
-  // @UseGuards(JwtAuthGuard)
-  // @ApiBearerAuth()
-  // @ApiOperation({
-  //   summary: '广告点击事件上报',
-  //   description:
-  //     '记录广告点击事件(uid/IP/UA 由服务端填充,不接受客户端时间戳)。',
-  // })
-  // @ApiResponse({
-  //   status: 200,
-  //   description: '成功',
-  //   schema: { example: { status: 1, code: 'OK' } },
-  // })
-  // @ApiResponse({ status: 401, description: '未授权 - 需要JWT token' })
-  // async recordAdClick(
-  //   @Body() body: AdClickDto,
-  //   @Req() req: RequestWithUser,
-  // ): Promise<{ status: number; code: string }> {
-  //   const uid = req.user?.uid;
-
-  //   if (!uid) {
-  //     this.logger.error('JWT payload missing uid');
-  //     throw new UnauthorizedException('Missing uid in JWT payload');
-  //   }
-
-  //   const ip = this.getClientIp(req);
-  //   const userAgent = this.getUserAgent(req);
-
-  //   // Fire-and-forget: don't await for immediate response
-  //   this.adService.recordAdClick(uid, body, ip, userAgent);
-
-  //   return { status: 1, code: 'OK' };
-  // }
+  @Post('click')
+  @UseGuards(JwtAuthGuard)
+  @ApiBearerAuth()
+  @ApiOperation({
+    summary: '广告点击事件上报',
+    description:
+      '记录广告点击事件(uid/IP/UA 由服务端填充,不接受客户端时间戳)。',
+  })
+  @ApiResponse({
+    status: 200,
+    description: '成功',
+    schema: { example: { status: 1, code: 'OK' } },
+  })
+  @ApiResponse({ status: 401, description: '未授权 - 需要JWT token' })
+  async recordAdClick(
+    @Body() body: AdClickDto,
+    @Req() req: RequestWithUser,
+  ): Promise<{ status: number; code: string }> {
+    const uid = req.user?.uid;
+
+    if (!uid) {
+      this.logger.error('JWT payload missing uid');
+      throw new UnauthorizedException('Missing uid in JWT payload');
+    }
+
+    const ip = this.getClientIp(req);
+    const userAgent = this.getUserAgent(req);
+
+    // Fire-and-forget: don't await for immediate response
+    this.adService.recordAdClick(uid, body, ip, userAgent);
+
+    return { status: 1, code: 'OK' };
+  }
 
   /**
    * POST /ads/impression