Skip to content

Commit

Permalink
feat: add post endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
Santiago Olayo committed Jun 23, 2024
1 parent a3f9ea1 commit 5c19388
Show file tree
Hide file tree
Showing 6 changed files with 74 additions and 2 deletions.
2 changes: 2 additions & 0 deletions src/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { TypeOrmModule } from '@nestjs/typeorm';
import { SecretsManagerModule } from './secrets-manager/secrets-manager.module';
import { SecretsManagerService } from './secrets-manager/secrets-manager.service';
import { DatabaseCredentials } from './secrets-manager/secret-value-interfaces/database-credentials.interface';
import { PostsModule } from './posts/posts.module';


@Module({
Expand All @@ -30,6 +31,7 @@ import { DatabaseCredentials } from './secrets-manager/secret-value-interfaces/d
};
},
}),
PostsModule,
],
controllers: [AppController],
providers: [AppService],
Expand Down
6 changes: 4 additions & 2 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,18 @@ import { DocumentBuilder, SwaggerModule } from '@nestjs/swagger';
async function bootstrap() {
const app = await NestFactory.create(AppModule);

app.setGlobalPrefix('api');

const config = new DocumentBuilder()
.setTitle('Auth Microservice')
.setDescription('The Auth API')
.setVersion('1.0')
.addTag('nestjs')
.addTag('NestJS')
.build();

const document = SwaggerModule.createDocument(app, config);
SwaggerModule.setup('docs', app, document);

await app.listen(process.env.PORT ?? 3000);
}
bootstrap();
33 changes: 33 additions & 0 deletions src/posts/post.entity.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import {
Entity,
Column,
PrimaryGeneratedColumn,
CreateDateColumn,
UpdateDateColumn,
} from 'typeorm';

@Entity({
name: 'posts',
})
export class Post {
@PrimaryGeneratedColumn()
id: number;

@Column()
title: string;

@Column({
type: 'text',
name: 'image_url',
})
imageUrl: string;

@CreateDateColumn({ name: 'created_at' })
createdAt: string;

@UpdateDateColumn({ name: 'updated_at' })
updatedAt: string;

@Column({ default: true, name: 'is_active' })
isActive: boolean;
}
16 changes: 16 additions & 0 deletions src/posts/posts.controller.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { Controller, Get } from '@nestjs/common';
import { ApiOperation, ApiResponse } from '@nestjs/swagger';
import { PostsService } from './posts.service';
import { Post } from './post.entity';

@Controller('/v1/posts')
export class PostsController {
constructor(private readonly postService: PostsService) {}

@Get('')
@ApiOperation({ summary: 'List posts' })
@ApiResponse({ status: 200, description: 'Post found' })
async getPosts(): Promise<Post[]> {
return this.postService.getPosts();
}
}
9 changes: 9 additions & 0 deletions src/posts/posts.module.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { Module } from '@nestjs/common';
import { PostsService } from './posts.service';
import { PostsController } from './posts.controller';

@Module({
providers: [PostsService],
controllers: [PostsController]
})
export class PostsModule {}
10 changes: 10 additions & 0 deletions src/posts/posts.service.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { Injectable } from '@nestjs/common';
import { Post } from './post.entity';

@Injectable()
export class PostsService {

getPosts(): Promise<Post[]> {
return Promise.resolve([]);
}
}

0 comments on commit 5c19388

Please sign in to comment.