Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

피드 조회 시 누락된 스키마 추가 및 swagger 데코레이터 추가 #75

Merged
merged 9 commits into from
Jul 20, 2024
42 changes: 24 additions & 18 deletions src/modules/classification/dto/classification.dto.ts
Original file line number Diff line number Diff line change
@@ -1,46 +1,52 @@
import { ApiProperty } from '@nestjs/swagger';
import { IsMongoId, IsNotEmpty } from 'class-validator';
import { PostAiStatus } from '@src/modules/posts/posts.constant';

export interface ClassificationFolderWithCount {
folderId: string;
folderName: string;
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[];

createdAt: Date;

readAt: Date;
}

export interface ClassificationPostList {
postId: string;

folderId: string;
@ApiProperty({
required: true,
description: 'ai 요약 상태',
enum: PostAiStatus,
})
aiStatus: PostAiStatus;

title: string;

url: string;

description: string;

keywords: string[];
@ApiProperty({ nullable: true, description: '피드 og 이미지', type: String })
thumbnailImgUrl: string | null;

@ApiProperty({ description: '생성 시간', type: Date })
createdAt: Date;

readAt: Date;
@ApiProperty({ nullable: true, description: '읽은 시간', type: Date })
readAt: Date | null;
}

export class UpdateAIClassificationDto {
Expand Down
17 changes: 7 additions & 10 deletions src/modules/classification/response/ai-post-list.dto.ts
Original file line number Diff line number Diff line change
@@ -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 {
Expand All @@ -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;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { ApiProperty } from '@nestjs/swagger';
import { PaginationMetadata } from '@src/common';
import { PostResponse } from './post.response';
import { PaginationMetadata } from '@src/common';

export class FolderPostResponse {
@ApiProperty({
Expand Down
2 changes: 1 addition & 1 deletion src/modules/folders/responses/index.ts
Original file line number Diff line number Diff line change
@@ -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';
35 changes: 26 additions & 9 deletions src/modules/folders/responses/post.response.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { ApiProperty } from '@nestjs/swagger';
import { PostDocument } from '@src/infrastructure';
import { PostAiStatus } from '@src/modules/posts/posts.constant';

/**
* @todo
Expand All @@ -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();
Expand All @@ -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;
}
}
11 changes: 6 additions & 5 deletions src/modules/posts/posts.repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down Expand Up @@ -142,7 +139,7 @@ export class PostsRepository {
suggestedFolderId: Types.ObjectId,
offset: number,
limit: number,
): Promise<PostListInClassificationFolder[]> {
): Promise<ClassificationPostList[]> {
return await this.postModel
.aggregate([
{
Expand Down Expand Up @@ -186,6 +183,8 @@ export class PostsRepository {
description: 1,
createdAt: 1,
readAt: 1,
aiStatus: 1,
thumbnailImgUrl: 1,
keywords: '$aiClassification.keywords',
},
},
Expand Down Expand Up @@ -303,6 +302,8 @@ export class PostsRepository {
description: 1,
createdAt: 1,
readAt: 1,
aiStatus: 1,
thumbnailImgUrl: 1,
keywords: '$aiClassification.keywords',
},
},
Expand Down
2 changes: 2 additions & 0 deletions src/modules/posts/posts.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ export class PostsService {
folderId: string,
query: GetPostQueryDto,
) {
// NOTE: 폴더 존재 여부조회
await this.folderRepository.findOneOrFail({
_id: folderId,
userId,
Expand All @@ -98,6 +99,7 @@ export class PostsService {
folderId,
query.isRead,
);
// NOTE: 폴더 id에 속하는 post 리스트 조회
const posts = await this.postRepository.findByFolderId(
folderId,
offset,
Expand Down
30 changes: 18 additions & 12 deletions src/modules/posts/response/listPost.response.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,31 +5,36 @@ 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()
@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({
nullable: true,
description: '요약 정보',
type: String,
})
description: string;

@ApiProperty()
@ApiProperty({ required: true, description: '즐겨찾기 여부', type: Boolean })
isFavorite: boolean;

@ApiProperty({
required: false,
})
readAt: Date;
@ApiProperty({ required: true, description: '생성 시간', type: Date })
createdAt: Date;

@ApiProperty({ nullable: true, description: '읽음 시간' })
readAt: Date | null;

@ApiProperty({ required: false, description: 'URL og 이미지' })
thumbnailImgUrl: string;
@ApiProperty({ nullable: true, description: 'URL og 이미지' })
thumbnailImgUrl: string | null;

@ApiProperty({
required: true,
Expand All @@ -45,6 +50,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;
Expand Down