From 8fc558d3db4c73d2d718f8b0888b3bfeab74707d Mon Sep 17 00:00:00 2001 From: koomin1227 Date: Sat, 9 Dec 2023 21:34:42 +0900 Subject: [PATCH 1/3] =?UTF-8?q?[BE]=20Feat=20:=20=EC=A0=9C=EB=AA=A9=20?= =?UTF-8?q?=EC=9E=90=EB=8F=99=EC=99=84=EC=84=B1=20API=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- BE/src/post/post.controller.ts | 7 +++++-- BE/src/post/post.service.ts | 14 ++++++++++++++ 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/BE/src/post/post.controller.ts b/BE/src/post/post.controller.ts index e284857..f5b9585 100644 --- a/BE/src/post/post.controller.ts +++ b/BE/src/post/post.controller.ts @@ -4,9 +4,7 @@ import { Get, HttpCode, HttpException, - MaxFileSizeValidator, Param, - ParseFilePipe, Patch, Post, Query, @@ -38,6 +36,11 @@ export class PostController { return posts; } + @Get('/titles') + async postsTitlesList(@Query('searchKeyword') searchKeyword) { + return await this.postService.findPostsTitles(searchKeyword); + } + @Post() @UseInterceptors(FilesInterceptor('image', 12)) async postsCreate( diff --git a/BE/src/post/post.service.ts b/BE/src/post/post.service.ts index 33950c3..e6209f3 100644 --- a/BE/src/post/post.service.ts +++ b/BE/src/post/post.service.ts @@ -249,4 +249,18 @@ export class PostService { await this.blockPostRepository.softDelete({ blocked_post: postId }); await this.postRepository.softDelete({ id: postId }); } + + async findPostsTitles(searchKeyword: string) { + const posts: PostEntity[] = await this.postRepository.find({ + where: { title: Like(`%${searchKeyword}%`) }, + order: { + create_date: 'desc', + }, + }); + const titles: string[] = posts.map((post) => post.title); + return { + titles: titles.slice(0, 5), + }; + // return titles.slice(0, 5); + } } From 5feb97b0532206b8a475264772075324c3f6681c Mon Sep 17 00:00:00 2001 From: koomin Date: Sat, 9 Dec 2023 21:38:38 +0900 Subject: [PATCH 2/3] =?UTF-8?q?[BE]=20Refactor=20:=20=EC=A3=BC=EC=84=9D?= =?UTF-8?q?=EC=A0=9C=EA=B1=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- BE/src/post/post.service.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/BE/src/post/post.service.ts b/BE/src/post/post.service.ts index e6209f3..03f591c 100644 --- a/BE/src/post/post.service.ts +++ b/BE/src/post/post.service.ts @@ -261,6 +261,5 @@ export class PostService { return { titles: titles.slice(0, 5), }; - // return titles.slice(0, 5); } } From b8b751eaf1a84aff55233dcad17771bbe88ff882 Mon Sep 17 00:00:00 2001 From: koomin1227 Date: Sat, 9 Dec 2023 23:11:56 +0900 Subject: [PATCH 3/3] =?UTF-8?q?[BE]=20Feat=20:=20=EB=B0=B0=EC=97=B4=20?= =?UTF-8?q?=ED=98=95=EC=8B=9D=EC=9C=BC=EB=A1=9C=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- BE/src/post/post.service.ts | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/BE/src/post/post.service.ts b/BE/src/post/post.service.ts index 03f591c..bf2ed12 100644 --- a/BE/src/post/post.service.ts +++ b/BE/src/post/post.service.ts @@ -223,7 +223,6 @@ export class PostService { post.end_date = createPostDto.end_date; post.user_hash = userHash; post.thumbnail = imageLocations.length > 0 ? imageLocations[0] : null; - // 이미지 추가 const res = await this.postRepository.save(post); if (res.is_request === false) { await this.createImages(imageLocations, res.id); @@ -258,8 +257,6 @@ export class PostService { }, }); const titles: string[] = posts.map((post) => post.title); - return { - titles: titles.slice(0, 5), - }; + return titles.slice(0, 5); } }