Skip to content

Commit

Permalink
feat: 내 정보 가져오기 구현
Browse files Browse the repository at this point in the history
  • Loading branch information
GGHDMS committed Dec 16, 2023
1 parent d712e1b commit 7363ec1
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
@@ -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,
)
19 changes: 19 additions & 0 deletions src/main/kotlin/com/yourssu/ssudateserver/service/UserService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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이 존재하지 않습니다.")
Expand Down

0 comments on commit 7363ec1

Please sign in to comment.