Skip to content

Commit

Permalink
Merge branch 'develop' into feat/#79
Browse files Browse the repository at this point in the history
  • Loading branch information
Daseul1 authored Mar 31, 2022
2 parents 4339268 + ed9372a commit bbe3873
Show file tree
Hide file tree
Showing 25 changed files with 467 additions and 133 deletions.
6 changes: 6 additions & 0 deletions ars/src/apis/art/art.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@ import { Module } from '@nestjs/common';
import { ElasticsearchModule } from '@nestjs/elasticsearch';
import { TypeOrmModule } from '@nestjs/typeorm';
import { ArtImage } from '../artImage/entities/artImage.entity';
import { Engage } from '../engage/entities/engage.entity';
import { FileService } from '../file/file.service';
import { LikeArtService } from '../likeArt/likeArt.service';
import { Payment } from '../payment/entities/payment.entity';
import { PaymentService } from '../payment/payment.service';
import { User } from '../user/entities/user.entity';
import { ArtResolver } from './art.resolver';
import { ArtService } from './art.service';
Expand All @@ -17,6 +20,8 @@ import { LikeArt } from './entities/likeArt.entity';
ArtImage,
LikeArt,
User,
Payment,
Engage,
]),
ElasticsearchModule.register({
node: 'http://elasticsearch:9200',
Expand All @@ -27,6 +32,7 @@ import { LikeArt } from './entities/likeArt.entity';
ArtService,
FileService,
LikeArtService,
PaymentService,
],
})
export class ArtModule {}
83 changes: 67 additions & 16 deletions ars/src/apis/art/art.resolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@ import { FileUpload, GraphQLUpload } from 'graphql-upload';
import { GqlAuthAccessGuard } from 'src/common/auth/gql-auth.guard';
import { CurrentUser, ICurrentUser } from 'src/common/auth/gql-user.param';
import { ArtImage } from '../artImage/entities/artImage.entity';
import { Engage } from '../engage/entities/engage.entity';
import { FileService } from '../file/file.service';
import { LikeArtService } from '../likeArt/likeArt.service';
import { PaymentService } from '../payment/payment.service';
import { ArtService } from './art.service';
import { CreateArtInput } from './dto/createArtInput';
import { Art } from './entities/art.entity';
Expand All @@ -23,6 +25,7 @@ export class ArtResolver {

@Inject(CACHE_MANAGER)
private readonly cacheManager: Cache,
private readonly paymentService: PaymentService,
) {}

@Query(() => [Art])
Expand Down Expand Up @@ -90,27 +93,82 @@ export class ArtResolver {
async fetchArtImages(@Args('artId') artId: string) {
return await this.artService.findImages({ artId });
}
///////////////////////////////////////////////////////////////////////////
@UseGuards(GqlAuthAccessGuard)
@Query(() => Number)
async fetchEngageCount(@CurrentUser() currentUser: ICurrentUser) {
return await this.artService.countEngage(currentUser.id);
}

@UseGuards(GqlAuthAccessGuard)
@Query(() => Number)
async fetchLikeArtCount(@CurrentUser() currentUser: ICurrentUser) {
return await this.artService.countLikeArt(currentUser.id);
}

@UseGuards(GqlAuthAccessGuard)
@Query(() => Number)
async fetchSoldoutArtsCount(@CurrentUser() currentUser: ICurrentUser) {
return await this.artService.countComletedAuctionArts(currentUser.id);
}

@UseGuards(GqlAuthAccessGuard)
@Query(() => Number)
async fetchTimedOutArtsCount(@CurrentUser() currentUser: ICurrentUser) {
return await this.artService.countTimedoutArts(currentUser.id);
}

@UseGuards(GqlAuthAccessGuard)
@Query(() => Number)
async fetchAuctionArtsCount(@CurrentUser() currentUser: ICurrentUser) {
return await this.artService.countAuctionArts(currentUser.id);
}
//////////////////////////////////////////////////////////////////////////

// 미대생이 판매중인 작품 조회
@UseGuards(GqlAuthAccessGuard)
@Query(() => [Art])
async fetchAuctionArts(@CurrentUser() currentUser: ICurrentUser) {
return await this.artService.findAuction({ currentUser });
async fetchAuctionArts(
@Args('page') page: number,
@CurrentUser() currentUser: ICurrentUser,
) {
return await this.artService.findAuction({ currentUser }, page);
}

// 미대생 마감된 작품 조회
@UseGuards(GqlAuthAccessGuard)
async fetchTimedOutArt(@CurrentUser() currentUser: ICurrentUser) {
return await this.artService.fetchTimedOutArt(currentUser);
@Query(() => [Art])
async fetchTimedOutArt(
@Args('page') page: number,
@CurrentUser() currentUser: ICurrentUser,
) {
return await this.artService.fetchTimedOutArt(currentUser, page);
}

// 일반유저(내가) 구매한 작품 조회
@UseGuards(GqlAuthAccessGuard)
@Query(() => [Art])
async fetchtransactioncompletedArts(
async fetchTransactionCompletedArts(
@Args('page') page: number,
@CurrentUser() currentUser: ICurrentUser,
) {
return await this.artService.findcompleteAuction({ currentUser }, page);
}

// 일반유저(내가) 경매 참여 중인 작품 조회
@UseGuards(GqlAuthAccessGuard)
@Query(() => [Engage])
async fetchEngaging(
@Args('page') page: number,
@CurrentUser() currentUser: ICurrentUser,
) {
return await this.artService.findcompleteAuction({ currentUser });
return await this.paymentService.findEngage(currentUser.id, page);
}

// 작품id로 해당 작가의 모든 작품 조회
@Query(() => [Art])
async fetchArtistWorks(@Args('artId') artId: string) {
return await this.artService.findArtistWorks(artId);
}

@UseGuards(GqlAuthAccessGuard)
Expand Down Expand Up @@ -150,17 +208,10 @@ export class ArtResolver {

@UseGuards(GqlAuthAccessGuard)
@Query(() => [Art])
async fetchLikeArt(@CurrentUser() currentUser: ICurrentUser) {
return await this.likeArtService.find(currentUser.id);
}

@UseGuards(GqlAuthAccessGuard)
@Mutation(() => [String])
async Bid(
@Args('artId') artId: string,
@Args('bid_price') bid_price: number,
async fetchLikeArt(
@Args('page') page: number,
@CurrentUser() currentUser: ICurrentUser,
) {
return await this.artService.call(artId, bid_price, currentUser.email);
return await this.likeArtService.find(currentUser.id, page);
}
}
100 changes: 83 additions & 17 deletions ars/src/apis/art/art.service.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { CACHE_MANAGER, Inject, Injectable } from '@nestjs/common';
import { Cache } from 'cache-manager';
import { Injectable } from '@nestjs/common';
import { InjectRepository } from '@nestjs/typeorm';
import { Connection, getRepository, MoreThan, Not, Repository } from 'typeorm';
import { Connection, IsNull, MoreThan, Not, Repository } from 'typeorm';
import { ArtImage } from '../artImage/entities/artImage.entity';
import { Engage } from '../engage/entities/engage.entity';
import { Art } from './entities/art.entity';
import { LikeArt } from './entities/likeArt.entity';

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

@Inject(CACHE_MANAGER)
private readonly cacheManager: Cache,

private readonly connection: Connection,
) {}

Expand All @@ -25,7 +23,6 @@ export class ArtService {
await queryRunner.connect();
await queryRunner.startTransaction();
try {
const qb = getRepository(Art).createQueryBuilder('art');
const num = tags.length;
let result = [];

Expand Down Expand Up @@ -95,27 +92,46 @@ export class ArtService {
}

// 미대생이 판매중인 작품 조회
async findAuction({ currentUser }) {
async findAuction({ currentUser }, page) {
const art = await this.artRepository.find({
take: 10,
skip: 10 * (page - 1),
where: { user: currentUser.id, is_soldout: false },
});
return art;
}

// 미대생 마감된 작품 조회
async fetchTimedOutArt(currentUser) {
async fetchTimedOutArt(currentUser, page) {
const art = await this.artRepository.find({
withDeleted: true,
where: { user: currentUser.id, deletedAt: Not(null) },
take: 10,
skip: 10 * (page - 1),
where: { user: currentUser.id, deletedAt: Not(IsNull()) },
});
console.log(art);
return art;
}

// 작품Id로 해당 작가 모든 작품검색
async findArtistWorks(artId) {
const art = await this.artRepository.findOne({
withDeleted: true,
where: { id: artId },
});
const user = art.user;
return await this.artRepository.find({
withDeleted: true,
where: { user: user },
});
}

// 일반유저(내가) 구매한 작품 조회
async findcompleteAuction({ currentUser }) {
async findcompleteAuction({ currentUser }, page) {
const art = await this.artRepository.find({
withDeleted: true,
relations: ['user'],
take: 10,
skip: 10 * (page - 1),
where: { user: currentUser.id, is_soldout: true },
});
return art;
Expand Down Expand Up @@ -151,7 +167,42 @@ export class ArtService {
});
}
}
await queryRunner.commitTransaction();
return result;
} catch (error) {
await queryRunner.rollbackTransaction();
throw error + 'Art create !';
} finally {
await queryRunner.manager.release();
}
}
///////////////////////////////////////////////////////////////////////////
async countEngage(userId) {
const queryRunner = this.connection.createQueryRunner();
await queryRunner.connect();
await queryRunner.startTransaction();
try {
const result = await queryRunner.manager.count(Engage, {
userId: userId,
});
await queryRunner.commitTransaction();
return result;
} catch (error) {
await queryRunner.rollbackTransaction();
throw error + 'Art create !';
} finally {
await queryRunner.manager.release();
}
}

async countLikeArt(userId) {
const queryRunner = this.connection.createQueryRunner();
await queryRunner.connect();
await queryRunner.startTransaction();
try {
const result = await queryRunner.manager.count(LikeArt, {
userId: userId,
});
await queryRunner.commitTransaction();
return result;
} catch (error) {
Expand All @@ -162,12 +213,27 @@ export class ArtService {
}
}

// 야매 입찰
async call(artId, bid_price, email) {
await this.cacheManager.set(artId, [bid_price, email], {
ttl: 180,
async countComletedAuctionArts(userId) {
const result = await this.artRepository.count({
withDeleted: true,
where: { user: userId, is_soldout: true },
});
return result;
}

async countTimedoutArts(userId) {
const result = await this.artRepository.count({
withDeleted: true,
where: { user: userId, deletedAt: Not(IsNull()) },
});
return result;
}

return [bid_price, email];
async countAuctionArts(userId) {
const result = await this.artRepository.find({
where: { user: userId, is_soldout: false },
});
return result;
}
///////////////////////////////////////////////////////////////////////////
}
4 changes: 2 additions & 2 deletions ars/src/apis/art/dto/createArtInput.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ export class CreateArtInput {
@Field(() => Int)
price: number;

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

@Field(() => [String])
image_urls: string[];
Expand Down
10 changes: 7 additions & 3 deletions ars/src/apis/art/entities/art.entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,15 @@ export class Art {

@CreateDateColumn()
@Field(() => Date)
createdAt: string;
createdAt: Date;

@DeleteDateColumn()
@Field(() => Date)
deletedAt: Date;

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

@Column({ default: false })
@Field(() => Boolean)
Expand Down
6 changes: 3 additions & 3 deletions ars/src/apis/auth/auth.resolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,12 @@ export class AuthResolver {
@Args('password') password: string,
@Context() context: any,
) {
const user = await this.userService.findOAuthUser({ email });
const user = await this.userService.findOne(email);
if (!user)
// 이메일 체크
throw new UnprocessableEntityException();
throw new UnprocessableEntityException('이메일이 올바르지 않습니다.');
const isAuth = await bcrypt.compare(password, user.password);
if (!isAuth) throw new UnauthorizedException();
if (!isAuth) throw new UnauthorizedException('비밀번호가 틀렸습니다.');

this.authService.setRefreshToken({ user, res: context.res });

Expand Down
1 change: 0 additions & 1 deletion ars/src/apis/auth/auth.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ export class AuthService {

if (!user) {
const { password, ...rest } = req.user;
console.log(password, '비밀번호');
const hashedPassword = await bcrypt.hash(String(password), 1);
const createUser = { ...rest, password: hashedPassword };
user = await this.userService.create({ ...createUser });
Expand Down
17 changes: 17 additions & 0 deletions ars/src/apis/engage/entities/engage.entity.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { Field, ObjectType } from '@nestjs/graphql';
import { Art } from 'src/apis/art/entities/art.entity';
import { Column, Entity, ManyToOne, PrimaryGeneratedColumn } from 'typeorm';

@Entity()
@ObjectType()
export class Engage {
@PrimaryGeneratedColumn()
id: string;

@Column()
userId: string;

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

0 comments on commit bbe3873

Please sign in to comment.