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

Feat : AI 분류 폴더 이름 리스트get api, AI 분류 링크 리스트 get api #26

Merged
merged 22 commits into from
Jul 2, 2024

Conversation

hye-on
Copy link
Collaborator

@hye-on hye-on commented Jun 29, 2024

PR 내용

  • BaseDocument 의 createdAt, updatedAt을 타입을 string에서 Date로 수정
  • AI 분류 폴더 이름 리스트 get api
  • AI 분류 링크 리스트 get api
  • postAIClassification의 keywords타입을 string으로 변경

PR 중점사항

잘 부탁드립니다

@github-actions github-actions bot added document 문서화 관련 작업 수정 및 생성 feature labels Jun 29, 2024
Comment on lines 17 to 20
@InjectModel(Folder.name) private folderModel: Model<Folder>,
@InjectModel(PostAIClassification.name)
private postAiClassificationModel: Model<PostAIClassification>,
@InjectModel(Post.name) private postModel: Model<Post>,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

이부분 나중에 repo로 빼보면 좋을 거 같당

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

오키!!

async getFolderNameList(
userId: Types.ObjectId,
): Promise<AIFolderNameServiceDto[]> {
const folders = await this.folderModel.find({ userId }).exec();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

요거 내가 folderRepo에 findByUserId라는 메소드로 만들어놨으~

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

오빠꺼 아직 머지 안되서 머지되면 수정할께!

name: string;

constructor(data: FolderDocument) {
(this.id = data._id.toString()), (this.name = data.name);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

요 부분 먼가 포매팅이 잘못 된 거 같당

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

오키!

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@@ -14,6 +14,7 @@ export class Post {

@Prop({ required: true })
title!: string;
//TODO : 사진 추가
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(˵ •̀ ᴗ - ˵ ) ✧
사진은 프론트에서 url 전달주면 opengraph로 가져오기로함! 필드 없어도 돼

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

오키!

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment on lines +26 to +27
const folders = await this.folderModel.find({ userId }).exec();
const folderIds = folders.map((folder) => folder._id);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

**(/¯◡‿◡)/¯✧·˚ : *✧·˚ : ***
이거 폴더 id만 필요한거면 folders 가져와서 map 하지말고 요렇게 하는 방법도 있네~
근데 folder schema는 필드가 많지않아서 건회가 만들어둔 findByUserId 써두 될듯~

https://www.zerocho.com/category/MongoDB/post/59bd148b1474c800194b695a
image

Suggested change
const folders = await this.folderModel.find({ userId }).exec();
const folderIds = folders.map((folder) => folder._id);
const folders = await this.folderModel.find({ userId }).select('')exec();
const folderIds = folders.map((folder) => folder._id);

Copy link
Collaborator Author

@hye-on hye-on Jul 2, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

오호 땡큐
건회오빠꺼 머지되면 만들어둔 findByUserId 써서 수정할께!

Comment on lines 29 to 39
const classifications = await this.postAiClassificationModel
.find({ suggestedFolderId: { $in: folderIds } })
.exec();

const uniqueFolderIds = [
...new Set(
classifications.map((classification) =>
classification.suggestedFolderId.toString(),
),
),
];
Copy link
Member

@JonghunAn JonghunAn Jun 29, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

˵ •̀ ᴗ - ˵ ) ✧

Suggested change
const classifications = await this.postAiClassificationModel
.find({ suggestedFolderId: { $in: folderIds } })
.exec();
const uniqueFolderIds = [
...new Set(
classifications.map((classification) =>
classification.suggestedFolderId.toString(),
),
),
];
const classifications = await this.postAiClassificationModel.distinct(folder_id).
.find({ suggestedFolderId: { $in: folderIds } })
.exec();

폴더 아이디를 중복을 제외하고 가져오고 싶으면 Set 하지말고 쿼리에서 distinct 쓰는게 맞을 것 같아~
문법은 지원하는데 저렇게 쓰는지는 한번 테스트해봐~
https://mongoosejs.com/docs/api/query.html#Query.prototype.distinct()

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

오키!

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment on lines 53 to 60
constructor(data: InputType) {
this.id = data.id;
this.title = data.title;
this.url = data.url;
this.description = data.description;
this.keywords = data.aiClassificationId.keywords;
this.createdAt = data.aiClassificationId.createdAt;
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
constructor(data: InputType) {
this.id = data.id;
this.title = data.title;
this.url = data.url;
this.description = data.description;
this.keywords = data.aiClassificationId.keywords;
this.createdAt = data.aiClassificationId.createdAt;
}
constructor(post: postSchema, ai: aiClassificationSchema ) {
this.id = post.id;
this.title = post.title;
this.url = post.url;
this.description = post.description;
this.keywords = ai.keywords;
this.createdAt = ai.aiClassificationId.createdAt;
}

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

오키

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment on lines 9 to 23
type InputType = Document<
unknown,
{},
MergeType<
Post,
{
aiClassificationId: PostAIClassification;
}
>
> &
Omit<Post, 'aiClassificationId'> & {
aiClassificationId: PostAIClassification;
} & {
_id: Types.ObjectId;
};
Copy link
Member

@JonghunAn JonghunAn Jun 29, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(˵ •̀ ᴗ - ˵ ) ✧
요건 serviceDto에서 constructor에서 paramter 받을때 도메인 스키마별로 받으면 필요없음!

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment on lines 63 to 71
export class AIPostListResponse {
@ApiProperty({ type: [AIPostServiceDto] })
@Type(() => AIPostServiceDto)
list: AIPostServiceDto[];

constructor(data: AIPostServiceDto[]) {
this.list = data;
}
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(˵ •̀ ᴗ - ˵ ) ✧
ResponseDto는 /classification/response 아래에 별도 클래스 파일로 분리해줘~

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

return matchedFolders.map((folder) => new AIFolderNameServiceDto(folder));
}

async getPostList(folderId: string): Promise<AIPostServiceDto[]> {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

혜온아 이부분도 @GetUser로 사용자 ID 가져와서 사용자 분기도 같이 해줘야할것 같아!

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment on lines 6 to 8
@ApiProperty({ description: '폴더 id' })
@IsNotEmpty()
@IsString()
Copy link
Collaborator

@Marades Marades Jun 29, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(˵ •̀ ᴗ - ˵ ) ✧
service dto라서 요 데코레이터들도 빼도 될 거 같아!

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

서비스 dto에서 스웨거 관련 데코레이터도 제거해?
스웨거에서 스키마 볼 때 필요하지 않나해서

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

import { AIPostListResponse } from './dto/getAIPostList.dto';
import { AIFolderNameListResponse } from './dto/getAIFolderNameLIst.dto';

@Controller('ai')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
@Controller('ai')
@Controller('classification')

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.


@Schema({
collection: 'post_ai_classifications',
timestamps: true,
versionKey: false,
})
export class PostAIClassification {
export class PostAIClassification extends BaseDocument {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
export class PostAIClassification extends BaseDocument {
export class AIClassification extends BaseDocument {

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Collaborator

@J-Hoplin J-Hoplin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

수고했어!!👍

@hye-on hye-on merged commit 2a4cbfa into development Jul 2, 2024
1 check failed
@J-Hoplin J-Hoplin deleted the feature/ai-domain branch July 3, 2024 15:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
document 문서화 관련 작업 수정 및 생성 feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants