feat: add FavoritesModule with service, controller, and CRUD endpoints
Implemented FavoritesModule to manage user favorites. Includes service methods for adding, removing, and listing favorites, along with appropriate database integrations and API endpoints.
This commit is contained in:
43
backend/src/favorites/favorites.controller.ts
Normal file
43
backend/src/favorites/favorites.controller.ts
Normal file
@@ -0,0 +1,43 @@
|
||||
import {
|
||||
Controller,
|
||||
DefaultValuePipe,
|
||||
Delete,
|
||||
Get,
|
||||
Param,
|
||||
ParseIntPipe,
|
||||
Post,
|
||||
Query,
|
||||
Req,
|
||||
UseGuards,
|
||||
} from "@nestjs/common";
|
||||
import { AuthGuard } from "../auth/guards/auth.guard";
|
||||
import type { AuthenticatedRequest } from "../common/interfaces/request.interface";
|
||||
import { FavoritesService } from "./favorites.service";
|
||||
|
||||
@UseGuards(AuthGuard)
|
||||
@Controller("favorites")
|
||||
export class FavoritesController {
|
||||
constructor(private readonly favoritesService: FavoritesService) {}
|
||||
|
||||
@Post(":contentId")
|
||||
add(@Req() req: AuthenticatedRequest, @Param("contentId") contentId: string) {
|
||||
return this.favoritesService.addFavorite(req.user.sub, contentId);
|
||||
}
|
||||
|
||||
@Delete(":contentId")
|
||||
remove(
|
||||
@Req() req: AuthenticatedRequest,
|
||||
@Param("contentId") contentId: string,
|
||||
) {
|
||||
return this.favoritesService.removeFavorite(req.user.sub, contentId);
|
||||
}
|
||||
|
||||
@Get()
|
||||
list(
|
||||
@Req() req: AuthenticatedRequest,
|
||||
@Query("limit", new DefaultValuePipe(10), ParseIntPipe) limit: number,
|
||||
@Query("offset", new DefaultValuePipe(0), ParseIntPipe) offset: number,
|
||||
) {
|
||||
return this.favoritesService.getUserFavorites(req.user.sub, limit, offset);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user