Skip to content

Commit

Permalink
[BE] Feat : GET /posts/{id} API 구현
Browse files Browse the repository at this point in the history
  • Loading branch information
namewhat99 committed Nov 20, 2023
1 parent f8d0b3c commit 91e4700
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
9 changes: 8 additions & 1 deletion BE/src/post/post.controller.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,19 @@
import { Controller, Get } from '@nestjs/common';
import { Controller, Get, Param } from '@nestjs/common';
import { PostService } from './post.service';

@Controller('post')
export class PostController {
constructor(private readonly postService: PostService) {}

@Get()
async getPosts() {
const posts = await this.postService.getPosts();
return posts;
}

@Get('/:id')
async postDetails(@Param('id') id: number) {
const post = await this.postService.findPostById(id);
return post;
}
}
15 changes: 15 additions & 0 deletions BE/src/post/post.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,19 @@ export class PostService {
// console.log(posts);
return posts;
}

async findPostById(postId: number) {
const res = await this.postRepository.findOne({ where: { id: postId } });
const post = {
title: res.title,
contents: res.contents,
price: res.price,
user_id: res.user_id,
images: res.post_images,
is_request: res.is_request,
start_date: res.start_date,
end_date: res.end_date,
};
return post;
}
}

0 comments on commit 91e4700

Please sign in to comment.