Created
February 24, 2024 10:43
-
-
Save Wanuja97/cc9d130bc8721d6018b1a2a3f47b5dd9 to your computer and use it in GitHub Desktop.
SRP-compliant Approach: PostController
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Controller, Get, Post, Body} from '@nestjs/common'; | |
import { PostsService } from './posts.service'; | |
import { CreatePostDto } from './dto/create-post.dto'; | |
@Controller('posts') | |
export class PostsController { | |
constructor(private readonly postsService: PostsService) {} | |
// endpoint for create new post | |
@Post() | |
createPost(@Body() createPostDto: CreatePostDto) { | |
return this.postsService.createPost(createPostDto); | |
} | |
// endpoint for retrieve all posts | |
@Get() | |
findAllPosts() { | |
return this.postsService.findAllPosts(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment