-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Feat] 유저 정보 조회 API 구현 #288
Merged
Merged
Changes from all commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
cc2dd09
feat: oauthlogin 유틸 수정
simeunseo cb66913
feat: OAuth 로그인 버튼 구현
simeunseo f1e77cb
feat: 로그인 페이지 구현
simeunseo 5f77458
feat: 로그인 관련 asset 추가
simeunseo 7954c1b
feat: merge develop
simeunseo bb847cf
feat: guest login 구현
simeunseo 48de519
feat: 고양이 이미지 api 교체
simeunseo 966b9ae
feat: Dialog 내부 클릭시 이벤트 전파 방지
simeunseo 4dcbe1d
feat: 티클 리스트 Empty 뷰 렌더링 조건 변경
simeunseo 4a38514
feat: oauth 로그인시 로딩 추가
simeunseo c682390
feat: userInfoDto 생성
simeunseo f28dbc8
feat: user 프로필 조회 api 구현
simeunseo 5e35234
feat: userInfoDto 삭제
simeunseo b368592
feat: 네이밍 변경
simeunseo cfc00a9
feat: 경로 수정
simeunseo ed0b9eb
feat: user id로 유저 정보 조회 API 구현
simeunseo 3555752
feat: 티클 상세 조회 API 응답에 speakerId 추가
simeunseo d8fb59d
feat: favicon 업데이트
simeunseo 7bd2bd6
feat: 사용하지 않는 import 제거
simeunseo File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -32,13 +32,16 @@ export class AuthService { | |
|
||
async createGuestUser() { | ||
const randomNum = Math.floor(Math.random() * 10000); | ||
const response = await fetch('https://api.thecatapi.com/v1/images/search'); | ||
const catImageUrl = (await response.json())[0].url; | ||
|
||
const guestUser = { | ||
username: `guest_${randomNum}`, | ||
password: `guest_password_${randomNum}`, | ||
email: `[email protected]`, | ||
nickname: `guest_${randomNum}`, | ||
introduce: `게스트 사용자입니다. `, | ||
profileImageUrl: `https://cataas.com/cat?${Date.now()}`, | ||
profileImageUrl: catImageUrl, | ||
}; | ||
const user = await this.userService.findUserByUsername(guestUser.username); | ||
if (!user) { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,6 +7,12 @@ export class TickleDetailResponseDto { | |
}) | ||
speakerName: string; | ||
|
||
@ApiProperty({ | ||
example: 1, | ||
description: '발표자 유저 아이디', | ||
}) | ||
speakerId: number; | ||
|
||
@ApiProperty({ | ||
example: '[email protected]', | ||
description: '발표자 이메일', | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import { ApiProperty } from '@nestjs/swagger'; | ||
|
||
export class UserProfileDto { | ||
@ApiProperty({ | ||
example: '1', | ||
description: '유저 아이디', | ||
}) | ||
id: number; | ||
|
||
@ApiProperty({ | ||
example: 'simeunseo', | ||
description: '유저 닉네임', | ||
}) | ||
nickname: string; | ||
|
||
@ApiProperty({ | ||
example: 'https://avatars.githubusercontent.com/u/55528304?v=4', | ||
description: '유저 프로필 사진', | ||
}) | ||
profileImageUrl: string; | ||
|
||
@ApiProperty({ | ||
example: 'github', | ||
description: '유저 소셜 로그인 프로바이더', | ||
}) | ||
provider: string; | ||
|
||
@ApiProperty({ | ||
example: ['개발자를 위한 피그마', '야, 너도 부캠할 수 있어'], | ||
description: '유저가 개설한 티클 목록', | ||
}) | ||
ticles: string[]; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import { ApiProperty } from '@nestjs/swagger'; | ||
|
||
export class UserProfileOfMeDto { | ||
@ApiProperty({ | ||
example: '1', | ||
description: '유저 아이디', | ||
}) | ||
id: number; | ||
|
||
@ApiProperty({ | ||
example: 'simeunseo', | ||
description: '유저 닉네임', | ||
}) | ||
nickname: string; | ||
|
||
@ApiProperty({ | ||
example: 'https://avatars.githubusercontent.com/u/55528304?v=4', | ||
description: '유저 프로필 사진', | ||
}) | ||
profileImageUrl: string; | ||
|
||
@ApiProperty({ | ||
example: 'github', | ||
description: '유저 소셜 로그인 프로바이더', | ||
}) | ||
provider: string; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,22 @@ | ||
import { Controller, Get, Patch } from '@nestjs/common'; | ||
import { Controller, Get, Param, UseGuards } from '@nestjs/common'; | ||
|
||
import { JwtAuthGuard } from '@/auth/jwt/jwt-auth.guard'; | ||
import { GetUserId } from '@/common/decorator/get-userId.decorator'; | ||
|
||
import { UserService } from './user.service'; | ||
|
||
@Controller('user') | ||
export class UserController { | ||
constructor() {} | ||
constructor(private readonly userService: UserService) {} | ||
|
||
@Get('profile') | ||
getUserProfile() {} | ||
@Get('me') | ||
@UseGuards(JwtAuthGuard) | ||
async getUserProfile(@GetUserId() userId: number) { | ||
return await this.userService.findUserProfileOfMeByUserId(userId); | ||
} | ||
|
||
@Patch('profile') | ||
patchUserProfile() {} | ||
@Get(':userId') | ||
async patchUserProfile(@Param('userId') userId: number) { | ||
return await this.userService.findUserProfileByUserId(userId); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
import { ConflictException, Injectable } from '@nestjs/common'; | ||
import { ConflictException, Injectable, NotFoundException } from '@nestjs/common'; | ||
import { InjectRepository } from '@nestjs/typeorm'; | ||
import * as bcrypt from 'bcrypt'; | ||
import { Repository } from 'typeorm'; | ||
|
@@ -8,6 +8,8 @@ | |
|
||
import { CreateLocalUserDto } from './dto/createLocalUser.dto'; | ||
import { CreateSocialUserDto } from './dto/createSocialUser.dto'; | ||
import { UserProfileDto } from './dto/userProfileDto'; | ||
import { UserProfileOfMeDto } from './dto/userProfileOfMeDto'; | ||
|
||
@Injectable() | ||
export class UserService { | ||
|
@@ -24,7 +26,7 @@ | |
password: hashedPassword, | ||
}); | ||
await this.userRepository.save(user); | ||
const { password, ...result } = user; | ||
return result; | ||
} | ||
|
||
|
@@ -64,4 +66,39 @@ | |
} | ||
return user; | ||
} | ||
|
||
async findUserProfileOfMeByUserId(userId: number): Promise<UserProfileOfMeDto> { | ||
const user = await this.userRepository.findOne({ | ||
where: { id: userId }, | ||
select: ['id', 'nickname', 'profileImageUrl', 'provider'], | ||
}); | ||
|
||
if (!user) { | ||
throw new NotFoundException(ErrorMessage.USER_NOT_FOUND); | ||
} | ||
|
||
return user; | ||
} | ||
|
||
async findUserProfileByUserId(userId: number): Promise<UserProfileDto> { | ||
const user = await this.userRepository | ||
.createQueryBuilder('user') | ||
.leftJoin('user.ticles', 'ticles') | ||
.addSelect('ticles.title') | ||
.where('user.id = :userId', { userId: userId }) | ||
.getOne(); | ||
|
||
if (!user) { | ||
throw new NotFoundException(ErrorMessage.USER_NOT_FOUND); | ||
} | ||
|
||
const ticles = user.ticles || []; | ||
return { | ||
id: user.id, | ||
nickname: user.nickname, | ||
profileImageUrl: user.profileImageUrl, | ||
provider: user.provider, | ||
ticles: ticles.map((ticle) => ticle.title), | ||
}; | ||
Comment on lines
+96
to
+102
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. p5: |
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,15 +2,19 @@ | |
<html lang="ko"> | ||
<head> | ||
<meta charset="UTF-8" /> | ||
<link rel="icon" type="image/svg+xml" href="/vite.svg" /> | ||
<link rel="icon" type="image/svg+xml" href="/favicon.png" /> | ||
<link | ||
rel="stylesheet" | ||
as="style" | ||
crossorigin | ||
href="https://cdn.jsdelivr.net/gh/orioncactus/[email protected]/dist/web/static/pretendard-dynamic-subset.min.css" | ||
/> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0" /> | ||
<title>Ticle</title> | ||
<meta | ||
name="Description" | ||
content="작은 지식이 모여 큰 성장이 되는 곳 - 실시간 지식 공유 플랫폼 TICLE" | ||
/> | ||
<title>TICLE</title> | ||
</head> | ||
<body> | ||
<div id="root"></div> | ||
|
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Q:
TypeORM
의find({relations})
와 동일한 결과 값을 반환할 것 같은데 queryBuilder를 사용하신 이유가 있을까요?