Skip to content

Commit

Permalink
Merge branch 'develop' into feat/#129
Browse files Browse the repository at this point in the history
  • Loading branch information
Arios67 authored Apr 3, 2022
2 parents d7d33ed + cfc489c commit cec14f6
Show file tree
Hide file tree
Showing 18 changed files with 184 additions and 143 deletions.
Binary file modified .DS_Store
Binary file not shown.
2 changes: 1 addition & 1 deletion ars/docker-compose.dev.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ version: '3.3'
services:
my_backend:
platform: linux/x86_64
image: asia.gcr.io/artiful-a1/my_backend:2.0
image: asia.gcr.io/artiful-a1/my_backend:1.9
build:
context: .
dockerfile: Dockerfile
Expand Down
4 changes: 2 additions & 2 deletions ars/elk/logstash/logstash.conf
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@ input {
last_run_metadata_path => "./aaa.txt"

tracking_column_type => "numeric"
statement => "select art.id, title, start_price, instant_bid, price, thumbnail, createdAt, deadline, tag1, tag2, tag3, tag4, updatedat, u.nickname, unix_timestamp(art.updatedat) as updatedat from art left join user as u ON art.userId = u.id where unix_timestamp(art.updatedat) > :sql_last_value order by updatedat asc"
statement => "select art.id, title, start_price, instant_bid, thumbnail, createdAt, deadline, is_soldout, tag1, tag2, tag3, tag4, updatedat, u.nickname, unix_timestamp(art.updatedat) as updatedat from art left join user as u ON art.userId = u.id where unix_timestamp(art.updatedat) > :sql_last_value order by updatedat asc"
}
}

output {
elasticsearch {
hosts => "elasticsearch:9200"
index => "artipul09"
index => "artipul00"
}
}
35 changes: 22 additions & 13 deletions ars/src/apis/art/art.resolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,24 +40,26 @@ export class ArtResolver {
}

const result = await this.elasticsearchService.search({
index: 'artipul09',
index: 'artipul00',
from: 0,
size: 500,
query: {
bool: {
must: [{ match: { tag1: tags[0] } }],
},
},
});

if (!result.hits.hits.length) return null;
if (!result.hits.hits.length) return [];

const artTags = result.hits.hits.map((el: any) => {
return {
id: el._source.id,
title: el._source.title,
start_price: el._source.start_price,
instant_bid: el._source.instant_bid,
price: el._source.price,
deadline: el._source.deadline,
is_soldout: el._source.is_soldout,
thumbnail: el._source.thumbnail,
tag1: el._source.tag1,
nickname: el._source.nickname,
Expand All @@ -78,24 +80,26 @@ 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] } }],
},
},
});

if (!result.hits.hits.length) return null;
if (!result.hits.hits.length) return [];

const artTags = result.hits.hits.map((el: any) => {
return {
id: el._source.id,
title: el._source.title,
start_price: el._source.start_price,
instant_bid: el._source.instant_bid,
price: el._source.price,
deadline: el._source.deadline,
is_soldout: el._source.is_soldout,
thumbnail: el._source.thumbnail,
tag1: el._source.tag1,
tag2: el._source.tag2,
Expand All @@ -117,7 +121,9 @@ export class ArtResolver {
}

const result = await this.elasticsearchService.search({
index: 'artipul09',
index: 'artipul00',
from: 0,
size: 500,
query: {
bool: {
must: [
Expand All @@ -129,16 +135,16 @@ export class ArtResolver {
},
});

if (!result.hits.hits.length) return null;
if (!result.hits.hits.length) return [];

const artTags = result.hits.hits.map((el: any) => {
return {
id: el._source.id,
title: el._source.title,
start_price: el._source.start_price,
instant_bid: el._source.instant_bid,
price: el._source.price,
deadline: el._source.deadline,
is_soldout: el._source.is_soldout,
thumbnail: el._source.thumbnail,
tag1: el._source.tag1,
tag2: el._source.tag2,
Expand All @@ -161,7 +167,9 @@ export class ArtResolver {
}

const result = await this.elasticsearchService.search({
index: 'artipul09',
index: 'artipul00',
from: 0,
size: 500,
query: {
bool: {
must: [
Expand All @@ -174,16 +182,16 @@ export class ArtResolver {
},
});

if (!result.hits.hits.length) return null;
if (!result.hits.hits.length) return [];

const artTags = result.hits.hits.map((el: any) => {
return {
id: el._source.id,
title: el._source.title,
start_price: el._source.start_price,
instant_bid: el._source.instant_bid,
price: el._source.price,
deadline: el._source.deadline,
is_soldout: el._source.is_soldout,
thumbnail: el._source.thumbnail,
tag1: el._source.tag1,
tag2: el._source.tag2,
Expand Down Expand Up @@ -267,7 +275,7 @@ export class ArtResolver {
@UseGuards(GqlAuthAccessGuard)
@Query(() => [Art])
async fetchTransactionCompletedArts(
@Args('page') page: number,
@Args('page', { nullable: true }) page: number,
@CurrentUser() currentUser: ICurrentUser,
) {
return await this.artService.findcompleteAuction({ currentUser }, page);
Expand Down Expand Up @@ -309,6 +317,7 @@ export class ArtResolver {
@Mutation(() => Boolean)
async addLikeArt(
@Args('artId') artId: string,
@Args('likeId', { nullable: true }) likeId: string,
@CurrentUser() currentUser: ICurrentUser,
) {
return await this.likeArtService.like(artId, currentUser.id);
Expand Down
65 changes: 33 additions & 32 deletions ars/src/apis/art/art.service.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import { Injectable } from '@nestjs/common';
import { InjectRepository } from '@nestjs/typeorm';
import { Connection, IsNull, MoreThan, Not, Repository } from 'typeorm';
import { Connection, getRepository, IsNull, Not, Repository } from 'typeorm';
import { ArtImage } from '../artImage/entities/artImage.entity';
import { Engage } from '../engage/entities/engage.entity';
import { Payment } from '../payment/entities/payment.entity';
import { User } from '../user/entities/user.entity';
import { Art } from './entities/art.entity';
import { LikeArt } from './entities/likeArt.entity';

Expand All @@ -15,6 +17,12 @@ export class ArtService {
@InjectRepository(ArtImage)
private readonly artImageRepository: Repository<ArtImage>,

@InjectRepository(User)
private readonly userRepository: Repository<User>,

@InjectRepository(Payment)
private readonly paymentRepository: Repository<Payment>,

private readonly connection: Connection,
) {}

Expand All @@ -34,9 +42,7 @@ export class ArtService {
tag2: tags[1],
tag3: tags[2],
tag4: tags[3],
createdAt: MoreThan(createdAt),
},
order: { createdAt: 'ASC' },
});
break;
case 3:
Expand All @@ -45,28 +51,22 @@ export class ArtService {
tag1: tags[0],
tag2: tags[1],
tag3: tags[2],
createdAt: MoreThan(createdAt),
},
order: { createdAt: 'ASC' },
});
break;
case 2:
result = await this.artRepository.find({
where: {
tag1: tags[0],
tag2: tags[1],
createdAt: MoreThan(createdAt),
},
order: { createdAt: 'ASC' },
});
break;
case 1:
result = await this.artRepository.find({
where: {
tag1: tags[0],
createdAt: MoreThan(createdAt),
},
order: { createdAt: 'ASC' },
});
}
await queryRunner.commitTransaction();
Expand Down Expand Up @@ -105,7 +105,6 @@ export class ArtService {
skip: 10 * (page - 1),
where: { user: currentUser.id, deletedAt: Not(IsNull()) },
});
console.log(art);
return art;
}

Expand All @@ -124,45 +123,47 @@ export class ArtService {

// 일반유저(내가) 구매한 작품 조회
async findcompleteAuction({ currentUser }, page) {
const art = await this.artRepository.find({
withDeleted: true,
take: 10,
skip: 10 * (page - 1),
where: { user: currentUser.id, is_soldout: true },
});
const art = await getRepository(Art)
.createQueryBuilder('art')
.leftJoinAndSelect('art.payment', 'payment')
.leftJoinAndSelect('payment.user', 'user')
.where('user.id =:id', { id: currentUser.id })
.withDeleted()
.getMany();
console.log('***********', art);
return art;
}

// 작품 등록
async create({ image_urls, tags, ...rest }, currentUser) {
async create({ thumbnail, tags, ...rest }, currentUser) {
const queryRunner = this.connection.createQueryRunner();
await queryRunner.connect();
await queryRunner.startTransaction();
try {
const result = await queryRunner.manager.save(Art, {
...rest,
user: currentUser,
thumbnail: image_urls[0],
thumbnail: thumbnail,
tag1: tags[0],
tag2: tags[1],
tag3: tags[2],
tag4: tags[3],
});

for (let i = 0; i < image_urls.length; i++) {
if (i === 0) {
await queryRunner.manager.save(ArtImage, {
url: image_urls[i],
isMain: true,
art: result,
});
} else {
await queryRunner.manager.save(ArtImage, {
url: image_urls[i],
art: result,
});
}
}
// for (let i = 0; i < image_urls.length; i++) {
// if (i === 0) {
// await queryRunner.manager.save(ArtImage, {
// url: image_urls[i],
// isMain: true,
// art: result,
// });
// } else {
// await queryRunner.manager.save(ArtImage, {
// url: image_urls[i],
// art: result,
// });
// }
// }
await queryRunner.commitTransaction();
return result;
} catch (error) {
Expand Down
21 changes: 6 additions & 15 deletions ars/src/apis/art/dto/createArtInput.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,27 +17,18 @@ export class CreateArtInput {
@Field(() => Int)
price: number;

@Field(() => Date)
@Field(() => Date, { nullable: true })
deadline: Date;

@Field(() => [String])
image_urls: string[];
// @Field(() => [String])
// image_urls: string[];

@Field(() => String)
thumbnail: string;

@Field(() => Boolean)
is_soldout: boolean;

@Field(() => [String])
tags: string[];

// @Field(() => String)
// tag1: string;

// @Field(() => String, { nullable: true })
// tag2?: string;

// @Field(() => String, { nullable: true })
// tag3?: string;

// @Field(() => String, { nullable: true })
// tag4?: string;
}
6 changes: 3 additions & 3 deletions ars/src/apis/art/entities/art.entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ export class Art {
deletedAt: Date;

@Column()
@Field(() => Date)
deadline: Date;
@Field(() => String)
deadline: string;

@Column({ default: false })
@Field(() => Boolean)
Expand All @@ -67,7 +67,7 @@ export class Art {
@Field(() => User)
user: User;

@OneToOne(() => Payment)
@OneToOne(() => Payment, (payment) => payment.art)
@Field(() => Payment)
payment: Payment;

Expand Down
12 changes: 6 additions & 6 deletions ars/src/apis/art/entities/artsSearch.entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,17 @@ export class ArtsSearch {
@Field(() => Int)
instant_bid: number;

@Column({ default: null })
@Field(() => Int)
price: number;

@Column()
@Field(() => String)
thumbnail: string;

@Column()
@Field(() => Date)
deadline: Date;
@Field(() => String, { nullable: true })
deadline: string;

@Column({ default: false })
@Field(() => Boolean)
is_soldout: boolean;

@Column()
@Field(() => String)
Expand Down
2 changes: 2 additions & 0 deletions ars/src/apis/art/entities/likeArt.entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,10 @@ export class LikeArt {
id: string;

@Column()
@Field(() => String)
userId: string;

@ManyToOne(() => Art, { eager: true })
@Field(() => Art)
art: Art;
}
Loading

0 comments on commit cec14f6

Please sign in to comment.