Skip to content

Commit

Permalink
엘라스틱 서치 수정 (즉시 구매 시 엘라스틱서치 삭제)
Browse files Browse the repository at this point in the history
  • Loading branch information
Arios67 committed Apr 4, 2022
1 parent ef8c86c commit 4c72f28
Show file tree
Hide file tree
Showing 9 changed files with 58 additions and 23 deletions.
2 changes: 1 addition & 1 deletion ars/elk/logstash/logstash.conf
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -21,5 +20,6 @@ output {
elasticsearch {
hosts => "elasticsearch:9200"
index => "artipul00"
document_id => "%{id}"
}
}
5 changes: 1 addition & 4 deletions ars/src/apis/art/art.module.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand Down
21 changes: 12 additions & 9 deletions ars/src/apis/art/art.resolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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] } }],
Expand All @@ -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,
Expand All @@ -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] } }],
Expand All @@ -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,
Expand All @@ -117,7 +118,9 @@ export class ArtResolver {
}

const result = await this.elasticsearchService.search({
index: 'artipul09',
index: 'artipul00',
from: 0,
size: 500,
query: {
bool: {
must: [
Expand All @@ -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,
Expand All @@ -161,7 +163,9 @@ export class ArtResolver {
}

const result = await this.elasticsearchService.search({
index: 'artipul09',
index: 'artipul00',
from: 0,
size: 500,
query: {
bool: {
must: [
Expand All @@ -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,
Expand Down
17 changes: 11 additions & 6 deletions ars/src/apis/art/art.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down Expand Up @@ -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) {
Expand Down
6 changes: 4 additions & 2 deletions ars/src/apis/board/board.service.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -34,7 +34,9 @@ export class BoardService {

// 게시물 모두 조회
async findAll() {
return await this.boardRepository.find();
return await this.boardRepository.find({
relations: ['art'],
});
}

// 내가 쓴 게시물 조회
Expand Down
4 changes: 4 additions & 0 deletions ars/src/apis/payment/payment.module.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -21,6 +22,9 @@ import { PaymentService } from './payment.service';
Engage,
]),
EventModule,
ElasticsearchModule.register({
node: 'http://elasticsearch:9200',
}),
],
providers: [
PaymentResolver, //
Expand Down
18 changes: 18 additions & 0 deletions ars/src/apis/payment/payment.resolver.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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,
) {}
Expand Down Expand Up @@ -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;
}

Expand All @@ -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);
}
}
7 changes: 6 additions & 1 deletion ars/src/apis/payment/payment.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -157,4 +160,6 @@ export class PaymentService {
where: { userId: userId },
});
}

async room(artId) {}
}
1 change: 1 addition & 0 deletions ars/src/common/graphql/schema.gql
Original file line number Diff line number Diff line change
Expand Up @@ -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!
}
Expand Down

0 comments on commit 4c72f28

Please sign in to comment.