From 4c72f287e6b46e6e7269374940eda326582577ce Mon Sep 17 00:00:00 2001 From: Arios67 Date: Mon, 4 Apr 2022 18:56:04 +0900 Subject: [PATCH] =?UTF-8?q?=EC=97=98=EB=9D=BC=EC=8A=A4=ED=8B=B1=20?= =?UTF-8?q?=EC=84=9C=EC=B9=98=20=EC=88=98=EC=A0=95=20(=EC=A6=89=EC=8B=9C?= =?UTF-8?q?=20=EA=B5=AC=EB=A7=A4=20=EC=8B=9C=20=EC=97=98=EB=9D=BC=EC=8A=A4?= =?UTF-8?q?=ED=8B=B1=EC=84=9C=EC=B9=98=20=EC=82=AD=EC=A0=9C)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ars/elk/logstash/logstash.conf | 2 +- ars/src/apis/art/art.module.ts | 5 +---- ars/src/apis/art/art.resolver.ts | 21 ++++++++++++--------- ars/src/apis/art/art.service.ts | 17 +++++++++++------ ars/src/apis/board/board.service.ts | 6 ++++-- ars/src/apis/payment/payment.module.ts | 4 ++++ ars/src/apis/payment/payment.resolver.ts | 18 ++++++++++++++++++ ars/src/apis/payment/payment.service.ts | 7 ++++++- ars/src/common/graphql/schema.gql | 1 + 9 files changed, 58 insertions(+), 23 deletions(-) diff --git a/ars/elk/logstash/logstash.conf b/ars/elk/logstash/logstash.conf index a51b377..871a546 100644 --- a/ars/elk/logstash/logstash.conf +++ b/ars/elk/logstash/logstash.conf @@ -2,7 +2,6 @@ input { jdbc { jdbc_driver_library => "/usr/share/logstash/mysql-connector-java-8.0.28.jar" jdbc_driver_class => "com.mysql.cj.jdbc.Driver" - #jdbc_connection_string => "jdbc:mysql://10.90.0.4:3306/ars" jdbc_connection_string => "jdbc:mysql://my_database:3306/ars" jdbc_user => "root" jdbc_password => "3160" @@ -21,5 +20,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.module.ts b/ars/src/apis/art/art.module.ts index 13abb77..322f743 100644 --- a/ars/src/apis/art/art.module.ts +++ b/ars/src/apis/art/art.module.ts @@ -1,8 +1,5 @@ import { Module } from '@nestjs/common'; -import { - ElasticsearchModule, - ElasticsearchService, -} from '@nestjs/elasticsearch'; +import { ElasticsearchModule } from '@nestjs/elasticsearch'; import { TypeOrmModule } from '@nestjs/typeorm'; import { ArtImage } from '../artImage/entities/artImage.entity'; import { Engage } from '../engage/entities/engage.entity'; diff --git a/ars/src/apis/art/art.resolver.ts b/ars/src/apis/art/art.resolver.ts index 1d0ab90..820455c 100644 --- a/ars/src/apis/art/art.resolver.ts +++ b/ars/src/apis/art/art.resolver.ts @@ -38,9 +38,10 @@ export class ArtResolver { if (redisValue) { return redisValue; } - const result = await this.elasticsearchService.search({ - index: 'artipul09', + index: 'artipul00', + from: 0, + size: 500, query: { bool: { must: [{ match: { tag1: tags[0] } }], @@ -56,7 +57,6 @@ export class ArtResolver { title: el._source.title, start_price: el._source.start_price, instant_bid: el._source.instant_bid, - price: el._source.price, deadline: el._source.deadline, thumbnail: el._source.thumbnail, tag1: el._source.tag1, @@ -78,7 +78,9 @@ export class ArtResolver { } const result = await this.elasticsearchService.search({ - index: 'artipul09', + index: 'artipul00', + from: 0, + size: 500, query: { bool: { must: [{ match: { tag1: tags[0] } }, { match: { tag2: tags[1] } }], @@ -94,7 +96,6 @@ export class ArtResolver { title: el._source.title, start_price: el._source.start_price, instant_bid: el._source.instant_bid, - price: el._source.price, deadline: el._source.deadline, thumbnail: el._source.thumbnail, tag1: el._source.tag1, @@ -117,7 +118,9 @@ export class ArtResolver { } const result = await this.elasticsearchService.search({ - index: 'artipul09', + index: 'artipul00', + from: 0, + size: 500, query: { bool: { must: [ @@ -137,7 +140,6 @@ export class ArtResolver { title: el._source.title, start_price: el._source.start_price, instant_bid: el._source.instant_bid, - price: el._source.price, deadline: el._source.deadline, thumbnail: el._source.thumbnail, tag1: el._source.tag1, @@ -161,7 +163,9 @@ export class ArtResolver { } const result = await this.elasticsearchService.search({ - index: 'artipul09', + index: 'artipul00', + from: 0, + size: 500, query: { bool: { must: [ @@ -182,7 +186,6 @@ export class ArtResolver { title: el._source.title, start_price: el._source.start_price, instant_bid: el._source.instant_bid, - price: el._source.price, deadline: el._source.deadline, thumbnail: el._source.thumbnail, tag1: el._source.tag1, diff --git a/ars/src/apis/art/art.service.ts b/ars/src/apis/art/art.service.ts index 0a1b7e4..f6a9005 100644 --- a/ars/src/apis/art/art.service.ts +++ b/ars/src/apis/art/art.service.ts @@ -127,10 +127,11 @@ export class ArtService { .createQueryBuilder('art') .leftJoinAndSelect('art.payment', 'payment') .leftJoinAndSelect('payment.user', 'user') + .take(10) + .skip(10 * (page - 1)) .where('user.id =:id', { id: currentUser.id }) .withDeleted() .getMany(); - console.log('***********', art); return art; } @@ -211,11 +212,15 @@ 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.service.ts b/ars/src/apis/board/board.service.ts index 2d7432b..e43a544 100644 --- a/ars/src/apis/board/board.service.ts +++ b/ars/src/apis/board/board.service.ts @@ -1,6 +1,6 @@ import { Injectable } from '@nestjs/common'; import { InjectRepository } from '@nestjs/typeorm'; -import { Connection, Repository } from 'typeorm'; +import { Connection, getRepository, Repository } from 'typeorm'; import { Art } from '../art/entities/art.entity'; import { BoardImage } from '../boardImage/entities/boardImage.entity'; import { Comment } from '../comment/entities/comment.entity'; @@ -34,7 +34,9 @@ export class BoardService { // 게시물 모두 조회 async findAll() { - return await this.boardRepository.find(); + return await this.boardRepository.find({ + relations: ['art'], + }); } // 내가 쓴 게시물 조회 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..58e4ac7 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'; @@ -12,6 +13,8 @@ export class PaymentResolver { private readonly paymentService: PaymentService, private readonly userService: UserService, + private readonly elasticsearchService: ElasticsearchService, + @Inject(CACHE_MANAGER) private readonly cacheManager: Cache, ) {} @@ -53,6 +56,16 @@ export class PaymentResolver { const bidder = await this.userService.findOne(currentUser.email); await this.paymentService.successfulBid(artId, price, bidder, artist); + const result = await this.elasticsearchService.deleteByQuery({ + index: 'artipul00', + query: { + bool: { + must: [{ match: { id: artId } }], + }, + }, + }); + console.log(result); + return artId; } @@ -78,4 +91,9 @@ export class PaymentResolver { await this.paymentService.save(artId, currentUser.id, bid_price); return 'ok'; } + + @Mutation(() => String) + async enterBidRomm(@Args('artId') artId: string) { + return await this.paymentService.room(artId); + } } diff --git a/ars/src/apis/payment/payment.service.ts b/ars/src/apis/payment/payment.service.ts index 0517ad2..b215842 100644 --- a/ars/src/apis/payment/payment.service.ts +++ b/ars/src/apis/payment/payment.service.ts @@ -118,7 +118,10 @@ export class PaymentService { // DB 저장 async save(artId, userId, bid_price) { - this.eventGateway.server.emit('message', bid_price); + this.eventGateway.server.emit('message', { + price: bid_price, + artId: artId, + }); const queryRunner = this.connection.createQueryRunner(); await queryRunner.connect(); await queryRunner.startTransaction(); @@ -157,4 +160,6 @@ export class PaymentService { where: { userId: userId }, }); } + + async room(artId) {} } diff --git a/ars/src/common/graphql/schema.gql b/ars/src/common/graphql/schema.gql index 0104c77..ab03380 100644 --- a/ars/src/common/graphql/schema.gql +++ b/ars/src/common/graphql/schema.gql @@ -195,6 +195,7 @@ type Mutation { instantBid(artId: String!, price: Float!, artistEmail: String!): String! Bid(artId: String!, bid_price: Float!): [String!]! saveBid(artId: String!, bid_price: Float!): String! + enterBidRomm(artId: String!): String! createPointTransaction(impUid: String!, charge_amount: Float!): PointTransaction! cancelPointTransaction(impUid: String!): PointTransaction! }