Skip to content

Commit

Permalink
πŸ”€ Merge pull request #273 from qkrwogk/test/board
Browse files Browse the repository at this point in the history
[BE] sentiment, board λͺ¨λ“ˆ e2e ν…ŒμŠ€νŠΈ μ½”λ“œ μž‘μ„±, ν…ŒμŠ€νŠΈ, μ½”λ“œ κ°œμ„ 
  • Loading branch information
qkrwogk authored Dec 7, 2023
2 parents 1417d30 + 4310454 commit 527f897
Show file tree
Hide file tree
Showing 6 changed files with 217 additions and 129 deletions.
22 changes: 11 additions & 11 deletions packages/server/src/board/board.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,13 @@ export class BoardController {
@UseInterceptors(TransactionInterceptor)
@UsePipes(ValidationPipe)
@CreateBoardSwaggerDecorator()
createBoard(
async createBoard(
@Body() createBoardDto: CreateBoardDto,
@GetUser() userData: UserDataDto,
@UploadedFiles() files: Express.Multer.File[],
@GetQueryRunner() queryRunner: QueryRunner,
): Promise<Board> {
return this.boardService.createBoard(
return await this.boardService.createBoard(
createBoardDto,
userData,
files,
Expand Down Expand Up @@ -97,7 +97,7 @@ export class BoardController {
@Param('id', ParseIntPipe) id: number,
@GetUser() userData: UserDataDto,
): Promise<boolean> {
return this.boardService.getIsLiked(id, userData);
return await this.boardService.getIsLiked(id, userData);
}

// 사진도 μˆ˜μ •ν•  수 μžˆλ„λ‘ 폼데이터 ν˜•νƒœλ‘œ λ°›κΈ°
Expand All @@ -107,14 +107,14 @@ export class BoardController {
@UseInterceptors(TransactionInterceptor)
@UsePipes(ValidationPipe)
@UpdateBoardSwaggerDecorator()
updateBoard(
async updateBoard(
@Param('id', ParseIntPipe) id: number,
@Body() updateBoardDto: UpdateBoardDto,
@GetUser() userData: UserDataDto,
@UploadedFiles() files: Express.Multer.File[],
@GetQueryRunner() queryRunner: QueryRunner,
) {
return this.boardService.updateBoard(
return await this.boardService.updateBoard(
id,
updateBoardDto,
userData,
Expand All @@ -127,22 +127,22 @@ export class BoardController {
@UseGuards(CookieAuthGuard)
@UsePipes(ValidationPipe)
@PatchLikeSwaggerDecorator()
patchLike(
async patchLike(
@Param('id', ParseIntPipe) id: number,
@GetUser() userData: UserDataDto,
): Promise<Partial<Board>> {
return this.boardService.patchLike(id, userData);
return await this.boardService.patchLike(id, userData);
}

@Patch(':id/unlike')
@UseGuards(CookieAuthGuard)
@UsePipes(ValidationPipe)
@PatchUnlikeSwaggerDecorator()
patchUnlike(
async patchUnlike(
@Param('id', ParseIntPipe) id: number,
@GetUser() userData: UserDataDto,
): Promise<Partial<Board>> {
return this.boardService.patchUnlike(id, userData);
return await this.boardService.patchUnlike(id, userData);
}

// μ—°κ΄€λœ Image 및 Star, Like도 ν•¨κ»˜ μ‚­μ œ
Expand All @@ -151,11 +151,11 @@ export class BoardController {
@UseInterceptors(TransactionInterceptor)
@UsePipes(ValidationPipe)
@DeleteBoardSwaggerDecorator()
deleteBoard(
async deleteBoard(
@Param('id', ParseIntPipe) id: number,
@GetUser() userData: UserDataDto,
@GetQueryRunner() queryRunner: QueryRunner,
): Promise<DeleteResult> {
return this.boardService.deleteBoard(id, userData, queryRunner);
return await this.boardService.deleteBoard(id, userData, queryRunner);
}
}
16 changes: 15 additions & 1 deletion packages/server/src/board/board.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import { Model } from 'mongoose';
@Injectable()
export class BoardService {
constructor(
// private readonly dataSource: DataSource,
@InjectRepository(Board)
private readonly boardRepository: Repository<Board>,
@InjectRepository(Image)
Expand All @@ -41,6 +42,9 @@ export class BoardService {
files: Express.Multer.File[],
queryRunner: QueryRunner,
): Promise<Board> {
// const queryRunner = this.dataSource.createQueryRunner();
// await queryRunner.startTransaction();

const { title, content, star } = createBoardDto;

const user = await queryRunner.manager.findOneBy(User, {
Expand Down Expand Up @@ -84,6 +88,8 @@ export class BoardService {
const createdBoard: Board = await queryRunner.manager.save(board);

createdBoard.user.password = undefined; // password μ œκ±°ν•˜μ—¬ λ°˜ν™˜

// await queryRunner.commitTransaction();
return createdBoard;
}

Expand Down Expand Up @@ -114,6 +120,8 @@ export class BoardService {
files: Express.Multer.File[],
queryRunner: QueryRunner,
) {
// await queryRunner.startTransaction();

const board: Board = await queryRunner.manager.findOneBy(Board, { id });
if (!board) {
throw new NotFoundException(`Not found board with id: ${id}`);
Expand All @@ -131,7 +139,7 @@ export class BoardService {
);
}

if (files.length > 0) {
if (files && files.length > 0) {
const images: Image[] = [];
for (const file of files) {
const imageInfo = await this.uploadFile(file);
Expand Down Expand Up @@ -165,6 +173,8 @@ export class BoardService {
});

delete updatedBoard.user.password; // password μ œκ±°ν•˜μ—¬ λ°˜ν™˜

// await queryRunner.commitTransaction();
return updatedBoard;
}

Expand Down Expand Up @@ -237,6 +247,8 @@ export class BoardService {
userData: UserDataDto,
queryRunner: QueryRunner,
): Promise<DeleteResult> {
// await queryRunner.startTransaction();

const board: Board = await queryRunner.manager.findOneBy(Board, { id });

if (!board) {
Expand Down Expand Up @@ -265,6 +277,8 @@ export class BoardService {

// κ²Œμ‹œκΈ€ μ‚­μ œ
const result = await queryRunner.manager.delete(Board, { id });

// await queryRunner.commitTransaction();
return result;
}

Expand Down
2 changes: 0 additions & 2 deletions packages/server/src/board/entities/board.entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,10 @@ import {
Column,
CreateDateColumn,
Entity,
JoinColumn,
JoinTable,
ManyToMany,
ManyToOne,
OneToMany,
OneToOne,
PrimaryGeneratedColumn,
UpdateDateColumn,
} from 'typeorm';
Expand Down
9 changes: 7 additions & 2 deletions packages/server/src/sentiment/sentiment.service.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
import { Injectable, InternalServerErrorException } from '@nestjs/common';
import {
BadRequestException,
Injectable,
InternalServerErrorException,
} from '@nestjs/common';
import { GetSentimentDto } from './dto/get-sentiment.dto';
import { clovaConfig } from 'src/config/clova.config';
import { clovaConfig } from '../config/clova.config';

@Injectable()
export class SentimentService {
async getSentiment(body: GetSentimentDto) {
const { content } = body;
if (!content) throw new BadRequestException('κ²Œμ‹œκΈ€ λ‚΄μš©μ΄ μ—†μŠ΅λ‹ˆλ‹€.');

const response = await fetch(clovaConfig.url, {
method: 'POST',
Expand Down
Loading

0 comments on commit 527f897

Please sign in to comment.