From ffae65d01b3b1709631475c03510cd5d19b53f44 Mon Sep 17 00:00:00 2001 From: blaxsior Date: Tue, 14 Nov 2023 22:27:37 +0900 Subject: [PATCH] =?UTF-8?q?feat:=20analysiscomment(=EB=B6=84=EC=84=9D?= =?UTF-8?q?=EB=90=9C=20=EB=8C=93=EA=B8=80=20=EB=AA=A9=EB=A1=9D)=EC=97=90?= =?UTF-8?q?=20big=5Femotion=20=EC=86=8D=EC=84=B1=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 프론트엔드 측에서 감정 대분류(긍정, 중립, 부정)가 필요해 big_emotion이라는 이름으로 속성을 추가 - mysql에서 속성을 추가, 쿼리를 이용하여 big_emotion에 값을 채움 - issue: 객체 내 클래스 배열에 대해 serialize가 적용되지 않아 임시로 serialize을 주석 처리 - search/search.controller.ts -> getKeywordWithTopComments() --- .../analysis-comment.controller.spec.ts | 1 + .../analysis-comment.service.ts | 24 +++++++++++++++---- .../dtos/create-comment.dto.ts | 9 ++++++- .../dtos/get-comments-query.dto.ts | 2 +- .../entity/analysis-comment.entity.ts | 12 +++++++--- .../dtos/keyword-with-top-comments.dto.ts | 15 ++++++------ .../server/src/search/search.controller.ts | 4 ++-- backend/server/src/search/search.service.ts | 4 ++-- 8 files changed, 51 insertions(+), 20 deletions(-) diff --git a/backend/server/src/analysis-comment/analysis-comment.controller.spec.ts b/backend/server/src/analysis-comment/analysis-comment.controller.spec.ts index 06fd33d..6450f6c 100644 --- a/backend/server/src/analysis-comment/analysis-comment.controller.spec.ts +++ b/backend/server/src/analysis-comment/analysis-comment.controller.spec.ts @@ -36,6 +36,7 @@ describe('AnalysisCommentController', () => { content: '', createdAt: new Date(), emotion: '', + big_emotion: '', keyword_id: 0, link: '', news_sentences: [], diff --git a/backend/server/src/analysis-comment/analysis-comment.service.ts b/backend/server/src/analysis-comment/analysis-comment.service.ts index a78754d..e02ebec 100644 --- a/backend/server/src/analysis-comment/analysis-comment.service.ts +++ b/backend/server/src/analysis-comment/analysis-comment.service.ts @@ -4,7 +4,7 @@ import { Between, DataSource, FindOperator, Repository } from 'typeorm'; import { AnalysisComment } from './entity/analysis-comment.entity'; import { CreateCommentReqDto } from './dtos/create-comment.dto'; import { ArticleContent } from './entity/article-content.entity'; -import { GetCommentsQueriesReqDto } from './dtos/get-comments-query.dto'; +import { CommentsQueriesReqDto } from './dtos/get-comments-query.dto'; @Injectable() export class AnalysisCommentService { @@ -23,6 +23,7 @@ export class AnalysisCommentService { comment.sympathy = dtos.sympathy; comment.antipathy = dtos.antipathy; comment.emotion = dtos.emotion; + comment.big_emotion = dtos.big_emotion; comment.link = dtos.link; comment.keyword_id = dtos.keyword_id; @@ -92,7 +93,7 @@ export class AnalysisCommentService { head_id, from, to, - }: GetCommentsQueriesReqDto) { + }: CommentsQueriesReqDto) { if (!search) return []; const qb = this.comment_repo.createQueryBuilder(); @@ -103,6 +104,7 @@ export class AnalysisCommentService { 'sympathy', 'antipathy', 'emotion', + 'big_emotion', 'link', ]).where(`keyword_id IN (SELECT id FROM keyword WHERE name = :name)`, { name: search, @@ -131,7 +133,16 @@ export class AnalysisCommentService { const qb = this.dataSource .createQueryBuilder() - .select(['id', 'content', 'sympathy', 'antipathy', 'emotion']) + .select([ + 'id', + 'createdAt', + 'content', + 'sympathy', + 'antipathy', + 'emotion', + 'big_emotion', + 'link', + ]) .from((subQuery) => { subQuery .select('*') @@ -148,6 +159,11 @@ export class AnalysisCommentService { return subQuery; }, 'temp') .where('ranking = 1'); - return await qb.getRawMany(); + const data = await qb.getRawMany(); + return data.map((it) => { + const comment = new AnalysisComment(); + Object.assign(comment, it); + return comment; + }); } } diff --git a/backend/server/src/analysis-comment/dtos/create-comment.dto.ts b/backend/server/src/analysis-comment/dtos/create-comment.dto.ts index bbdf7d2..9104bab 100644 --- a/backend/server/src/analysis-comment/dtos/create-comment.dto.ts +++ b/backend/server/src/analysis-comment/dtos/create-comment.dto.ts @@ -42,11 +42,18 @@ export class CreateCommentReqDto { /** * 댓글의 대표 감정 - * @example happiness + * @example 행복 */ @IsString() emotion: string; + /** + * 댓글의 감정 대분류 + * @example 행복 + */ + @IsString() + big_emotion: string; + /** * 대응되는 키워드의 id 값 * @example 1 diff --git a/backend/server/src/analysis-comment/dtos/get-comments-query.dto.ts b/backend/server/src/analysis-comment/dtos/get-comments-query.dto.ts index 192aed5..3479610 100644 --- a/backend/server/src/analysis-comment/dtos/get-comments-query.dto.ts +++ b/backend/server/src/analysis-comment/dtos/get-comments-query.dto.ts @@ -2,7 +2,7 @@ import { IsString, IsNumber, IsOptional, IsDateString } from 'class-validator'; /** * 댓글 검색에 사용되는 쿼리 목록 */ -export class GetCommentsQueriesReqDto { +export class CommentsQueriesReqDto { /** * 검색어 * @example 윤석열 diff --git a/backend/server/src/analysis-comment/entity/analysis-comment.entity.ts b/backend/server/src/analysis-comment/entity/analysis-comment.entity.ts index 495424c..3d689d3 100644 --- a/backend/server/src/analysis-comment/entity/analysis-comment.entity.ts +++ b/backend/server/src/analysis-comment/entity/analysis-comment.entity.ts @@ -41,18 +41,24 @@ export class AnalysisComment { @Column() link: string; /** - * 댓글에 할당된 감정 + * 댓글에 할당된 감정(기쁨, 슬픔, 당황, 분노 등) */ @Column() emotion: string; + /** + * 댓글에 할당된 감정 대분류(긍정 / 부정 / 중립) + */ + @Column() + big_emotion: string; + @Column() keyword_id: number; @OneToMany(() => ArticleContent, (content) => content.comment) - news_sentences: ArticleContent[]; + news_sentences?: ArticleContent[]; @JoinColumn({ name: 'keyword_id' }) @ManyToOne(() => Keyword, (keyword) => keyword.comments) - keyword: Keyword; + keyword?: Keyword; } diff --git a/backend/server/src/search/dtos/keyword-with-top-comments.dto.ts b/backend/server/src/search/dtos/keyword-with-top-comments.dto.ts index 2ce6c66..2734a41 100644 --- a/backend/server/src/search/dtos/keyword-with-top-comments.dto.ts +++ b/backend/server/src/search/dtos/keyword-with-top-comments.dto.ts @@ -27,17 +27,14 @@ export class KeywordWithTopCommentsReqQueryDto { @IsOptional() to?: string; } - export class OutCommentDto - implements - Omit< - AnalysisComment, - 'link' | 'keyword_id' | 'news_sentences' | 'keyword' | 'createdAt' - > + implements Omit { @Expose() id: number; @Expose() + createdAt: Date; + @Expose() content: string; @Expose() sympathy: number; @@ -45,12 +42,16 @@ export class OutCommentDto antipathy: number; @Expose() emotion: string; + @Expose() + big_emotion: string; + @Expose() + link: string; } export class KeywordWithTopCommentsResDto { @Expose() keyword: OutKeywordDto; - @Expose() + @Expose({ toClassOnly: false, toPlainOnly: false }) comments: OutCommentDto[]; } diff --git a/backend/server/src/search/search.controller.ts b/backend/server/src/search/search.controller.ts index f5758e4..aea5723 100644 --- a/backend/server/src/search/search.controller.ts +++ b/backend/server/src/search/search.controller.ts @@ -25,7 +25,7 @@ export class SearchController { description: '중요한 키워드 목록을 반환한다.', type: () => PopularKeywordsResDto, }) - // @Serialize(PopularKeywordsResDto) + @Serialize(PopularKeywordsResDto) @Get('popular-keywords') async getPopularKeywords( @Query() dto: PopularKeywordsReqQueryDto, @@ -46,7 +46,7 @@ export class SearchController { status: 200, type: () => KeywordWithTopCommentsResDto, }) - @Serialize(KeywordWithTopCommentsResDto) + // @Serialize(KeywordWithTopCommentsResDto) @Get('keyword-search-result') async getKeywordWithTopComments( @Query() dto: KeywordWithTopCommentsReqQueryDto, diff --git a/backend/server/src/search/search.service.ts b/backend/server/src/search/search.service.ts index f37755b..3239024 100644 --- a/backend/server/src/search/search.service.ts +++ b/backend/server/src/search/search.service.ts @@ -73,8 +73,8 @@ export class SearchService { id, true, ); - if (!commentWithSentences) - throw new NotFoundException(`there is no comment id: ${id}`); + // if (!commentWithSentences) + // throw new NotFoundException(`there is no comment id: ${id}`); return commentWithSentences; }