From b74809e705f1e46d22a11f11208535b7f3403ec5 Mon Sep 17 00:00:00 2001 From: Anjonghun <58875626+JonghunAn@users.noreply.github.com> Date: Sun, 21 Jul 2024 01:27:38 +0900 Subject: [PATCH 1/9] refactor: add aiStatus, thumbnailImgUrl in ai post --- src/modules/posts/posts.repository.ts | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/modules/posts/posts.repository.ts b/src/modules/posts/posts.repository.ts index af88d30..0e63bf6 100644 --- a/src/modules/posts/posts.repository.ts +++ b/src/modules/posts/posts.repository.ts @@ -4,10 +4,7 @@ import { OrderType } from '@src/common'; import { AIClassification, Post, PostDocument } from '@src/infrastructure'; import { PostAiStatus } from '@src/modules/posts/posts.constant'; import { FilterQuery, Model, Types } from 'mongoose'; -import { - ClassificationPostList, - PostListInClassificationFolder, -} from '../classification/dto/classification.dto'; +import { ClassificationPostList } from '../classification/dto/classification.dto'; import { P001 } from './error'; import { PostUpdateableFields } from './type/type'; @@ -142,7 +139,7 @@ export class PostsRepository { suggestedFolderId: Types.ObjectId, offset: number, limit: number, - ): Promise { + ): Promise { return await this.postModel .aggregate([ { @@ -186,6 +183,8 @@ export class PostsRepository { description: 1, createdAt: 1, readAt: 1, + aiStatus: 1, + thumbnailImgUrl: 1, keywords: '$aiClassification.keywords', }, }, @@ -303,6 +302,8 @@ export class PostsRepository { description: 1, createdAt: 1, readAt: 1, + aiStatus: 1, + thumbnailImgUrl: 1, keywords: '$aiClassification.keywords', }, }, From f8dae073e4d0ec3646320dd4766c611f391155e9 Mon Sep 17 00:00:00 2001 From: Anjonghun <58875626+JonghunAn@users.noreply.github.com> Date: Sun, 21 Jul 2024 01:28:13 +0900 Subject: [PATCH 2/9] refactor: erase unused import --- src/modules/folders/responses/post-list-in-folder.response.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/modules/folders/responses/post-list-in-folder.response.ts b/src/modules/folders/responses/post-list-in-folder.response.ts index 1765ed3..7560310 100644 --- a/src/modules/folders/responses/post-list-in-folder.response.ts +++ b/src/modules/folders/responses/post-list-in-folder.response.ts @@ -1,4 +1,6 @@ import { ApiProperty } from '@nestjs/swagger'; +import { PostResponse } from './post.response'; +import { PostDocument } from '@src/infrastructure'; import { PaginationMetadata } from '@src/common'; import { PostResponse } from './post.response'; From 3916f2309d0e43263803e84ab9e8032a7ee9b9b0 Mon Sep 17 00:00:00 2001 From: Anjonghun <58875626+JonghunAn@users.noreply.github.com> Date: Sun, 21 Jul 2024 01:36:19 +0900 Subject: [PATCH 3/9] refactor: erase unused interface --- .../classification/dto/classification.dto.ts | 18 ------------------ .../response/ai-post-list.dto.ts | 17 +++++++---------- 2 files changed, 7 insertions(+), 28 deletions(-) diff --git a/src/modules/classification/dto/classification.dto.ts b/src/modules/classification/dto/classification.dto.ts index d747bbe..9345022 100644 --- a/src/modules/classification/dto/classification.dto.ts +++ b/src/modules/classification/dto/classification.dto.ts @@ -25,24 +25,6 @@ export interface PostListInClassificationFolder { readAt: Date; } -export interface ClassificationPostList { - postId: string; - - folderId: string; - - title: string; - - url: string; - - description: string; - - keywords: string[]; - - createdAt: Date; - - readAt: Date; -} - export class UpdateAIClassificationDto { @IsNotEmpty() @IsMongoId() diff --git a/src/modules/classification/response/ai-post-list.dto.ts b/src/modules/classification/response/ai-post-list.dto.ts index 7d7adf9..6ef7ec1 100644 --- a/src/modules/classification/response/ai-post-list.dto.ts +++ b/src/modules/classification/response/ai-post-list.dto.ts @@ -1,9 +1,5 @@ import { ApiProperty } from '@nestjs/swagger'; -import { Type } from 'class-transformer'; -import { - ClassificationPostList, - PostListInClassificationFolder, -} from '../dto/classification.dto'; +import { ClassificationPostList } from '../dto/classification.dto'; import { PaginationMetadata } from '@src/common'; export class AIPostListResponse { @@ -12,14 +8,15 @@ export class AIPostListResponse { }) metadata: PaginationMetadata; - @ApiProperty() - list: PostListInClassificationFolder[] | ClassificationPostList[]; + @ApiProperty({ + type: ClassificationPostList, + isArray: true, + }) + list: ClassificationPostList[]; constructor( metaData: PaginationMetadata, - classificationPostList: - | PostListInClassificationFolder[] - | ClassificationPostList[], + classificationPostList: ClassificationPostList[], ) { this.metadata = metaData; this.list = classificationPostList; From 068f1c48d8b182e47f065e3306714c247249de62 Mon Sep 17 00:00:00 2001 From: Anjonghun <58875626+JonghunAn@users.noreply.github.com> Date: Sun, 21 Jul 2024 01:40:06 +0900 Subject: [PATCH 4/9] refactor: swagger definition --- .../classification/dto/classification.dto.ts | 28 +++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/src/modules/classification/dto/classification.dto.ts b/src/modules/classification/dto/classification.dto.ts index 9345022..9a4ad3a 100644 --- a/src/modules/classification/dto/classification.dto.ts +++ b/src/modules/classification/dto/classification.dto.ts @@ -1,5 +1,6 @@ import { ApiProperty } from '@nestjs/swagger'; import { IsMongoId, IsNotEmpty } from 'class-validator'; +import { PostAiStatus } from '@src/modules/posts/posts.constant'; export interface ClassificationFolderWithCount { folderId: string; @@ -7,22 +8,45 @@ export interface ClassificationFolderWithCount { postCount: number; } -export interface PostListInClassificationFolder { +export class ClassificationPostList { + @ApiProperty({ required: true, description: '피드 id', type: String }) postId: string; + @ApiProperty({ required: true, description: '폴더 id', type: String }) folderId: string; + @ApiProperty({ required: true, description: '피드 제목', type: String }) title: string; + @ApiProperty({ required: true, description: '피드 URL', type: String }) url: string; + @ApiProperty({ required: true, description: '피드 요약', type: String }) description: string; + @ApiProperty({ + required: true, + description: '키워드', + isArray: true, + type: String, + }) keywords: string[]; + @ApiProperty({ + required: true, + description: 'ai 요약 상태', + enum: PostAiStatus, + }) + aiStatus: PostAiStatus; + + @ApiProperty({ required: false, description: '피드 og 이미지', type: String }) + thumbnailImgUrl: string | null; + + @ApiProperty({ required: false, description: '생성 시간', type: Date }) createdAt: Date; - readAt: Date; + @ApiProperty({ required: false, description: '읽은 시간', type: Date }) + readAt: Date | null; } export class UpdateAIClassificationDto { From 7a707c214339816d434ec4eec830e7c1cef7e763 Mon Sep 17 00:00:00 2001 From: Anjonghun <58875626+JonghunAn@users.noreply.github.com> Date: Sun, 21 Jul 2024 01:48:50 +0900 Subject: [PATCH 5/9] refactor: file-name renaming --- ...{post-list-in-folder.response.ts => folder-post.response.ts} | 2 -- src/modules/folders/responses/index.ts | 2 +- 2 files changed, 1 insertion(+), 3 deletions(-) rename src/modules/folders/responses/{post-list-in-folder.response.ts => folder-post.response.ts} (82%) diff --git a/src/modules/folders/responses/post-list-in-folder.response.ts b/src/modules/folders/responses/folder-post.response.ts similarity index 82% rename from src/modules/folders/responses/post-list-in-folder.response.ts rename to src/modules/folders/responses/folder-post.response.ts index 7560310..50afffd 100644 --- a/src/modules/folders/responses/post-list-in-folder.response.ts +++ b/src/modules/folders/responses/folder-post.response.ts @@ -1,8 +1,6 @@ import { ApiProperty } from '@nestjs/swagger'; import { PostResponse } from './post.response'; -import { PostDocument } from '@src/infrastructure'; import { PaginationMetadata } from '@src/common'; -import { PostResponse } from './post.response'; export class FolderPostResponse { @ApiProperty({ diff --git a/src/modules/folders/responses/index.ts b/src/modules/folders/responses/index.ts index 2e613e1..af0d5a7 100644 --- a/src/modules/folders/responses/index.ts +++ b/src/modules/folders/responses/index.ts @@ -1,4 +1,4 @@ export * from './folder.response'; export * from './folder-list.response'; -export * from './post-list-in-folder.response'; +export * from './folder-post.response'; export * from './folder-summary.response'; From 93b0f2dab04a6142b00697b48603be69bcd75f56 Mon Sep 17 00:00:00 2001 From: Anjonghun <58875626+JonghunAn@users.noreply.github.com> Date: Sun, 21 Jul 2024 02:08:14 +0900 Subject: [PATCH 6/9] refactor: add createdAt in get postList --- src/modules/posts/response/listPost.response.ts | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/modules/posts/response/listPost.response.ts b/src/modules/posts/response/listPost.response.ts index 8f77a7e..9ca3a94 100644 --- a/src/modules/posts/response/listPost.response.ts +++ b/src/modules/posts/response/listPost.response.ts @@ -23,10 +23,11 @@ export class ListPostItem { @ApiProperty() isFavorite: boolean; - @ApiProperty({ - required: false, - }) - readAt: Date; + @ApiProperty({ required: true, description: '생성 시간', type: Date }) + createdAt: Date; + + @ApiProperty({ required: false, description: '읽음 시간' }) + readAt: Date | null; @ApiProperty({ required: false, description: 'URL og 이미지' }) thumbnailImgUrl: string; @@ -45,6 +46,7 @@ export class ListPostItem { this.title = data.title; this.description = data.description; this.isFavorite = data.isFavorite; + this.createdAt = data.createdAt; this.readAt = data.readAt; this.thumbnailImgUrl = data.thumbnailImgUrl; this.aiStatus = data.aiStatus; From 97319278b38deca1ea88a8b94f1df76e05593870 Mon Sep 17 00:00:00 2001 From: Anjonghun <58875626+JonghunAn@users.noreply.github.com> Date: Sun, 21 Jul 2024 02:08:44 +0900 Subject: [PATCH 7/9] feat: define swagger --- src/modules/posts/response/listPost.response.ts | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/modules/posts/response/listPost.response.ts b/src/modules/posts/response/listPost.response.ts index 9ca3a94..ba006c7 100644 --- a/src/modules/posts/response/listPost.response.ts +++ b/src/modules/posts/response/listPost.response.ts @@ -8,19 +8,19 @@ export class ListPostItem { @ApiProperty() id: string; - @ApiProperty() + @ApiProperty({ required: true, description: '폴더 id', type: String }) folderId: string; - @ApiProperty() + @ApiProperty({ required: true, description: '피드 URL', type: String }) url: string; - @ApiProperty() + @ApiProperty({ required: true, description: '피드 제목', type: String }) title: string; - @ApiProperty() + @ApiProperty({ required: false, description: '요약 정보', type: String }) description: string; - @ApiProperty() + @ApiProperty({ required: true, description: '즐겨찾기 여부', type: Boolean }) isFavorite: boolean; @ApiProperty({ required: true, description: '생성 시간', type: Date }) @@ -30,7 +30,7 @@ export class ListPostItem { readAt: Date | null; @ApiProperty({ required: false, description: 'URL og 이미지' }) - thumbnailImgUrl: string; + thumbnailImgUrl: string | null; @ApiProperty({ required: true, From 729391e12a75c49b1855b7a88adcc7520224e3ec Mon Sep 17 00:00:00 2001 From: Anjonghun <58875626+JonghunAn@users.noreply.github.com> Date: Sun, 21 Jul 2024 02:34:23 +0900 Subject: [PATCH 8/9] feat: define schema swagger --- .../classification/dto/classification.dto.ts | 6 ++-- .../folders/responses/post.response.ts | 35 ++++++++++++++----- .../posts/response/listPost.response.ts | 12 ++++--- 3 files changed, 37 insertions(+), 16 deletions(-) diff --git a/src/modules/classification/dto/classification.dto.ts b/src/modules/classification/dto/classification.dto.ts index 9a4ad3a..26e03eb 100644 --- a/src/modules/classification/dto/classification.dto.ts +++ b/src/modules/classification/dto/classification.dto.ts @@ -39,13 +39,13 @@ export class ClassificationPostList { }) aiStatus: PostAiStatus; - @ApiProperty({ required: false, description: '피드 og 이미지', type: String }) + @ApiProperty({ nullable: true, description: '피드 og 이미지', type: String }) thumbnailImgUrl: string | null; - @ApiProperty({ required: false, description: '생성 시간', type: Date }) + @ApiProperty({ description: '생성 시간', type: Date }) createdAt: Date; - @ApiProperty({ required: false, description: '읽은 시간', type: Date }) + @ApiProperty({ nullable: true, description: '읽은 시간', type: Date }) readAt: Date | null; } diff --git a/src/modules/folders/responses/post.response.ts b/src/modules/folders/responses/post.response.ts index 058d140..9c22acc 100644 --- a/src/modules/folders/responses/post.response.ts +++ b/src/modules/folders/responses/post.response.ts @@ -1,5 +1,6 @@ import { ApiProperty } from '@nestjs/swagger'; import { PostDocument } from '@src/infrastructure'; +import { PostAiStatus } from '@src/modules/posts/posts.constant'; /** * @todo @@ -18,36 +19,50 @@ class Keyword { * 추후 post module로 이동 예정 */ export class PostResponse { - @ApiProperty() + @ApiProperty({ required: true, description: '피드 id', type: String }) id: string; - @ApiProperty() + @ApiProperty({ required: true, description: '유저 id', type: String }) userId: string; - @ApiProperty() + @ApiProperty({ required: true, description: '폴더 id', type: String }) folderId: string; - @ApiProperty() + @ApiProperty({ required: true, description: '피드 URL', type: String }) url: string; - @ApiProperty() + @ApiProperty({ required: true, description: '피드 제목', type: String }) title: string; - @ApiProperty({ nullable: true }) + @ApiProperty({ + nullable: true, + description: '요약 정보', + type: String, + }) description: string; - @ApiProperty() + @ApiProperty({ description: '즐겨찾기 여부' }) isFavorite: boolean; - @ApiProperty() + @ApiProperty({ nullable: true, description: '읽은 시간' }) readAt: Date; - @ApiProperty() + @ApiProperty({ description: '생성 시간' }) createdAt: Date; @ApiProperty({ type: Keyword, isArray: true }) keywords: Keyword[]; + @ApiProperty({ nullable: true, description: 'URL og 이미지' }) + thumbnailImgUrl: string | null; + + @ApiProperty({ + required: true, + enum: PostAiStatus, + description: '피드 게시글의 ai 진행 상태', + }) + aiStatus: PostAiStatus; + constructor(data: PostDocument) { this.id = data._id.toString(); this.userId = data.userId.toString(); @@ -58,5 +73,7 @@ export class PostResponse { this.isFavorite = data.isFavorite; this.readAt = data.readAt; this.createdAt = data.createdAt; + this.thumbnailImgUrl = data.thumbnailImgUrl; + this.aiStatus = data.aiStatus; } } diff --git a/src/modules/posts/response/listPost.response.ts b/src/modules/posts/response/listPost.response.ts index ba006c7..f5fa6fd 100644 --- a/src/modules/posts/response/listPost.response.ts +++ b/src/modules/posts/response/listPost.response.ts @@ -5,7 +5,7 @@ import { Types } from 'mongoose'; import { PostAiStatus } from '@src/modules/posts/posts.constant'; export class ListPostItem { - @ApiProperty() + @ApiProperty({ required: true, description: '피드 id', type: String }) id: string; @ApiProperty({ required: true, description: '폴더 id', type: String }) @@ -17,7 +17,11 @@ export class ListPostItem { @ApiProperty({ required: true, description: '피드 제목', type: String }) title: string; - @ApiProperty({ required: false, description: '요약 정보', type: String }) + @ApiProperty({ + nullable: true, + description: '요약 정보', + type: String, + }) description: string; @ApiProperty({ required: true, description: '즐겨찾기 여부', type: Boolean }) @@ -26,10 +30,10 @@ export class ListPostItem { @ApiProperty({ required: true, description: '생성 시간', type: Date }) createdAt: Date; - @ApiProperty({ required: false, description: '읽음 시간' }) + @ApiProperty({ nullable: true, description: '읽음 시간' }) readAt: Date | null; - @ApiProperty({ required: false, description: 'URL og 이미지' }) + @ApiProperty({ nullable: true, description: 'URL og 이미지' }) thumbnailImgUrl: string | null; @ApiProperty({ From 80c2d56e19f62c328958e68bdffb2f08378ecb00 Mon Sep 17 00:00:00 2001 From: Anjonghun <58875626+JonghunAn@users.noreply.github.com> Date: Sun, 21 Jul 2024 02:34:39 +0900 Subject: [PATCH 9/9] refactor: comment to repository method --- src/modules/posts/posts.service.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/modules/posts/posts.service.ts b/src/modules/posts/posts.service.ts index 68a4215..04c5f52 100644 --- a/src/modules/posts/posts.service.ts +++ b/src/modules/posts/posts.service.ts @@ -88,6 +88,7 @@ export class PostsService { folderId: string, query: GetPostQueryDto, ) { + // NOTE: 폴더 존재 여부조회 await this.folderRepository.findOneOrFail({ _id: folderId, userId, @@ -98,6 +99,7 @@ export class PostsService { folderId, query.isRead, ); + // NOTE: 폴더 id에 속하는 post 리스트 조회 const posts = await this.postRepository.findByFolderId( folderId, offset,