Skip to content

Commit

Permalink
Merge pull request #61 from boostcampwm2023/feature/be-mypage
Browse files Browse the repository at this point in the history
마이페이지 api 추가 분리
  • Loading branch information
GeunH authored Nov 19, 2023
2 parents cce2e36 + d8b64fe commit 2159921
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 12 deletions.
4 changes: 2 additions & 2 deletions be/src/auth/strategy/jwt.strategy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ export class JwtStrategy extends PassportStrategy(Strategy) {
}

async validate(payload: any) {
const { nickName } = payload;
const { id } = payload;

return { nickName };
return { id };
}
}
27 changes: 19 additions & 8 deletions be/src/user/user.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,20 @@ import { AuthGuard } from "@nestjs/passport";
export class UserController {
constructor(private userService: UserService) { }

@Get()
@UseGuards(AuthGuard("jwt"))
@ApiBearerAuth()
@ApiOperation({ summary: "마이페이지 유저 수정페이지 정보 가져오기" })
@ApiResponse({
status: 200,
description: "마이페이지 수정페이지 정보 요청 성공",
})
@ApiResponse({ status: 401, description: "인증 실패" })
@ApiResponse({ status: 400, description: "부적절한 요청" })
async getMypageUserDetailInfo(@GetUser() tokenInfo: TokenInfo) {
return await this.userService.getMypageUserDetailInfo(tokenInfo);
}

@Get(":nickname/details")
@UseGuards(AuthGuard("jwt"))
@ApiBearerAuth()
Expand All @@ -42,18 +56,15 @@ export class UserController {
return await this.userService.getUserInfo(nickname);
}

@Get()
@Get("/details")
@UseGuards(AuthGuard("jwt"))
@ApiBearerAuth()
@ApiOperation({ summary: "마이페이지 유저 수정페이지 정보 가져오기" })
@ApiResponse({
status: 200,
description: "마이페이지 수정페이지 정보 요청 성공",
})
@ApiOperation({ summary: "마이페이지 유저 정보 가져오기" })
@ApiResponse({ status: 200, description: "마이페이지 정보 요청 성공" })
@ApiResponse({ status: 401, description: "인증 실패" })
@ApiResponse({ status: 400, description: "부적절한 요청" })
async getMypageUserDetailInfo(@GetUser() tokenInfo: TokenInfo) {
return await this.userService.getMypageUserDetailInfo(tokenInfo);
async getMypageUserInfo(@GetUser() tokenInfo: TokenInfo) {
return await this.userService.getMypageUserInfo(tokenInfo);
}

@Get("nickname/:nickname/exists")
Expand Down
12 changes: 10 additions & 2 deletions be/src/user/user.repository.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { DataSource, Repository } from "typeorm";
import { DataSource, IsNull, Repository, Not } from "typeorm";
import { User } from "./entities/user.entity";
import { UserInfoDto } from "./dto/userInfo.dto";
import { ConflictException, Injectable } from "@nestjs/common";


@Injectable()
export class UserRepository extends Repository<User> {
constructor(private dataSource: DataSource) {
Expand Down Expand Up @@ -33,10 +34,17 @@ export class UserRepository extends Repository<User> {
});
return { isexist: user !== null };
}
async getMypageUserInfo(id: number) {
const userInfo = await this.findOne({
select: ["nickName", "birthdate", "isMale", "region"],
where: { id: id },
});
return { userInfo: userInfo };
}
async getUserInfo(nickName: UserInfoDto["nickName"]) {
const userInfo = await this.findOne({
select: ["nickName", "birthdate", "isMale", "region"],
where: { nickName: nickName },
where: { nickName: nickName, deleted_at: IsNull() },
});
return { userInfo: userInfo };
}
Expand Down
3 changes: 3 additions & 0 deletions be/src/user/user.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ export class UserService {
async getEmailAvailability(email: UserInfoDto["email"]) {
return await this.usersRepository.getEmailAvailability(email);
}
async getMypageUserInfo(tokenInfo: TokenInfo) {
return await this.usersRepository.getMypageUserInfo(tokenInfo.id);
}
async getUserInfo(nickName: UserInfoDto["nickName"]) {
return await this.usersRepository.getUserInfo(nickName);
}
Expand Down

0 comments on commit 2159921

Please sign in to comment.