feat(backend): add /feed endpoint mirrored from /posts
- Introduced FeedModule with controller and service - /feed mirrors /posts 1:1 (baseline, deterministic) - No discovery or random logic yet - Prisma + DI fully wired and stable - Backend now frontend-ready for feed consumption
This commit is contained in:
1 parent
703470e501
commit
5b66e57d2e
4 files changed
+54
-3
No files matched your search
@@ -1,17 +1,21 @@
|
||||
import { Module } from '@nestjs/common';
|
||||
import { APP_GUARD } from '@nestjs/core';
|
||||
|
||||
import { PostsModule } from './posts/posts.module';
|
||||
import { FeedModule } from './feed/feed.module';
|
||||
import { PrismaModule } from './prisma/prisma.module';
|
||||
|
||||
import { DummyAuthGuard } from './auth/guards/dummy-auth.guard';
|
||||
import { HealthController } from './health.controller';
|
||||
|
||||
@Module({
|
||||
imports: [
|
||||
PostsModule, // 👈 aktivieren wir jetzt bewusst
|
||||
PrismaModule,
|
||||
PrismaModule, // Basis zuerst
|
||||
PostsModule, // /posts
|
||||
FeedModule, // /feed (1:1 Spiegel)
|
||||
],
|
||||
controllers: [
|
||||
HealthController, // 👈 bleibt direkt hier
|
||||
HealthController,
|
||||
],
|
||||
providers: [
|
||||
{
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
import { Controller, Get, Req } from '@nestjs/common';
|
||||
import { FeedService } from './feed.service';
|
||||
import { AuthRequest } from '../auth/types/auth-request';
|
||||
|
||||
@Controller('feed')
|
||||
export class FeedController {
|
||||
constructor(private readonly feedService: FeedService) {}
|
||||
|
||||
@Get()
|
||||
async getFeed(@Req() req: AuthRequest) {
|
||||
return this.feedService.getFeed(req.user);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
import { Module } from '@nestjs/common';
|
||||
import { FeedController } from './feed.controller';
|
||||
import { FeedService } from './feed.service';
|
||||
import { PrismaService } from '../prisma/prisma.service';
|
||||
|
||||
@Module({
|
||||
controllers: [FeedController],
|
||||
providers: [FeedService, PrismaService],
|
||||
})
|
||||
export class FeedModule {}
|
||||
@@ -0,0 +1,24 @@
|
||||
import { Injectable } from '@nestjs/common';
|
||||
import { PrismaService } from '../prisma/prisma.service';
|
||||
|
||||
type AuthUser = {
|
||||
id: string;
|
||||
role: 'USER' | 'ADMIN' | 'MOD';
|
||||
} | null;
|
||||
|
||||
@Injectable()
|
||||
export class FeedService {
|
||||
constructor(private readonly prisma: PrismaService) {}
|
||||
|
||||
async getFeed(_user: AuthUser) {
|
||||
return this.prisma.post.findMany({
|
||||
include: {
|
||||
pet: true,
|
||||
author: true,
|
||||
},
|
||||
orderBy: {
|
||||
createdAt: 'desc',
|
||||
},
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user