-
Notifications
You must be signed in to change notification settings - Fork 0
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
Conversation
@InjectModel(Folder.name) private folderModel: Model<Folder>, | ||
@InjectModel(PostAIClassification.name) | ||
private postAiClassificationModel: Model<PostAIClassification>, | ||
@InjectModel(Post.name) private postModel: Model<Post>, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
이부분 나중에 repo로 빼보면 좋을 거 같당
There was a problem hiding this comment.
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(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
요거 내가 folderRepo에 findByUserId라는 메소드로 만들어놨으~
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
요 부분 먼가 포매팅이 잘못 된 거 같당
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
오키!
There was a problem hiding this comment.
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 : 사진 추가 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(˵ •̀ ᴗ - ˵ ) ✧
사진은 프론트에서 url 전달주면 opengraph로 가져오기로함! 필드 없어도 돼
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
오키!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
const folders = await this.folderModel.find({ userId }).exec(); | ||
const folderIds = folders.map((folder) => folder._id); |
There was a problem hiding this comment.
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
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); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
오호 땡큐
건회오빠꺼 머지되면 만들어둔 findByUserId 써서 수정할께!
const classifications = await this.postAiClassificationModel | ||
.find({ suggestedFolderId: { $in: folderIds } }) | ||
.exec(); | ||
|
||
const uniqueFolderIds = [ | ||
...new Set( | ||
classifications.map((classification) => | ||
classification.suggestedFolderId.toString(), | ||
), | ||
), | ||
]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
˵ •̀ ᴗ - ˵ ) ✧
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()
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
오키!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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; | |
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
오키
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
type InputType = Document< | ||
unknown, | ||
{}, | ||
MergeType< | ||
Post, | ||
{ | ||
aiClassificationId: PostAIClassification; | ||
} | ||
> | ||
> & | ||
Omit<Post, 'aiClassificationId'> & { | ||
aiClassificationId: PostAIClassification; | ||
} & { | ||
_id: Types.ObjectId; | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(˵ •̀ ᴗ - ˵ ) ✧
요건 serviceDto에서 constructor에서 paramter 받을때 도메인 스키마별로 받으면 필요없음!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
export class AIPostListResponse { | ||
@ApiProperty({ type: [AIPostServiceDto] }) | ||
@Type(() => AIPostServiceDto) | ||
list: AIPostServiceDto[]; | ||
|
||
constructor(data: AIPostServiceDto[]) { | ||
this.list = data; | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(˵ •̀ ᴗ - ˵ ) ✧
ResponseDto는 /classification/response
아래에 별도 클래스 파일로 분리해줘~
There was a problem hiding this comment.
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[]> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
혜온아 이부분도 @GetUser
로 사용자 ID 가져와서 사용자 분기도 같이 해줘야할것 같아!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ApiProperty({ description: '폴더 id' }) | ||
@IsNotEmpty() | ||
@IsString() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(˵ •̀ ᴗ - ˵ ) ✧
service dto라서 요 데코레이터들도 빼도 될 거 같아!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
서비스 dto에서 스웨거 관련 데코레이터도 제거해?
스웨거에서 스키마 볼 때 필요하지 않나해서
There was a problem hiding this comment.
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') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Controller('ai') | |
@Controller('classification') |
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
export class PostAIClassification extends BaseDocument { | |
export class AIClassification extends BaseDocument { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
수고했어!!👍
PR 내용
PR 중점사항
잘 부탁드립니다