-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'development' into feat/folder-list-api
- Loading branch information
Showing
31 changed files
with
1,541 additions
and
897 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
# compiled output | ||
/dist | ||
/worker-dist | ||
/node_modules | ||
|
||
# Logs | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import { Context, Handler } from 'aws-lambda'; | ||
import { NestFactory } from '@nestjs/core'; | ||
import { AiModule } from '@src/infrastructure/ai/ai.module'; | ||
import { AiService } from '@src/infrastructure/ai/ai.service'; | ||
|
||
export const handler: Handler = async (event: any) => { | ||
const data = JSON.parse(event.body); | ||
// event 데이터 잘 들어오는지 확인용 | ||
console.log(data); | ||
const app = await NestFactory.create(AiModule); | ||
const aiService = app.get(AiService); | ||
|
||
// NOTE: AI 요약 요청 | ||
const summarizeUrlContent = await aiService.summarizeLinkContent( | ||
data.postContent, | ||
data.folderList, | ||
); | ||
|
||
if (summarizeUrlContent.success === true) { | ||
return true; | ||
// TODO create row PostAIClassification | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import { Module } from '@nestjs/common'; | ||
import { AwsLambdaService } from './aws-lambda.service'; | ||
|
||
@Module({ | ||
providers: [AwsLambdaService], | ||
exports: [AwsLambdaService], | ||
}) | ||
export class AwsLambdaModule {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import { Injectable } from '@nestjs/common'; | ||
import { InvokeCommand, LambdaClient } from '@aws-sdk/client-lambda'; | ||
import { ConfigService } from '@nestjs/config'; | ||
@Injectable() | ||
export class AwsLambdaService { | ||
constructor(private readonly config: ConfigService) {} | ||
// TODO credentials 추가 필요 (acccess_key, secret_key) | ||
readonly client = new LambdaClient({ | ||
region: 'ap-northeast-2', | ||
credentials: { | ||
accessKeyId: this.config.get<string>('AWS_ACCESS_KEY'), | ||
secretAccessKey: this.config.get<string>('AWS_SECRET_KEY'), | ||
}, | ||
}); | ||
|
||
invoke_lambda(lambdaFunctionName: string, payload: object): void { | ||
const command = new InvokeCommand({ | ||
FunctionName: lambdaFunctionName, | ||
InvocationType: 'Event', | ||
Payload: JSON.stringify(payload), | ||
}); | ||
this.client.send(command); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
export class BaseDocument { | ||
createdAt: string; | ||
createdAt: Date; | ||
|
||
updatedAt: string; | ||
updatedAt: Date; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import { Controller, Get, UseGuards, Param } from '@nestjs/common'; | ||
import { ClassificationService } from './classification.service'; | ||
import { GetUser } from '@src/common'; | ||
import { | ||
ClassificationControllerDocs, | ||
GetAIFolderNameListDocs, | ||
GetAIPostListDocs, | ||
} from './docs'; | ||
import { JwtGuard } from '../users/guards'; | ||
import { AIFolderNameListResponse } from './response/ai-folder-list.dto'; | ||
import { AIPostListResponse } from './response/ai-post-list.dto'; | ||
|
||
@Controller('classification') | ||
@UseGuards(JwtGuard) | ||
@ClassificationControllerDocs | ||
export class ClassificationController { | ||
constructor(private readonly classificationService: ClassificationService) {} | ||
|
||
@Get('/suggestions') //TODO : 정렬 | ||
@GetAIFolderNameListDocs | ||
async getSuggestedFolderNameList(@GetUser() userId: String) { | ||
const folderNames = | ||
await this.classificationService.getFolderNameList(userId); | ||
|
||
return new AIFolderNameListResponse(folderNames); | ||
} | ||
|
||
@Get('/suggestions/:folderId') | ||
@GetAIPostListDocs | ||
async getSuggestedPostList( | ||
@GetUser() userId: string, | ||
@Param('folderId') folderId: string, | ||
) { | ||
const posts = await this.classificationService.getPostList( | ||
userId, | ||
folderId, | ||
); | ||
|
||
return new AIPostListResponse(posts); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import { Module } from '@nestjs/common'; | ||
import { ClassificationService } from './classification.service'; | ||
import { MongooseModule } from '@nestjs/mongoose'; | ||
import { | ||
Folder, | ||
FolderSchema, | ||
Post, | ||
AIClassification, | ||
PostAIClassificationSchema, | ||
PostSchema, | ||
} from '@src/infrastructure/database/schema'; | ||
|
||
import { ClassificationController } from './classification.controller'; | ||
|
||
@Module({ | ||
imports: [ | ||
MongooseModule.forFeature([ | ||
{ name: Folder.name, schema: FolderSchema }, | ||
{ name: AIClassification.name, schema: PostAIClassificationSchema }, | ||
{ name: Post.name, schema: PostSchema }, | ||
]), | ||
], | ||
controllers: [ClassificationController], | ||
providers: [ClassificationService], | ||
}) | ||
export class ClassificationModule {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import { Test, TestingModule } from '@nestjs/testing'; | ||
import { ClassificationService } from './classification.service'; | ||
|
||
describe('ClassificationService', () => { | ||
let service: ClassificationService; | ||
|
||
beforeEach(async () => { | ||
const module: TestingModule = await Test.createTestingModule({ | ||
providers: [ClassificationService], | ||
}).compile(); | ||
|
||
service = module.get<ClassificationService>(ClassificationService); | ||
}); | ||
|
||
it('should be defined', () => { | ||
expect(service).toBeDefined(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import { Injectable } from '@nestjs/common'; | ||
import { | ||
Folder, | ||
Post, | ||
AIClassification, | ||
} from '@src/infrastructure/database/schema'; | ||
|
||
import { InjectModel } from '@nestjs/mongoose'; | ||
import { Model, Types } from 'mongoose'; | ||
import { AIFolderNameServiceDto } from './dto/getAIFolderNameLIst.dto'; | ||
import { AIPostServiceDto } from './dto/getAIPostList.dto'; | ||
|
||
@Injectable() | ||
export class ClassificationService { | ||
constructor( | ||
@InjectModel(Folder.name) private folderModel: Model<Folder>, | ||
@InjectModel(AIClassification.name) | ||
private postAiClassificationModel: Model<AIClassification>, | ||
@InjectModel(Post.name) private postModel: Model<Post>, | ||
) {} | ||
|
||
async getFolderNameList(userId: String): Promise<AIFolderNameServiceDto[]> { | ||
const folders = await this.folderModel.find({ userId }).exec(); | ||
const folderIds = folders.map((folder) => folder._id); | ||
|
||
const classificationIds = await this.postAiClassificationModel | ||
.distinct('suggestedFolderId') | ||
.where('suggestedFolderId') | ||
.in(folderIds) | ||
.exec(); | ||
|
||
const matchedFolders = await this.folderModel | ||
.find({ _id: { $in: classificationIds } }) | ||
.exec(); | ||
|
||
return matchedFolders.map((folder) => new AIFolderNameServiceDto(folder)); | ||
} | ||
|
||
async getPostList( | ||
userId: string, | ||
folderId: string, | ||
): Promise<AIPostServiceDto[]> { | ||
const posts = await this.postModel | ||
.find({ userId: userId }) | ||
.populate<{ | ||
aiClassificationId: AIClassification; | ||
}>({ | ||
path: 'aiClassificationId', | ||
match: { deletedAt: null, suggestedFolderId: folderId }, | ||
}) | ||
.sort({ createdAt: -1 }) | ||
.exec(); | ||
|
||
return posts | ||
.filter((post) => post.aiClassificationId) | ||
.map((post) => new AIPostServiceDto(post, post.aiClassificationId)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import { applyDecorators } from '@nestjs/common'; | ||
import { ApiTags } from '@nestjs/swagger'; | ||
|
||
export const ClassificationControllerDocs = applyDecorators( | ||
ApiTags('AI classification API'), | ||
); |
14 changes: 14 additions & 0 deletions
14
src/modules/classification/docs/getAIFolderNameList.docs.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import { applyDecorators } from '@nestjs/common'; | ||
import { ApiBearerAuth, ApiOperation, ApiResponse } from '@nestjs/swagger'; | ||
import { AIFolderNameListResponse } from '../response/ai-folder-list.dto'; | ||
|
||
export const GetAIFolderNameListDocs = applyDecorators( | ||
ApiOperation({ | ||
summary: '폴더 리스트', | ||
description: 'AI 분류 폴더 리스트.', | ||
}), | ||
ApiResponse({ | ||
type: AIFolderNameListResponse, | ||
}), | ||
ApiBearerAuth(), | ||
); |
Oops, something went wrong.