From 06faf74cf366b529651ce55c6d3e6bf559b23d26 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: Sat, 2 Apr 2022 15:53:22 +0900 Subject: [PATCH 1/6] =?UTF-8?q?[#116]feat:=20=EC=97=98=EB=9D=BC=EC=8A=A4?= =?UTF-8?q?=ED=8B=B1=20=EC=B5=9C=EC=A2=85=20=EC=88=98=EC=A0=953?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .DS_Store | Bin 6148 -> 6148 bytes ars/docker-compose.dev.yaml | 5 ++++- ars/elk/logstash/logstash.conf | 2 +- ars/src/apis/art/art.resolver.ts | 13 +++++++++---- ars/src/apis/art/art.service.ts | 8 -------- ars/src/apis/art/dto/createArtInput.ts | 14 +------------- .../apis/art/entities/artsSearch.entity.ts | 4 ++-- ars/src/app.module.ts | 1 + ars/src/common/graphql/schema.gql | 4 ++-- 9 files changed, 20 insertions(+), 31 deletions(-) diff --git a/.DS_Store b/.DS_Store index 45d21ae6a8f68cc74d24b87504e5179e86777414..970b22e2921ecb0dcf1281778d0bb3d3e20795d1 100644 GIT binary patch delta 57 zcmV-90LK4>FoZCWVFR~faFY=Nr;`f-76G@DA^~v<7khg)H8?CFEi;pz0UH5{lez&P P0gAKQ0WAiz1_=HS1OyR_ delta 58 zcmV-A0LA}=FoZCWVFS2gaFY=Nr;`f-76G`EA^~v=7<+p)GB7M4Gcz}nodFvGij%nk Q9|4QA*#RvEvj+(M4-)YazW@LL diff --git a/ars/docker-compose.dev.yaml b/ars/docker-compose.dev.yaml index cd67f2a..5d69b1b 100644 --- a/ars/docker-compose.dev.yaml +++ b/ars/docker-compose.dev.yaml @@ -2,14 +2,17 @@ version: '3.3' services: my_backend: + platform: linux/x86_64 + image: asia.gcr.io/artiful-a1/my_backend:1.9 build: context: . dockerfile: Dockerfile + env_file: + - ./.env.dev ports: - 3000:3000 volumes: - ./src:/myfolder/src - - ./.env:/myfolder/.env my_database: platform: linux/x86_64 diff --git a/ars/elk/logstash/logstash.conf b/ars/elk/logstash/logstash.conf index 7013835..12f440a 100644 --- a/ars/elk/logstash/logstash.conf +++ b/ars/elk/logstash/logstash.conf @@ -13,7 +13,7 @@ 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, 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" } } diff --git a/ars/src/apis/art/art.resolver.ts b/ars/src/apis/art/art.resolver.ts index 1d0ab90..5d71497 100644 --- a/ars/src/apis/art/art.resolver.ts +++ b/ars/src/apis/art/art.resolver.ts @@ -41,6 +41,8 @@ export class ArtResolver { const result = await this.elasticsearchService.search({ index: 'artipul09', + from: 0, + size: 500, query: { bool: { must: [{ match: { tag1: tags[0] } }], @@ -56,7 +58,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, @@ -79,6 +80,8 @@ export class ArtResolver { const result = await this.elasticsearchService.search({ index: 'artipul09', + from: 0, + size: 500, query: { bool: { must: [{ match: { tag1: tags[0] } }, { match: { tag2: tags[1] } }], @@ -94,7 +97,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, @@ -118,6 +120,8 @@ export class ArtResolver { const result = await this.elasticsearchService.search({ index: 'artipul09', + from: 0, + size: 500, query: { bool: { must: [ @@ -132,12 +136,12 @@ export class ArtResolver { if (!result.hits.hits.length) return null; const artTags = result.hits.hits.map((el: any) => { + console.log('=======', el); 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, thumbnail: el._source.thumbnail, tag1: el._source.tag1, @@ -162,6 +166,8 @@ export class ArtResolver { const result = await this.elasticsearchService.search({ index: 'artipul09', + from: 0, + size: 500, query: { bool: { must: [ @@ -182,7 +188,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 994db75..7963b05 100644 --- a/ars/src/apis/art/art.service.ts +++ b/ars/src/apis/art/art.service.ts @@ -34,9 +34,7 @@ export class ArtService { tag2: tags[1], tag3: tags[2], tag4: tags[3], - createdAt: MoreThan(createdAt), }, - order: { createdAt: 'ASC' }, }); break; case 3: @@ -45,9 +43,7 @@ export class ArtService { tag1: tags[0], tag2: tags[1], tag3: tags[2], - createdAt: MoreThan(createdAt), }, - order: { createdAt: 'ASC' }, }); break; case 2: @@ -55,18 +51,14 @@ export class ArtService { 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(); diff --git a/ars/src/apis/art/dto/createArtInput.ts b/ars/src/apis/art/dto/createArtInput.ts index 55ed12b..860beed 100644 --- a/ars/src/apis/art/dto/createArtInput.ts +++ b/ars/src/apis/art/dto/createArtInput.ts @@ -17,7 +17,7 @@ export class CreateArtInput { @Field(() => Int) price: number; - @Field(() => Date) + @Field(() => Date, { nullable: true }) deadline: Date; @Field(() => [String]) @@ -28,16 +28,4 @@ export class CreateArtInput { @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; } diff --git a/ars/src/apis/art/entities/artsSearch.entity.ts b/ars/src/apis/art/entities/artsSearch.entity.ts index bff902b..dd97da2 100644 --- a/ars/src/apis/art/entities/artsSearch.entity.ts +++ b/ars/src/apis/art/entities/artsSearch.entity.ts @@ -29,8 +29,8 @@ export class ArtsSearch { thumbnail: string; @Column() - @Field(() => Date) - deadline: Date; + @Field(() => String, { nullable: true }) + deadline: string; @Column() @Field(() => String) diff --git a/ars/src/app.module.ts b/ars/src/app.module.ts index 3affd5c..21ad61a 100644 --- a/ars/src/app.module.ts +++ b/ars/src/app.module.ts @@ -47,6 +47,7 @@ import { PaymentModule } from './apis/payment/payment.module'; entities: [__dirname + '/apis/**/*.entity.*'], synchronize: true, logging: true, + timezone: 'Asia/seoul', }), CacheModule.register({ store: redisStore, diff --git a/ars/src/common/graphql/schema.gql b/ars/src/common/graphql/schema.gql index e89ded4..d828794 100644 --- a/ars/src/common/graphql/schema.gql +++ b/ars/src/common/graphql/schema.gql @@ -103,7 +103,7 @@ type ArtsSearch { instant_bid: Int! price: Int! thumbnail: String! - deadline: DateTime! + deadline: String tag1: String! tag2: String tag3: String @@ -203,7 +203,7 @@ input CreateArtInput { start_price: Int! instant_bid: Int! price: Int! - deadline: DateTime! + deadline: DateTime image_urls: [String!]! is_soldout: Boolean! tags: [String!]! From 759fa458b88195e3774d0c70b193fd6e9d916cc6 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: Sat, 2 Apr 2022 20:33:14 +0900 Subject: [PATCH 2/6] =?UTF-8?q?[#118]feat:=20=EC=97=94=ED=8B=B0=ED=8B=B0?= =?UTF-8?q?=EC=88=98=EC=A0=95,=20art=20=EC=88=98=EC=A0=95,=20createBoard?= =?UTF-8?q?=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ars/elk/logstash/logstash.conf | 4 +-- ars/src/apis/art/art.resolver.ts | 21 +++++++----- ars/src/apis/art/art.service.ts | 33 +++++++++---------- ars/src/apis/art/dto/createArtInput.ts | 7 ++-- ars/src/apis/art/entities/art.entity.ts | 4 +-- .../apis/art/entities/artsSearch.entity.ts | 8 ++--- ars/src/apis/art/entities/likeArt.entity.ts | 9 +---- ars/src/apis/auth/auth.service.ts | 6 ---- ars/src/apis/board/board.service.ts | 7 +++- ars/src/apis/board/entities/board.entity.ts | 2 +- ars/src/apis/tag/entities/tag.entity.ts | 14 -------- ars/src/common/graphql/schema.gql | 6 ++-- 12 files changed, 52 insertions(+), 69 deletions(-) delete mode 100644 ars/src/apis/tag/entities/tag.entity.ts diff --git a/ars/elk/logstash/logstash.conf b/ars/elk/logstash/logstash.conf index 12f440a..a51b377 100644 --- a/ars/elk/logstash/logstash.conf +++ b/ars/elk/logstash/logstash.conf @@ -13,13 +13,13 @@ input { last_run_metadata_path => "./aaa.txt" tracking_column_type => "numeric" - statement => "select art.id, title, start_price, instant_bid, 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" } } \ 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 5d71497..e3b9287 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', from: 0, size: 500, query: { @@ -50,7 +50,7 @@ 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 { @@ -59,6 +59,7 @@ export class ArtResolver { start_price: el._source.start_price, instant_bid: el._source.instant_bid, deadline: el._source.deadline, + is_soldout: el._source.is_soldout, thumbnail: el._source.thumbnail, tag1: el._source.tag1, nickname: el._source.nickname, @@ -79,7 +80,7 @@ export class ArtResolver { } const result = await this.elasticsearchService.search({ - index: 'artipul09', + index: 'artipul00', from: 0, size: 500, query: { @@ -89,7 +90,7 @@ 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 { @@ -98,6 +99,7 @@ export class ArtResolver { start_price: el._source.start_price, instant_bid: el._source.instant_bid, deadline: el._source.deadline, + is_soldout: el._source.is_soldout, thumbnail: el._source.thumbnail, tag1: el._source.tag1, tag2: el._source.tag2, @@ -119,7 +121,7 @@ export class ArtResolver { } const result = await this.elasticsearchService.search({ - index: 'artipul09', + index: 'artipul00', from: 0, size: 500, query: { @@ -133,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) => { - console.log('=======', el); return { id: el._source.id, title: el._source.title, start_price: el._source.start_price, instant_bid: el._source.instant_bid, deadline: el._source.deadline, + is_soldout: el._source.is_soldout, thumbnail: el._source.thumbnail, tag1: el._source.tag1, tag2: el._source.tag2, @@ -165,7 +167,7 @@ export class ArtResolver { } const result = await this.elasticsearchService.search({ - index: 'artipul09', + index: 'artipul00', from: 0, size: 500, query: { @@ -180,7 +182,7 @@ 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 { @@ -189,6 +191,7 @@ export class ArtResolver { start_price: el._source.start_price, instant_bid: el._source.instant_bid, deadline: el._source.deadline, + is_soldout: el._source.is_soldout, thumbnail: el._source.thumbnail, tag1: el._source.tag1, tag2: el._source.tag2, diff --git a/ars/src/apis/art/art.service.ts b/ars/src/apis/art/art.service.ts index 7963b05..00aacb8 100644 --- a/ars/src/apis/art/art.service.ts +++ b/ars/src/apis/art/art.service.ts @@ -97,7 +97,6 @@ export class ArtService { skip: 10 * (page - 1), where: { user: currentUser.id, deletedAt: Not(IsNull()) }, }); - console.log(art); return art; } @@ -126,7 +125,7 @@ export class ArtService { } // 작품 등록 - async create({ image_urls, tags, ...rest }, currentUser) { + async create({ thumbnail, tags, ...rest }, currentUser) { const queryRunner = this.connection.createQueryRunner(); await queryRunner.connect(); await queryRunner.startTransaction(); @@ -134,27 +133,27 @@ export class ArtService { 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) { diff --git a/ars/src/apis/art/dto/createArtInput.ts b/ars/src/apis/art/dto/createArtInput.ts index 860beed..9db1173 100644 --- a/ars/src/apis/art/dto/createArtInput.ts +++ b/ars/src/apis/art/dto/createArtInput.ts @@ -20,8 +20,11 @@ export class CreateArtInput { @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; diff --git a/ars/src/apis/art/entities/art.entity.ts b/ars/src/apis/art/entities/art.entity.ts index 7ff338f..87b0acd 100644 --- a/ars/src/apis/art/entities/art.entity.ts +++ b/ars/src/apis/art/entities/art.entity.ts @@ -52,8 +52,8 @@ export class Art { deletedAt: Date; @Column() - @Field(() => Date) - deadline: Date; + @Field(() => String) + deadline: string; @Column({ default: false }) @Field(() => Boolean) diff --git a/ars/src/apis/art/entities/artsSearch.entity.ts b/ars/src/apis/art/entities/artsSearch.entity.ts index dd97da2..a0d06fd 100644 --- a/ars/src/apis/art/entities/artsSearch.entity.ts +++ b/ars/src/apis/art/entities/artsSearch.entity.ts @@ -20,10 +20,6 @@ export class ArtsSearch { @Field(() => Int) instant_bid: number; - @Column({ default: null }) - @Field(() => Int) - price: number; - @Column() @Field(() => String) thumbnail: string; @@ -32,6 +28,10 @@ export class ArtsSearch { @Field(() => String, { nullable: true }) deadline: string; + @Column({ default: false }) + @Field(() => Boolean) + is_soldout: boolean; + @Column() @Field(() => String) tag1: string; diff --git a/ars/src/apis/art/entities/likeArt.entity.ts b/ars/src/apis/art/entities/likeArt.entity.ts index ef20c3c..ef19738 100644 --- a/ars/src/apis/art/entities/likeArt.entity.ts +++ b/ars/src/apis/art/entities/likeArt.entity.ts @@ -1,12 +1,5 @@ import { ObjectType } from '@nestjs/graphql'; -import { User } from 'src/apis/user/entities/user.entity'; -import { - Column, - Entity, - ManyToOne, - PrimaryColumn, - PrimaryGeneratedColumn, -} from 'typeorm'; +import { Column, Entity, ManyToOne, PrimaryGeneratedColumn } from 'typeorm'; import { Art } from './art.entity'; @Entity() diff --git a/ars/src/apis/auth/auth.service.ts b/ars/src/apis/auth/auth.service.ts index c4026a9..042275a 100644 --- a/ars/src/apis/auth/auth.service.ts +++ b/ars/src/apis/auth/auth.service.ts @@ -31,23 +31,17 @@ export class AuthService { async loginOAuth(req, res) { let email = req.user.email; - console.log(email + '****************!!'); let user = await this.userService.findOne(email); - console.log('LLLLLLOOOOOO !' + user); if (!user) { const { password, ...rest } = req.user; const hashedPassword = await bcrypt.hash(String(password), 1); const createUser = { ...rest, password: hashedPassword }; user = await this.userService.create({ ...createUser }); this.setRefreshToken({ user, res }); - console.log('user created !!!'); res.redirect('https://artipul.shop/socialLogin'); - return user; } else { this.setRefreshToken({ user, res }); res.redirect('https://artipul.shop/'); - res.send(user); - return user; } } } diff --git a/ars/src/apis/board/board.service.ts b/ars/src/apis/board/board.service.ts index 9dd17b1..81640fb 100644 --- a/ars/src/apis/board/board.service.ts +++ b/ars/src/apis/board/board.service.ts @@ -3,6 +3,7 @@ import { InjectRepository } from '@nestjs/typeorm'; import { Connection, Repository } from 'typeorm'; import { BoardImage } from '../boardImage/entities/boardImage.entity'; import { Comment } from '../comment/entities/comment.entity'; +import { User } from '../user/entities/user.entity'; import { Board } from './entities/board.entity'; @Injectable() @@ -56,9 +57,13 @@ export class BoardService { await queryRunner.connect(); await queryRunner.startTransaction(); try { + const user = await queryRunner.manager.findOne(User, { + id: currentUser.id, + }); + const result = await queryRunner.manager.save(Board, { ...rest, - user: currentUser, + user: user, thumbnail: image_urls[0], }); diff --git a/ars/src/apis/board/entities/board.entity.ts b/ars/src/apis/board/entities/board.entity.ts index b8a74a5..5dd3333 100644 --- a/ars/src/apis/board/entities/board.entity.ts +++ b/ars/src/apis/board/entities/board.entity.ts @@ -31,7 +31,7 @@ export class Board { @Field(() => String) thumbnail: string; - @ManyToOne(() => User) + @ManyToOne(() => User, { eager: true }) @Field(() => User) user: User; } diff --git a/ars/src/apis/tag/entities/tag.entity.ts b/ars/src/apis/tag/entities/tag.entity.ts deleted file mode 100644 index 9ee49f1..0000000 --- a/ars/src/apis/tag/entities/tag.entity.ts +++ /dev/null @@ -1,14 +0,0 @@ -import { Field, Int, ObjectType } from '@nestjs/graphql'; -import { Column, Entity, PrimaryGeneratedColumn } from 'typeorm'; - -@Entity() -@ObjectType() -export class Tag { - @PrimaryGeneratedColumn() - @Field(() => Int) - id: number; - - @Column() - @Field(() => String) - name: string; -} diff --git a/ars/src/common/graphql/schema.gql b/ars/src/common/graphql/schema.gql index 8b41179..4cc2639 100644 --- a/ars/src/common/graphql/schema.gql +++ b/ars/src/common/graphql/schema.gql @@ -50,7 +50,7 @@ type Art { thumbnail: String! createdAt: DateTime! deletedAt: DateTime! - deadline: DateTime! + deadline: String! is_soldout: Boolean! updatedAt: DateTime! user: User! @@ -101,9 +101,9 @@ type ArtsSearch { title: String! start_price: Int! instant_bid: Int! - price: Int! thumbnail: String! deadline: String + is_soldout: Boolean! tag1: String! tag2: String tag3: String @@ -204,7 +204,7 @@ input CreateArtInput { instant_bid: Int! price: Int! deadline: DateTime - image_urls: [String!]! + thumbnail: String! is_soldout: Boolean! tags: [String!]! } From 7d4fbbb5c3285f9fbbd313cfd8fb636aeced7f99 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: Sun, 3 Apr 2022 14:23:47 +0900 Subject: [PATCH 3/6] =?UTF-8?q?[#122]feat:=20=EC=A2=8B=EC=95=84=EC=9A=94?= =?UTF-8?q?=20=EA=B8=B0=EB=8A=A5=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ars/src/apis/auth/auth.service.ts | 2 +- ars/src/apis/board/board.service.ts | 5 ++- ars/src/apis/comment/comment.service.ts | 5 ++- ars/src/apis/likeBoard/likeBoard.service.ts | 50 ++++++++++++++++----- 4 files changed, 49 insertions(+), 13 deletions(-) diff --git a/ars/src/apis/auth/auth.service.ts b/ars/src/apis/auth/auth.service.ts index 042275a..c772e74 100644 --- a/ars/src/apis/auth/auth.service.ts +++ b/ars/src/apis/auth/auth.service.ts @@ -22,7 +22,7 @@ export class AuthService { { email: user.email, sub: user.id }, { secret: process.env.REFRESH_TOKEN_KEY, expiresIn: '8h' }, ); - res.setHeader('Access-Control-Allow-Origin', 'https://artipul.shop'); + res.setHeader('Access-Control-Allow-Origin', 'http://localhost:3000'); res.setHeader( 'Set-Cookie', `refreshToken=${refreshToken}; path=/; domain=.daseul.shop; SameSite=None; Secure;httpOnly;`, diff --git a/ars/src/apis/board/board.service.ts b/ars/src/apis/board/board.service.ts index 81640fb..bfa038f 100644 --- a/ars/src/apis/board/board.service.ts +++ b/ars/src/apis/board/board.service.ts @@ -98,10 +98,13 @@ export class BoardService { await queryRunner.startTransaction(); try { const board = await queryRunner.manager.findOne(Board, { id: boardId }); + const user = await queryRunner.manager.findOne(User, { + id: currentUser.id, + }); const result = await queryRunner.manager.save(Board, { ...board, ...rest, - user: currentUser, + user: user, thumbnail: image_urls[0], }); diff --git a/ars/src/apis/comment/comment.service.ts b/ars/src/apis/comment/comment.service.ts index 2b13b9c..347942e 100644 --- a/ars/src/apis/comment/comment.service.ts +++ b/ars/src/apis/comment/comment.service.ts @@ -25,10 +25,13 @@ export class CommentService { await queryRunner.startTransaction(); try { const board = await queryRunner.manager.findOne(Board, { id: boardId }); + const user = await queryRunner.manager.findOne(User, { + id: currentUser.id, + }); const comment = await queryRunner.manager.save(Comment, { content, board, - user: currentUser, + user: user, }); await queryRunner.commitTransaction(); return comment; diff --git a/ars/src/apis/likeBoard/likeBoard.service.ts b/ars/src/apis/likeBoard/likeBoard.service.ts index 1c802cb..d56c72f 100644 --- a/ars/src/apis/likeBoard/likeBoard.service.ts +++ b/ars/src/apis/likeBoard/likeBoard.service.ts @@ -1,36 +1,66 @@ import { Injectable } from '@nestjs/common'; import { InjectRepository } from '@nestjs/typeorm'; -import { Repository } from 'typeorm'; +import { Connection, getRepository, Repository } from 'typeorm'; +import { Board } from '../board/entities/board.entity'; import { LikeBoard } from '../board/entities/likeBoard.entity'; +import { User } from '../user/entities/user.entity'; @Injectable() export class LikeBoardService { constructor( @InjectRepository(LikeBoard) private readonly likeBoardRepository: Repository, + + private readonly connection: Connection, ) {} async find(userId) { - const arts = await this.likeBoardRepository.find({ userId: userId }); - return arts.map((ele) => ele.board); + const queryRunner = this.connection.createQueryRunner(); + await queryRunner.connect(); + await queryRunner.startTransaction(); + try { + const boards = await queryRunner.manager.find(LikeBoard, { + where: { userId }, + relations: ['board'], + }); + return boards.map((ele) => ele.board); + } catch (error) { + await queryRunner.rollbackTransaction(); + throw error + 'find board!!!'; + } finally { + await queryRunner.manager.release(); + } } async like(boardId, userId) { + const queryRunner = this.connection.createQueryRunner(); + await queryRunner.connect(); + await queryRunner.startTransaction(); try { - const prevLike = await this.likeBoardRepository.findOne({ - userId: userId, - }); - if (prevLike.board !== boardId) { - await this.likeBoardRepository.save({ + const board = await queryRunner.manager.findOne(Board, { id: boardId }); + const prevLike = await queryRunner.manager.findOne(LikeBoard, { + where: { userId: userId, board: boardId, + }, + }); + if (!prevLike) { + await queryRunner.manager.save(LikeBoard, { + userId: userId, + board: board, }); + await queryRunner.commitTransaction(); + return true; } else { - await this.likeBoardRepository.delete({ userId: userId }); + await queryRunner.manager.delete(LikeBoard, { board: boardId }); + await queryRunner.commitTransaction(); + return false; } - return true; } catch (error) { + await queryRunner.rollbackTransaction(); throw error + 'like board!!!'; + } finally { + await queryRunner.manager.release(); } } From f2c4822fe8e9657a6106bfab25a5f6606a20aa2e 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: Sun, 3 Apr 2022 15:13:47 +0900 Subject: [PATCH 4/6] =?UTF-8?q?[#122]feat:=20=EC=A2=8B=EC=95=84=EC=9A=94?= =?UTF-8?q?=20=EA=B8=B0=EB=8A=A5=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ars/src/apis/likeBoard/likeBoard.service.ts | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/ars/src/apis/likeBoard/likeBoard.service.ts b/ars/src/apis/likeBoard/likeBoard.service.ts index d56c72f..88fb281 100644 --- a/ars/src/apis/likeBoard/likeBoard.service.ts +++ b/ars/src/apis/likeBoard/likeBoard.service.ts @@ -1,9 +1,7 @@ import { Injectable } from '@nestjs/common'; import { InjectRepository } from '@nestjs/typeorm'; import { Connection, getRepository, Repository } from 'typeorm'; -import { Board } from '../board/entities/board.entity'; import { LikeBoard } from '../board/entities/likeBoard.entity'; -import { User } from '../user/entities/user.entity'; @Injectable() export class LikeBoardService { @@ -17,12 +15,14 @@ export class LikeBoardService { async find(userId) { const queryRunner = this.connection.createQueryRunner(); await queryRunner.connect(); - await queryRunner.startTransaction(); + await queryRunner.startTransaction('SERIALIZABLE'); try { const boards = await queryRunner.manager.find(LikeBoard, { where: { userId }, relations: ['board'], + lock: { mode: 'pessimistic_write' }, }); + await queryRunner.commitTransaction(); return boards.map((ele) => ele.board); } catch (error) { await queryRunner.rollbackTransaction(); @@ -35,9 +35,8 @@ export class LikeBoardService { async like(boardId, userId) { const queryRunner = this.connection.createQueryRunner(); await queryRunner.connect(); - await queryRunner.startTransaction(); + await queryRunner.startTransaction('SERIALIZABLE'); try { - const board = await queryRunner.manager.findOne(Board, { id: boardId }); const prevLike = await queryRunner.manager.findOne(LikeBoard, { where: { userId: userId, @@ -47,7 +46,7 @@ export class LikeBoardService { if (!prevLike) { await queryRunner.manager.save(LikeBoard, { userId: userId, - board: board, + board: boardId, }); await queryRunner.commitTransaction(); return true; From 0ba4753f52964c2e8464ac1f570dbc1295466f7c 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: Sun, 3 Apr 2022 16:19:48 +0900 Subject: [PATCH 5/6] =?UTF-8?q?[#122]feat:=EC=A2=8B=EC=95=84=EC=9A=94=20?= =?UTF-8?q?=EA=B8=B0=EB=8A=A5=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ars/src/apis/likeBoard/likeBoard.service.ts | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/ars/src/apis/likeBoard/likeBoard.service.ts b/ars/src/apis/likeBoard/likeBoard.service.ts index 88fb281..f5955b8 100644 --- a/ars/src/apis/likeBoard/likeBoard.service.ts +++ b/ars/src/apis/likeBoard/likeBoard.service.ts @@ -1,6 +1,7 @@ import { Injectable } from '@nestjs/common'; import { InjectRepository } from '@nestjs/typeorm'; -import { Connection, getRepository, Repository } from 'typeorm'; +import { Connection, Repository } from 'typeorm'; +import { Board } from '../board/entities/board.entity'; import { LikeBoard } from '../board/entities/likeBoard.entity'; @Injectable() @@ -37,16 +38,19 @@ export class LikeBoardService { await queryRunner.connect(); await queryRunner.startTransaction('SERIALIZABLE'); try { + const board = await queryRunner.manager.findOne(Board, { id: boardId }); const prevLike = await queryRunner.manager.findOne(LikeBoard, { where: { userId: userId, board: boardId, }, + relations: ['board'], + lock: { mode: 'pessimistic_write' }, }); if (!prevLike) { await queryRunner.manager.save(LikeBoard, { userId: userId, - board: boardId, + board: board, }); await queryRunner.commitTransaction(); return true; From 09db5b34bd00783d6dd4189694e7e3b730e77a01 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 00:08:44 +0900 Subject: [PATCH 6/6] =?UTF-8?q?[#124]feat:=20=EC=9D=BC=EB=B0=98=EC=9C=A0?= =?UTF-8?q?=EC=A0=80(=EB=82=B4=EA=B0=80)=20=EA=B5=AC=EB=A7=A4=ED=95=9C=20?= =?UTF-8?q?=EC=9E=91=ED=92=88=20=EC=A1=B0=ED=9A=8C=20(fetchTransactionComp?= =?UTF-8?q?letedArts=20API)=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ars/src/apis/art/art.resolver.ts | 3 +- ars/src/apis/art/art.service.ts | 24 ++++-- ars/src/apis/art/entities/art.entity.ts | 2 +- ars/src/apis/art/entities/likeArt.entity.ts | 5 +- .../apis/payment/entities/payment.entity.ts | 4 +- ars/src/apis/user/entities/user.entity.ts | 13 +++- ars/src/common/graphql/schema.gql | 73 ++++++++++--------- 7 files changed, 75 insertions(+), 49 deletions(-) diff --git a/ars/src/apis/art/art.resolver.ts b/ars/src/apis/art/art.resolver.ts index e3b9287..5e9621f 100644 --- a/ars/src/apis/art/art.resolver.ts +++ b/ars/src/apis/art/art.resolver.ts @@ -275,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); @@ -317,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); diff --git a/ars/src/apis/art/art.service.ts b/ars/src/apis/art/art.service.ts index 00aacb8..0a1b7e4 100644 --- a/ars/src/apis/art/art.service.ts +++ b/ars/src/apis/art/art.service.ts @@ -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'; @@ -15,6 +17,12 @@ export class ArtService { @InjectRepository(ArtImage) private readonly artImageRepository: Repository, + @InjectRepository(User) + private readonly userRepository: Repository, + + @InjectRepository(Payment) + private readonly paymentRepository: Repository, + private readonly connection: Connection, ) {} @@ -115,12 +123,14 @@ 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; } diff --git a/ars/src/apis/art/entities/art.entity.ts b/ars/src/apis/art/entities/art.entity.ts index 87b0acd..262bba8 100644 --- a/ars/src/apis/art/entities/art.entity.ts +++ b/ars/src/apis/art/entities/art.entity.ts @@ -67,7 +67,7 @@ export class Art { @Field(() => User) user: User; - @OneToOne(() => Payment) + @OneToOne(() => Payment, (payment) => payment.art) @Field(() => Payment) payment: Payment; diff --git a/ars/src/apis/art/entities/likeArt.entity.ts b/ars/src/apis/art/entities/likeArt.entity.ts index ef19738..6828094 100644 --- a/ars/src/apis/art/entities/likeArt.entity.ts +++ b/ars/src/apis/art/entities/likeArt.entity.ts @@ -1,4 +1,4 @@ -import { ObjectType } from '@nestjs/graphql'; +import { Field, ObjectType } from '@nestjs/graphql'; import { Column, Entity, ManyToOne, PrimaryGeneratedColumn } from 'typeorm'; import { Art } from './art.entity'; @@ -6,11 +6,14 @@ import { Art } from './art.entity'; @ObjectType() export class LikeArt { @PrimaryGeneratedColumn() + @Field(() => String) id: string; @Column() + @Field(() => String) userId: string; @ManyToOne(() => Art, { eager: true }) + @Field(() => Art) art: Art; } diff --git a/ars/src/apis/payment/entities/payment.entity.ts b/ars/src/apis/payment/entities/payment.entity.ts index 47648ee..626e83d 100644 --- a/ars/src/apis/payment/entities/payment.entity.ts +++ b/ars/src/apis/payment/entities/payment.entity.ts @@ -27,11 +27,11 @@ export class Payment { amount: number; @JoinColumn() - @OneToOne(() => Art) + @OneToOne(() => Art, (art) => art.payment) @Field(() => Art) art: Art; - @ManyToOne(() => User, { eager: true }) + @ManyToOne(() => User, (user) => user.payment, { eager: true }) @Field(() => User) user: User; } diff --git a/ars/src/apis/user/entities/user.entity.ts b/ars/src/apis/user/entities/user.entity.ts index 2d62c35..96024de 100644 --- a/ars/src/apis/user/entities/user.entity.ts +++ b/ars/src/apis/user/entities/user.entity.ts @@ -1,6 +1,13 @@ -import { Column, Entity, OneToOne, PrimaryGeneratedColumn } from 'typeorm'; +import { + Column, + Entity, + OneToMany, + OneToOne, + PrimaryGeneratedColumn, +} from 'typeorm'; import { Field, Int, ObjectType } from '@nestjs/graphql'; import { Profile } from 'src/apis/profile/entities/profile.entity'; +import { Payment } from 'src/apis/payment/entities/payment.entity'; @Entity() @ObjectType() @@ -44,4 +51,8 @@ export class User { @OneToOne(() => Profile) @Field(() => Profile, { nullable: true }) profile?: Profile; + + @OneToMany(() => Payment, (payment) => payment.user) + @Field(() => Payment) + payment: Payment; } diff --git a/ars/src/common/graphql/schema.gql b/ars/src/common/graphql/schema.gql index 4cc2639..a389f3e 100644 --- a/ars/src/common/graphql/schema.gql +++ b/ars/src/common/graphql/schema.gql @@ -2,6 +2,40 @@ # THIS FILE WAS AUTOMATICALLY GENERATED (DO NOT MODIFY) # ------------------------------------------------------ +type Art { + id: String! + title: String! + description: String! + start_price: Int! + instant_bid: Int! + price: Int! + thumbnail: String! + createdAt: DateTime! + deletedAt: DateTime! + deadline: String! + is_soldout: Boolean! + updatedAt: DateTime! + user: User! + payment: Payment! + tag1: String! + tag2: String + tag3: String + tag4: String +} + +""" +A date-time string at UTC, such as 2019-12-03T09:54:33Z, compliant with the date-time format. +""" +scalar DateTime + +type Payment { + id: String! + createdAt: DateTime! + amount: Int! + art: Art! + user: User! +} + type User { id: String! name: String! @@ -13,6 +47,7 @@ type User { is_artist: Boolean! college: String! profile: Profile + payment: Payment! } type Profile { @@ -27,40 +62,6 @@ type Token { accessToken: String! } -type Payment { - id: String! - createdAt: DateTime! - amount: Int! - art: Art! - user: User! -} - -""" -A date-time string at UTC, such as 2019-12-03T09:54:33Z, compliant with the date-time format. -""" -scalar DateTime - -type Art { - id: String! - title: String! - description: String! - start_price: Int! - instant_bid: Int! - price: Int! - thumbnail: String! - createdAt: DateTime! - deletedAt: DateTime! - deadline: String! - is_soldout: Boolean! - updatedAt: DateTime! - user: User! - payment: Payment! - tag1: String! - tag2: String - tag3: String - tag4: String -} - type ArtImage { id: String! url: String! @@ -145,7 +146,7 @@ type Query { fetchAuctionArtsCount: Float! fetchAuctionArts(page: Float!): [Art!]! fetchTimedOutArt(page: Float!): [Art!]! - fetchTransactionCompletedArts(page: Float!): [Art!]! + fetchTransactionCompletedArts(page: Float): [Art!]! fetchEngaging(page: Float!): [Engage!]! fetchArtistWorks(artId: String!): [Art!]! fetchLikeArt(page: Float): [Art!]! @@ -170,7 +171,7 @@ type Query { type Mutation { createArt(createArtInput: CreateArtInput!): Art! uploadArtImage(files: [Upload!]!): [String!]! - addLikeArt(artId: String!): Boolean! + addLikeArt(artId: String!, likeId: String): Boolean! login(email: String!, password: String!): Token! restoreAccessToken: Token! logout: String!