Skip to content

Commit

Permalink
Merge pull request #261 from boostcampwm2023/feat/260-purchase-premiu…
Browse files Browse the repository at this point in the history
…m-get-api

[Feat] 광고 제거 구매 여부 API 구현
  • Loading branch information
JoonSoo-Kim authored Dec 11, 2023
2 parents 22d62c9 + 852d25e commit b0a9f09
Show file tree
Hide file tree
Showing 13 changed files with 36 additions and 43 deletions.
4 changes: 2 additions & 2 deletions BE/src/auth/auth.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export class AuthController {
const loginResponseDto: LoginResponseDto =
await this.authService.kakaoSignIn(user, request);
return {
url: `${process.env.FRONTEND_URL}?access-token=${loginResponseDto.accessToken}&nickname=${loginResponseDto.nickname}&premium=${loginResponseDto.premium}`,
url: `${process.env.FRONTEND_URL}?access-token=${loginResponseDto.accessToken}&nickname=${loginResponseDto.nickname}`,
};
}

Expand All @@ -49,7 +49,7 @@ export class AuthController {
const loginResponseDto: LoginResponseDto =
await this.authService.naverSignIn(user, request);
return {
url: `${process.env.FRONTEND_URL}?access-token=${loginResponseDto.accessToken}&nickname=${loginResponseDto.nickname}&premium=${loginResponseDto.premium}`,
url: `${process.env.FRONTEND_URL}?access-token=${loginResponseDto.accessToken}&nickname=${loginResponseDto.nickname}`,
};
}

Expand Down
16 changes: 8 additions & 8 deletions BE/src/auth/auth.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@ export class AuthService {
throw new NotFoundException("올바르지 않은 비밀번호입니다.");
}

const { nickname, premium } = user;
const { nickname } = user;
const accessToken = await this.createUserTokens(userId, requestIp);
return new LoginResponseDto(accessToken, nickname, premium);
return new LoginResponseDto(accessToken, nickname);
}

async signOut(user: User): Promise<void> {
Expand All @@ -62,15 +62,15 @@ export class AuthService {

const userId = expiredResult.userId;

const { nickname, premium } = await User.findOne({
const { nickname } = await User.findOne({
where: { userId },
});
const accessToken = await this.createUserTokens(userId, requestIp);
return new LoginResponseDto(accessToken, nickname, premium);
return new LoginResponseDto(accessToken, nickname);
}

async naverSignIn(user: User, request: Request): Promise<LoginResponseDto> {
const { userId, nickname, premium } = user;
const { userId, nickname } = user;
const provider = providerEnum.NAVER;
const requestIp = request.headers["x-forwarded-for"]
? (request.headers["x-forwarded-for"] as string)
Expand All @@ -81,11 +81,11 @@ export class AuthService {
}

const accessToken = await this.createUserTokens(userId, requestIp);
return new LoginResponseDto(accessToken, nickname, premium);
return new LoginResponseDto(accessToken, nickname);
}

async kakaoSignIn(user: User, request: Request): Promise<LoginResponseDto> {
const { userId, nickname, premium } = user;
const { userId, nickname } = user;
const provider = providerEnum.KAKAO;
const requestIp = request.headers["x-forwarded-for"]
? (request.headers["x-forwarded-for"] as string)
Expand All @@ -96,7 +96,7 @@ export class AuthService {
}

const accessToken = await this.createUserTokens(userId, requestIp);
return new LoginResponseDto(accessToken, nickname, premium);
return new LoginResponseDto(accessToken, nickname);
}

private async createUserTokens(
Expand Down
2 changes: 1 addition & 1 deletion BE/src/auth/dto/auth-credential.dto.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { IsNotEmpty, IsString, Length, Matches } from "class-validator";
import { IsNotEmpty, IsString, Matches } from "class-validator";

export class AuthCredentialsDto {
@IsNotEmpty({ message: "유저 아이디는 비어있지 않아야 합니다." })
Expand Down
6 changes: 1 addition & 5 deletions BE/src/auth/dto/login-response.dto.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
import { premiumStatus } from "src/utils/enum";

export class LoginResponseDto {
accessToken: string;
nickname: string;
premium: premiumStatus;

constructor(accessToken: string, nickname: string, premium: premiumStatus) {
constructor(accessToken: string, nickname: string) {
this.accessToken = accessToken;
this.nickname = nickname;
this.premium = premium;
}
}
8 changes: 1 addition & 7 deletions BE/src/auth/dto/users.dto.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,4 @@
import {
IsString,
Length,
MaxLength,
Matches,
IsNotEmpty,
} from "class-validator";
import { IsString, MaxLength, Matches, IsNotEmpty } from "class-validator";

export class CreateUserDto {
@IsNotEmpty({ message: "아이디는 비어있지 않아야 합니다." })
Expand Down
1 change: 0 additions & 1 deletion BE/src/auth/guard/auth.jwt-guard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import {
UnauthorizedException,
} from "@nestjs/common";
import { AuthGuard as NestAuthGuard } from "@nestjs/passport";
import { access } from "fs";
import * as jwt from "jsonwebtoken";
import { Redis } from "ioredis";
import { InjectRedis } from "@liaoliaots/nestjs-redis";
Expand Down
2 changes: 1 addition & 1 deletion BE/src/purchase/dto/purchase.design.dto.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { IsEnum, IsIn, IsNotEmpty } from "class-validator";
import { IsIn, IsNotEmpty } from "class-validator";
import { designEnum, domainEnum } from "src/utils/enum";

export class PurchaseDesignDto {
Expand Down
9 changes: 9 additions & 0 deletions BE/src/purchase/dto/purchase.premium.dto.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { premiumStatus } from "src/utils/enum";

export class PremiumDto {
premium: premiumStatus;

constructor(premium: premiumStatus) {
this.premium = premium;
}
}
6 changes: 6 additions & 0 deletions BE/src/purchase/purchase.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { PurchaseDesignDto, PurchaseListDto } from "./dto/purchase.design.dto";
import { GetUser } from "src/auth/get-user.decorator";
import { User } from "src/auth/users.entity";
import { CreditDto } from "./dto/purchase.credit.dto";
import { PremiumDto } from "./dto/purchase.premium.dto";

@Controller("purchase")
@UseGuards(JwtAuthGuard)
Expand Down Expand Up @@ -41,4 +42,9 @@ export class PurchaseController {
async purchasePremium(@GetUser() user: User): Promise<CreditDto> {
return this.purchaseService.purchasePremium(user);
}

@Get("/premium")
async getPremiumStatus(@GetUser() user: User): Promise<PremiumDto> {
return this.purchaseService.getPremiumStatus(user);
}
}
5 changes: 5 additions & 0 deletions BE/src/purchase/purchase.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { PurchaseRepository } from "./purchase.repository";
import { Purchase } from "./purchase.entity";
import { designEnum, domainEnum, premiumStatus } from "src/utils/enum";
import { CreditDto } from "./dto/purchase.credit.dto";
import { PremiumDto } from "./dto/purchase.premium.dto";

@Injectable()
export class PurchaseService {
Expand Down Expand Up @@ -88,4 +89,8 @@ export class PurchaseService {
result["sky"] = skyPurchase;
return result;
}

async getPremiumStatus(user: User): Promise<PremiumDto> {
return new PremiumDto(user.premium);
}
}
7 changes: 0 additions & 7 deletions BE/src/tags/tags.controller.ts

This file was deleted.

6 changes: 2 additions & 4 deletions BE/src/tags/tags.module.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
import { Module } from "@nestjs/common";
import { TagsController } from "./tags.controller";
import { TagsService } from "./tags.service";
import { TagsRepository } from "./tags.repository";
import { Tag } from "./tags.entity";
import { TypeOrmModule } from "@nestjs/typeorm";

@Module({
imports: [TypeOrmModule.forFeature([Tag])],
controllers: [TagsController],
providers: [TagsService, TagsRepository],
controllers: [],
providers: [TagsRepository],
exports: [TagsRepository],
})
export class TagsModule {}
7 changes: 0 additions & 7 deletions BE/src/tags/tags.service.ts

This file was deleted.

0 comments on commit b0a9f09

Please sign in to comment.