Skip to content

Commit

Permalink
Merge pull request #75 from mash-up-kr/refactor/post
Browse files Browse the repository at this point in the history
ํ”ผ๋“œ ์กฐํšŒ ์‹œ ๋ˆ„๋ฝ๋œ ์Šคํ‚ค๋งˆ ์ถ”๊ฐ€ ๋ฐ swagger ๋ฐ์ฝ”๋ ˆ์ดํ„ฐ ์ถ”๊ฐ€
  • Loading branch information
JonghunAn authored Jul 20, 2024
2 parents 3223295 + 80c2d56 commit 35c5b54
Show file tree
Hide file tree
Showing 8 changed files with 85 additions and 56 deletions.
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

0 comments on commit 35c5b54

Please sign in to comment.