Last active
February 24, 2024 10:31
-
-
Save Wanuja97/6fb83f26cfc9ad0185cdce0a11e156c2 to your computer and use it in GitHub Desktop.
Non-SRP Approach: UserPosts Controller
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 { UserpostsService } from './userposts.service'; | |
import { CreateUserDto } from 'src/users/dto/create-user.dto'; | |
import { CreatePostDto } from 'src/posts/dto/create-post.dto'; | |
/* | |
This approach is not recommended because this controller class is | |
responsible for handling users and posts endpoints............. | |
Violates Single Responsibility Principle..................... | |
*/ | |
@Controller('userposts') | |
export class UserpostsController { | |
constructor(private readonly userpostsService: UserpostsService) {} | |
//endpoint for create new user | |
@Post('/createuser') | |
createUser(@Body() createUserDto: CreateUserDto) { | |
return this.userpostsService.createPost(createUserDto); | |
} | |
//endpoint for create new post | |
@Post('/createposts') | |
createPost(@Body() createPostDto: CreatePostDto) { | |
return this.userpostsService.createPost(createPostDto); | |
} | |
//endpoint for retrieve all users | |
@Get('/getallusers') | |
findAllUsers() { | |
return this.userpostsService.findAllUsers(); | |
} | |
//endpoint for retrieve all posts | |
@Get('/getallposts') | |
findAllPosts() { | |
return this.userpostsService.findAllPosts(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment