From 7363ec154d995503dc843f842cbdf24dd672f7ed Mon Sep 17 00:00:00 2001 From: HeoSeokMun Date: Sat, 16 Dec 2023 15:27:42 +0900 Subject: [PATCH] =?UTF-8?q?feat:=20=EB=82=B4=20=EC=A0=95=EB=B3=B4=20?= =?UTF-8?q?=EA=B0=80=EC=A0=B8=EC=98=A4=EA=B8=B0=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/UserController.kt | 7 +++++++ .../dto/response/UserInfoResponseDto.kt | 19 +++++++++++++++++++ .../ssudateserver/service/UserService.kt | 19 +++++++++++++++++++ 3 files changed, 45 insertions(+) create mode 100644 src/main/kotlin/com/yourssu/ssudateserver/dto/response/UserInfoResponseDto.kt diff --git a/src/main/kotlin/com/yourssu/ssudateserver/controller/UserController.kt b/src/main/kotlin/com/yourssu/ssudateserver/controller/UserController.kt index cba5768..2045696 100644 --- a/src/main/kotlin/com/yourssu/ssudateserver/controller/UserController.kt +++ b/src/main/kotlin/com/yourssu/ssudateserver/controller/UserController.kt @@ -8,6 +8,7 @@ import com.yourssu.ssudateserver.dto.request.UpdateMaleRequestDto import com.yourssu.ssudateserver.dto.response.RefreshTokenResponseDto import com.yourssu.ssudateserver.dto.response.RegisterResponseDto import com.yourssu.ssudateserver.dto.response.UpdateResponseDto +import com.yourssu.ssudateserver.dto.response.UserInfoResponseDto import com.yourssu.ssudateserver.dto.security.UserPrincipal import com.yourssu.ssudateserver.enums.Animals import com.yourssu.ssudateserver.enums.FemaleAnimals @@ -16,6 +17,7 @@ import com.yourssu.ssudateserver.enums.MaleAnimals import com.yourssu.ssudateserver.exception.logic.AllCanNotRegisterException import com.yourssu.ssudateserver.service.UserService import org.springframework.security.core.annotation.AuthenticationPrincipal +import org.springframework.web.bind.annotation.GetMapping import org.springframework.web.bind.annotation.PatchMapping import org.springframework.web.bind.annotation.PostMapping import org.springframework.web.bind.annotation.RequestBody @@ -68,6 +70,11 @@ class UserController( ) } + @GetMapping("/users/my") + fun getMyInfo(@AuthenticationPrincipal userPrincipal: UserPrincipal): UserInfoResponseDto { + return userService.getMyInfo(oauthName = userPrincipal.name) + } + @PatchMapping("/users/my/male") fun updateMaleInfo( @RequestBody updateRequestDto: UpdateMaleRequestDto, diff --git a/src/main/kotlin/com/yourssu/ssudateserver/dto/response/UserInfoResponseDto.kt b/src/main/kotlin/com/yourssu/ssudateserver/dto/response/UserInfoResponseDto.kt new file mode 100644 index 0000000..9b6909b --- /dev/null +++ b/src/main/kotlin/com/yourssu/ssudateserver/dto/response/UserInfoResponseDto.kt @@ -0,0 +1,19 @@ +package com.yourssu.ssudateserver.dto.response + +import com.yourssu.ssudateserver.enums.Animals +import com.yourssu.ssudateserver.enums.Gender +import com.yourssu.ssudateserver.enums.MBTI +import java.time.LocalDateTime + +data class UserInfoResponseDto( + val id: Long, + var animals: Animals, + var mbti: MBTI, + var nickName: String, + var introduction: String, + var contact: String, + var weight: Int, + var ticket: Int, + val gender: Gender, + val createdAt: LocalDateTime, +) diff --git a/src/main/kotlin/com/yourssu/ssudateserver/service/UserService.kt b/src/main/kotlin/com/yourssu/ssudateserver/service/UserService.kt index 6f1e998..a1dbde5 100644 --- a/src/main/kotlin/com/yourssu/ssudateserver/service/UserService.kt +++ b/src/main/kotlin/com/yourssu/ssudateserver/service/UserService.kt @@ -3,6 +3,7 @@ package com.yourssu.ssudateserver.service import com.yourssu.ssudateserver.dto.response.RefreshTokenResponseDto import com.yourssu.ssudateserver.dto.response.RegisterResponseDto import com.yourssu.ssudateserver.dto.response.UpdateResponseDto +import com.yourssu.ssudateserver.dto.response.UserInfoResponseDto import com.yourssu.ssudateserver.entity.User import com.yourssu.ssudateserver.enums.Animals import com.yourssu.ssudateserver.enums.Gender @@ -30,6 +31,24 @@ class UserService( return userRepository.findByOauthName(oauthName) } + fun getMyInfo(oauthName: String): UserInfoResponseDto { + val user = + userRepository.findByOauthName(oauthName) ?: throw UserNotFoundException("해당 oauthName인 유저가 없습니다.") + + return UserInfoResponseDto( + id = user.id!!, + animals = user.animals, + mbti = user.mbti, + nickName = user.nickName, + introduction = user.introduction, + contact = user.contact, + weight = user.weight, + ticket = user.ticket, + gender = user.gender, + createdAt = user.createdAt, + ) + } + fun refreshToken(refreshToken: String, oauthName: String): RefreshTokenResponseDto { val foundedToken = refreshTokenService.findRefreshToken(oauthName) ?: throw RefreshTokenNotFoundException("유저의 refreshToken이 존재하지 않습니다.")