Skip to content

Commit

Permalink
[#120]feat: 찜 기능 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
Arios67 committed Apr 2, 2022
1 parent 3c0182b commit 53705e6
Show file tree
Hide file tree
Showing 8 changed files with 62 additions and 32 deletions.
5 changes: 4 additions & 1 deletion ars/docker-compose.dev.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,17 @@ version: '3.3'

services:
my_backend:
platform: linux/x86_64
image: asia.gcr.io/artiful-a1/my_backend:2.0
build:
context: .
dockerfile: Dockerfile
env_file:
- ./.env.dev
ports:
- 3000:3000
volumes:
- ./src:/myfolder/src
- ./.env:/myfolder/.env

my_database:
platform: linux/x86_64
Expand Down
2 changes: 1 addition & 1 deletion ars/docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ services:
cap_add:
- SYS_NICE
ports:
- 3307:3306
- 3306:3306

my_redis:
image: redis:6.2.6
Expand Down
5 changes: 3 additions & 2 deletions ars/src/apis/art/entities/likeArt.entity.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ObjectType } from '@nestjs/graphql';
import { Field, ObjectType } from '@nestjs/graphql';
import { User } from 'src/apis/user/entities/user.entity';
import {
Column,
Expand All @@ -13,11 +13,12 @@ import { Art } from './art.entity';
@ObjectType()
export class LikeArt {
@PrimaryGeneratedColumn()
@Field(() => String)
id: string;

@Column()
userId: string;

@ManyToOne(() => Art, { eager: true })
@ManyToOne(() => Art)
art: Art;
}
9 changes: 2 additions & 7 deletions ars/src/apis/auth/auth.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,23 +31,18 @@ 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) {

if (!user || !user.phoneNum) {
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;
}
}
}
6 changes: 5 additions & 1 deletion ars/src/apis/board/board.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -56,9 +57,12 @@ 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],
});

Expand Down
59 changes: 42 additions & 17 deletions ars/src/apis/likeArt/likeArt.service.ts
Original file line number Diff line number Diff line change
@@ -1,49 +1,74 @@
import { Injectable } from '@nestjs/common';
import { InjectRepository } from '@nestjs/typeorm';
import { Repository } from 'typeorm';
import { Connection, Like, Repository } from 'typeorm';
import { Art } from '../art/entities/art.entity';
import { LikeArt } from '../art/entities/likeArt.entity';

@Injectable()
export class LikeArtService {
constructor(
@InjectRepository(LikeArt)
private readonly likeArtRepository: Repository<LikeArt>,

private readonly connection: Connection,
) {}

async find(userId, page) {
let arts = [];
if (page) {
arts = await this.likeArtRepository.find({
take: 10,
skip: 10 * (page - 1),
where: { userId: userId },
});
} else {
arts = await this.likeArtRepository.find({ userId });
const queryRunner = this.connection.createQueryRunner();
await queryRunner.connect();
await queryRunner.startTransaction();
try {
let arts = [];
if (page) {
arts = await queryRunner.manager.find(Art, {
take: 10,
skip: 10 * (page - 1),
where: { userId: userId },
});
} else {
arts = await queryRunner.manager.find(LikeArt, {
where: { userId },
relations: ['art'],
});
}
return arts.map((ele) => ele.art);
} catch (error) {
await queryRunner.rollbackTransaction();
throw error + 'like art!!!';
} finally {
await queryRunner.release();
}

return arts.map((ele) => ele.art);
}

async like(artId, userId) {
const queryRunner = this.connection.createQueryRunner();
await queryRunner.connect();
await queryRunner.startTransaction();
try {
const prevLike = await this.likeArtRepository.findOne({
const art = await queryRunner.manager.findOne(Art, { id: artId });
const prevLike = await queryRunner.manager.findOne(LikeArt, {
where: {
userId: userId,
art: artId,
},
});
if (!prevLike) {
await this.likeArtRepository.save({
await queryRunner.manager.save(LikeArt, {
userId: userId,
art: artId,
art: art,
});
await queryRunner.commitTransaction();
return true;
} else {
await this.likeArtRepository.delete({ art: artId });
await queryRunner.manager.delete(LikeArt, { art: artId });
await queryRunner.commitTransaction();
return false;
}
return true;
} catch (error) {
await queryRunner.rollbackTransaction();
throw error + 'like art!!!';
} finally {
await queryRunner.release();
}
}
}
6 changes: 3 additions & 3 deletions ars/src/apis/payment/payment.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,16 +64,16 @@ export class PaymentService {
});

// 유저 누적 포인트 업데이트
const updated = await queryRunner.manager.save(User, {
const updatedUser = await queryRunner.manager.save(User, {
...bidder,
point: bidder.point - price,
});

// 히스토리 테이블(낙찰자) 저장
await queryRunner.manager.save(History, {
point: price,
balance: updated.point,
user: updated,
balance: updatedUser.point,
user: updatedUser,
payment: payment,
});

Expand Down
2 changes: 2 additions & 0 deletions ars/src/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import { ProfileModule } from './apis/profile/profile.module';
import { HistoryModule } from './apis/history/history.module';
import { ScheduleModule } from '@nestjs/schedule';
import { PaymentModule } from './apis/payment/payment.module';
import { setgroups } from 'process';

@Module({
imports: [
Expand Down Expand Up @@ -47,6 +48,7 @@ import { PaymentModule } from './apis/payment/payment.module';
entities: [__dirname + '/apis/**/*.entity.*'],
synchronize: true,
logging: true,
timezone: 'Asia/seoul',
}),
CacheModule.register<RedisClientOptions>({
store: redisStore,
Expand Down

0 comments on commit 53705e6

Please sign in to comment.