From 35ef92b1bb7a3da6b475b4743b8fa505588e0eae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=B5=9C=EB=8B=A4=EC=8A=AC?= <95472052+Daseul1@users.noreply.github.com> Date: Mon, 4 Apr 2022 18:55:31 +0900 Subject: [PATCH] =?UTF-8?q?[#134]feat:=20=EB=B2=84=EA=B7=B8=EC=88=98?= =?UTF-8?q?=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ars/elk/logstash/logstash.conf | 1 + ars/src/apis/art/art.resolver.ts | 8 ++++---- ars/src/apis/art/art.service.ts | 14 ++++++++------ ars/src/apis/board/board.module.ts | 2 ++ ars/src/apis/board/board.resolver.ts | 6 +++--- ars/src/apis/board/board.service.ts | 9 ++++++--- ars/src/apis/payment/payment.module.ts | 4 ++++ ars/src/apis/payment/payment.resolver.ts | 14 ++++++++++++-- ars/src/apis/payment/payment.service.ts | 4 ++++ ars/src/common/graphql/schema.gql | 4 ++-- frontend/payment.html | 2 +- 11 files changed, 47 insertions(+), 21 deletions(-) diff --git a/ars/elk/logstash/logstash.conf b/ars/elk/logstash/logstash.conf index a51b377..0807a5c 100644 --- a/ars/elk/logstash/logstash.conf +++ b/ars/elk/logstash/logstash.conf @@ -21,5 +21,6 @@ output { elasticsearch { hosts => "elasticsearch:9200" index => "artipul00" + document_id => "%{id}" } } \ No newline at end of file diff --git a/ars/src/apis/art/art.resolver.ts b/ars/src/apis/art/art.resolver.ts index 1d0ab90..7c5c952 100644 --- a/ars/src/apis/art/art.resolver.ts +++ b/ars/src/apis/art/art.resolver.ts @@ -40,7 +40,7 @@ export class ArtResolver { } const result = await this.elasticsearchService.search({ - index: 'artipul09', + index: 'artipul00', query: { bool: { must: [{ match: { tag1: tags[0] } }], @@ -78,7 +78,7 @@ export class ArtResolver { } const result = await this.elasticsearchService.search({ - index: 'artipul09', + index: 'artipul00', query: { bool: { must: [{ match: { tag1: tags[0] } }, { match: { tag2: tags[1] } }], @@ -117,7 +117,7 @@ export class ArtResolver { } const result = await this.elasticsearchService.search({ - index: 'artipul09', + index: 'artipul00', query: { bool: { must: [ @@ -161,7 +161,7 @@ export class ArtResolver { } const result = await this.elasticsearchService.search({ - index: 'artipul09', + index: 'artipul00', query: { bool: { must: [ diff --git a/ars/src/apis/art/art.service.ts b/ars/src/apis/art/art.service.ts index 0a1b7e4..67205f5 100644 --- a/ars/src/apis/art/art.service.ts +++ b/ars/src/apis/art/art.service.ts @@ -130,7 +130,6 @@ export class ArtService { .where('user.id =:id', { id: currentUser.id }) .withDeleted() .getMany(); - console.log('***********', art); return art; } @@ -211,11 +210,14 @@ export class ArtService { } async countComletedAuctionArts(userId) { - const result = await this.artRepository.count({ - withDeleted: true, - where: { user: userId, is_soldout: true }, - }); - return result; + const art = await getRepository(Art) + .createQueryBuilder('art') + .leftJoinAndSelect('art.payment', 'payment') + .leftJoinAndSelect('payment.user', 'user') + .where('user.id =:id', { id: userId }) + .withDeleted() + .getCount(); + return art; } async countTimedoutArts(userId) { diff --git a/ars/src/apis/board/board.module.ts b/ars/src/apis/board/board.module.ts index eec8333..26c8b89 100644 --- a/ars/src/apis/board/board.module.ts +++ b/ars/src/apis/board/board.module.ts @@ -5,6 +5,7 @@ import { BoardImage } from '../boardImage/entities/boardImage.entity'; import { Comment } from '../comment/entities/comment.entity'; import { FileService } from '../file/file.service'; import { LikeBoardService } from '../likeBoard/likeBoard.service'; +import { User } from '../user/entities/user.entity'; import { BoardResolver } from './board.resolver'; import { BoardService } from './board.service'; import { Board } from './entities/board.entity'; @@ -18,6 +19,7 @@ import { LikeBoard } from './entities/likeBoard.entity'; BoardImage, Comment, LikeBoard, + User, ]), ], providers: [ diff --git a/ars/src/apis/board/board.resolver.ts b/ars/src/apis/board/board.resolver.ts index 4527fa0..49b859e 100644 --- a/ars/src/apis/board/board.resolver.ts +++ b/ars/src/apis/board/board.resolver.ts @@ -33,15 +33,15 @@ export class BoardResolver { // 게시물 모두 조회 @Query(() => [Board]) - async fetchBoards() { - return await this.boardService.findAll(); + async fetchBoards(@Args('page', { nullable: true }) page: number) { + return await this.boardService.findAll(page); } // 내가 쓴 게시물 조회 @UseGuards(GqlAuthAccessGuard) @Query(() => [Board]) async fetchBoardsOfMine( - @Args('page') page: number, + @Args('page', { nullable: true }) page: number, @CurrentUser() currentUser: ICurrentUser, ) { return await this.boardService.findMine({ currentUser }, page); diff --git a/ars/src/apis/board/board.service.ts b/ars/src/apis/board/board.service.ts index 2d7432b..8959ee1 100644 --- a/ars/src/apis/board/board.service.ts +++ b/ars/src/apis/board/board.service.ts @@ -33,15 +33,18 @@ export class BoardService { } // 게시물 모두 조회 - async findAll() { - return await this.boardRepository.find(); + async findAll(page) { + return await this.boardRepository.find({ + take: 10, + skip: 10 * (page - 1), + }); } // 내가 쓴 게시물 조회 async findMine({ currentUser }, page) { return await this.boardRepository.find({ - skip: 10, take: 10, + skip: 10 * (page - 1), where: { user: currentUser }, }); } diff --git a/ars/src/apis/payment/payment.module.ts b/ars/src/apis/payment/payment.module.ts index 159083a..8b50855 100644 --- a/ars/src/apis/payment/payment.module.ts +++ b/ars/src/apis/payment/payment.module.ts @@ -1,4 +1,5 @@ import { Module } from '@nestjs/common'; +import { ElasticsearchModule } from '@nestjs/elasticsearch'; import { TypeOrmModule } from '@nestjs/typeorm'; import { ArtService } from '../art/art.service'; import { Art } from '../art/entities/art.entity'; @@ -21,6 +22,9 @@ import { PaymentService } from './payment.service'; Engage, ]), EventModule, + ElasticsearchModule.register({ + node: 'http://elasticsearch:9200', + }), ], providers: [ PaymentResolver, // diff --git a/ars/src/apis/payment/payment.resolver.ts b/ars/src/apis/payment/payment.resolver.ts index 867ce30..d7e6fe1 100644 --- a/ars/src/apis/payment/payment.resolver.ts +++ b/ars/src/apis/payment/payment.resolver.ts @@ -1,4 +1,5 @@ import { CACHE_MANAGER, Inject, UseGuards } from '@nestjs/common'; +import { ElasticsearchService } from '@nestjs/elasticsearch'; import { Args, Mutation, Resolver } from '@nestjs/graphql'; import { Cache } from 'cache-manager'; import { GqlAuthAccessGuard } from 'src/common/auth/gql-auth.guard'; @@ -11,6 +12,7 @@ export class PaymentResolver { constructor( private readonly paymentService: PaymentService, private readonly userService: UserService, + private readonly elasticsearchService: ElasticsearchService, @Inject(CACHE_MANAGER) private readonly cacheManager: Cache, @@ -53,9 +55,17 @@ export class PaymentResolver { const bidder = await this.userService.findOne(currentUser.email); await this.paymentService.successfulBid(artId, price, bidder, artist); - return artId; - } + const result = await this.elasticsearchService.deleteByQuery({ + index: 'artipul00', + query: { + bool: { + must: [{ match: { id: artId } }], + }, + }, + }); + return 'ok'; + } // 레디스에 입찰 정보(작품, 현재 입찰가, 현재 상위 입찰자) @UseGuards(GqlAuthAccessGuard) @Mutation(() => [String]) diff --git a/ars/src/apis/payment/payment.service.ts b/ars/src/apis/payment/payment.service.ts index 0517ad2..0c7e75d 100644 --- a/ars/src/apis/payment/payment.service.ts +++ b/ars/src/apis/payment/payment.service.ts @@ -29,6 +29,10 @@ export class PaymentService { private readonly connection: Connection, ) {} + async find() { + await this.artRepository.find(); + } + // 마감된 작품 체크 async checkTimeout() { const utc = new Date(); diff --git a/ars/src/common/graphql/schema.gql b/ars/src/common/graphql/schema.gql index 0104c77..470f69f 100644 --- a/ars/src/common/graphql/schema.gql +++ b/ars/src/common/graphql/schema.gql @@ -153,8 +153,8 @@ type Query { fetchLikeArt(page: Float): [Art!]! fetchBoard(boardId: String!): Board! fetchBoardImgaes(boardId: String!): [BoardImage!]! - fetchBoards: [Board!]! - fetchBoardsOfMine(page: Float!): [Board!]! + fetchBoards(page: Float): [Board!]! + fetchBoardsOfMine(page: Float): [Board!]! fetchBoardsOfMineCount: Float! countLikeBoard(boardId: String!): Int! fetchLikeBoard: [Board!]! diff --git a/frontend/payment.html b/frontend/payment.html index f982d0c..14e416e 100644 --- a/frontend/payment.html +++ b/frontend/payment.html @@ -57,7 +57,7 @@ { headers: { Authorization: - "Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJlbWFpbCI6ImJiYkBhLmEiLCJzdWIiOiI4MzdjZTkyOS1lYjE5LTRiYTgtOTgzNi02ZTk3NTQ2NzkzNGEiLCJpYXQiOjE2NDg2MzU0OTcsImV4cCI6MTY0ODYzOTA5N30.0biQLLvJrSYyntwAsBzQX6abz-x7yXsFDSr44uA7h2M", + "Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJlbWFpbCI6ImVrdG1mQGEuYSIsInN1YiI6ImM0ZTViYWY5LTI0NzctNDIxZC1iMDRhLWZmNzAwNjQwYjc2MCIsImlhdCI6MTY0OTA0NjMwMCwiZXhwIjoxNjQ5MDQ5OTAwfQ.i__qC-xy43JECudJ0YGuCoHWYyTb7nmRYJHU__4G9Ns", }, } );