Skip to content

Commit

Permalink
feat: analysiscomment(분석된 댓글 목록)에 big_emotion 속성 추가
Browse files Browse the repository at this point in the history
- 프론트엔드 측에서 감정 대분류(긍정, 중립, 부정)가 필요해 big_emotion이라는 이름으로 속성을 추가
- mysql에서 속성을 추가, 쿼리를 이용하여 big_emotion에 값을 채움

- issue: 객체 내 클래스 배열에 대해 serialize가 적용되지 않아 임시로 serialize을 주석 처리
- search/search.controller.ts -> getKeywordWithTopComments()
  • Loading branch information
blaxsior committed Nov 14, 2023
1 parent fcfd579 commit ffae65d
Show file tree
Hide file tree
Showing 8 changed files with 51 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ describe('AnalysisCommentController', () => {
content: '',
createdAt: new Date(),
emotion: '',
big_emotion: '',
keyword_id: 0,
link: '',
news_sentences: [],
Expand Down
24 changes: 20 additions & 4 deletions backend/server/src/analysis-comment/analysis-comment.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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;

Expand Down Expand Up @@ -92,7 +93,7 @@ export class AnalysisCommentService {
head_id,
from,
to,
}: GetCommentsQueriesReqDto) {
}: CommentsQueriesReqDto) {
if (!search) return [];

const qb = this.comment_repo.createQueryBuilder();
Expand All @@ -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,
Expand Down Expand Up @@ -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('*')
Expand All @@ -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;
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,18 @@ export class CreateCommentReqDto {

/**
* 댓글의 대표 감정
* @example happiness
* @example 행복
*/
@IsString()
emotion: string;

/**
* 댓글의 감정 대분류
* @example 행복
*/
@IsString()
big_emotion: string;

/**
* 대응되는 키워드의 id 값
* @example 1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { IsString, IsNumber, IsOptional, IsDateString } from 'class-validator';
/**
* 댓글 검색에 사용되는 쿼리 목록
*/
export class GetCommentsQueriesReqDto {
export class CommentsQueriesReqDto {
/**
* 검색어
* @example 윤석열
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
15 changes: 8 additions & 7 deletions backend/server/src/search/dtos/keyword-with-top-comments.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,30 +27,31 @@ export class KeywordWithTopCommentsReqQueryDto {
@IsOptional()
to?: string;
}

export class OutCommentDto
implements
Omit<
AnalysisComment,
'link' | 'keyword_id' | 'news_sentences' | 'keyword' | 'createdAt'
>
implements Omit<AnalysisComment, 'keyword_id' | 'news_sentences' | 'keyword'>
{
@Expose()
id: number;
@Expose()
createdAt: Date;
@Expose()
content: string;
@Expose()
sympathy: number;
@Expose()
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[];
}
4 changes: 2 additions & 2 deletions backend/server/src/search/search.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export class SearchController {
description: '중요한 키워드 목록을 반환한다.',
type: () => PopularKeywordsResDto,
})
// @Serialize(PopularKeywordsResDto)
@Serialize(PopularKeywordsResDto)
@Get('popular-keywords')
async getPopularKeywords(
@Query() dto: PopularKeywordsReqQueryDto,
Expand All @@ -46,7 +46,7 @@ export class SearchController {
status: 200,
type: () => KeywordWithTopCommentsResDto,
})
@Serialize(KeywordWithTopCommentsResDto)
// @Serialize(KeywordWithTopCommentsResDto)
@Get('keyword-search-result')
async getKeywordWithTopComments(
@Query() dto: KeywordWithTopCommentsReqQueryDto,
Expand Down
4 changes: 2 additions & 2 deletions backend/server/src/search/search.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down

0 comments on commit ffae65d

Please sign in to comment.