diff --git a/src/main/kotlin/com/nexters/bottles/user/controller/UserProfileController.kt b/src/main/kotlin/com/nexters/bottles/user/controller/UserProfileController.kt index 1b8d96c4..5a6ac93f 100644 --- a/src/main/kotlin/com/nexters/bottles/user/controller/UserProfileController.kt +++ b/src/main/kotlin/com/nexters/bottles/user/controller/UserProfileController.kt @@ -4,6 +4,7 @@ import com.nexters.bottles.user.facade.dto.ProfileChoiceResponseDto import com.nexters.bottles.user.facade.dto.RegisterIntroductionRequestDto import com.nexters.bottles.user.facade.dto.RegisterProfileRequestDto import com.nexters.bottles.user.facade.UserProfileFacade +import com.nexters.bottles.user.facade.dto.UserProfileResponseDto import org.springframework.web.bind.annotation.GetMapping import org.springframework.web.bind.annotation.PostMapping import org.springframework.web.bind.annotation.RequestBody @@ -30,4 +31,9 @@ class UserProfileController( fun upsertIntroduction(@RequestBody registerIntroductionRequestDto: RegisterIntroductionRequestDto) { profileFacade.upsertIntroduction(registerIntroductionRequestDto) } + + @GetMapping + fun getProfile(): UserProfileResponseDto { + return profileFacade.getProfile() + } } diff --git a/src/main/kotlin/com/nexters/bottles/user/domain/User.kt b/src/main/kotlin/com/nexters/bottles/user/domain/User.kt index 780e521d..35431883 100644 --- a/src/main/kotlin/com/nexters/bottles/user/domain/User.kt +++ b/src/main/kotlin/com/nexters/bottles/user/domain/User.kt @@ -2,6 +2,7 @@ package com.nexters.bottles.user.domain import com.nexters.bottles.global.BaseEntity import com.nexters.bottles.user.domain.enum.Gender +import java.time.LocalDate import javax.persistence.* @Entity @@ -10,6 +11,8 @@ class User( @GeneratedValue(strategy = GenerationType.IDENTITY) val id: Long = 0, + var birthdate: LocalDate? = null, + var name: String? = null, var kakaoId: String? = null, diff --git a/src/main/kotlin/com/nexters/bottles/user/facade/UserProfileFacade.kt b/src/main/kotlin/com/nexters/bottles/user/facade/UserProfileFacade.kt index 54bbac0e..eff205c7 100644 --- a/src/main/kotlin/com/nexters/bottles/user/facade/UserProfileFacade.kt +++ b/src/main/kotlin/com/nexters/bottles/user/facade/UserProfileFacade.kt @@ -4,7 +4,9 @@ import com.nexters.bottles.user.facade.dto.ProfileChoiceResponseDto import com.nexters.bottles.user.facade.dto.RegisterIntroductionRequestDto import com.nexters.bottles.user.facade.dto.RegisterProfileRequestDto import com.nexters.bottles.user.domain.UserProfileSelect +import com.nexters.bottles.user.facade.dto.UserProfileResponseDto import com.nexters.bottles.user.service.UserProfileService +import mu.KotlinLogging import org.springframework.stereotype.Component import regions @@ -13,6 +15,8 @@ class UserProfileFacade( private val profileService: UserProfileService, ) { + private val log = KotlinLogging.logger { } + fun upsertProfile(profileDto: RegisterProfileRequestDto) { validateProfile(profileDto) val convertedProfileDto = convertProfileDto(profileDto) @@ -43,6 +47,17 @@ class UserProfileFacade( profileService.saveIntroduction(registerIntroductionRequestDto.introduction) } + fun getProfile(): UserProfileResponseDto { + + val userProfile = profileService.findUserProfile(1L) // TODO: 회원 기능 구현후 수정 + return UserProfileResponseDto( + userName = "테스트", + age = 20, + introduction = userProfile?.introduction, + profileSelect = userProfile?.profileSelect + ) + } + private fun validateProfile(profileDto: RegisterProfileRequestDto) { require(profileDto.keyword.size <= 5) { "키워드는 5개 이하여야 해요" diff --git a/src/main/kotlin/com/nexters/bottles/user/facade/dto/UserProfileResponseDto.kt b/src/main/kotlin/com/nexters/bottles/user/facade/dto/UserProfileResponseDto.kt new file mode 100644 index 00000000..396d20af --- /dev/null +++ b/src/main/kotlin/com/nexters/bottles/user/facade/dto/UserProfileResponseDto.kt @@ -0,0 +1,12 @@ +package com.nexters.bottles.user.facade.dto + +import com.nexters.bottles.user.domain.QuestionAndAnswer +import com.nexters.bottles.user.domain.UserProfileSelect + +data class UserProfileResponseDto( + val userName: String, + val age: Int, + val introduction: List? = null, + val profileSelect: UserProfileSelect? = null, +) { +} diff --git a/src/main/kotlin/com/nexters/bottles/user/service/UserProfileService.kt b/src/main/kotlin/com/nexters/bottles/user/service/UserProfileService.kt index 4799d4e6..cd1cc2a5 100644 --- a/src/main/kotlin/com/nexters/bottles/user/service/UserProfileService.kt +++ b/src/main/kotlin/com/nexters/bottles/user/service/UserProfileService.kt @@ -8,7 +8,7 @@ import com.nexters.bottles.user.repository.UserRepository import mu.KotlinLogging import org.springframework.data.repository.findByIdOrNull import org.springframework.stereotype.Service -import javax.transaction.Transactional +import org.springframework.transaction.annotation.Transactional @Service class UserProfileService( @@ -26,7 +26,6 @@ class UserProfileService( profileRepository.findByUserId(user.id)?.let { it.user = user it.profileSelect = profileSelect - it.introduction = it.introduction } ?: run { profileRepository.save( UserProfile( @@ -53,4 +52,9 @@ class UserProfileService( ) } } + + @Transactional(readOnly = true) + fun findUserProfile(userId: Long): UserProfile? { + return profileRepository.findByUserId(userId) + } } diff --git a/src/main/kotlin/com/nexters/bottles/user/service/UserService.kt b/src/main/kotlin/com/nexters/bottles/user/service/UserService.kt new file mode 100644 index 00000000..fff7e1e8 --- /dev/null +++ b/src/main/kotlin/com/nexters/bottles/user/service/UserService.kt @@ -0,0 +1,12 @@ +package com.nexters.bottles.user.service + +import com.nexters.bottles.user.domain.User +import com.nexters.bottles.user.repository.UserRepository +import org.springframework.stereotype.Service +import org.springframework.transaction.annotation.Transactional + +@Service +class UserService( + private val userRepository: UserRepository, +) { +} diff --git a/src/main/resources/sql/table_query.sql b/src/main/resources/sql/table_query.sql index 62579309..9e102f71 100644 --- a/src/main/resources/sql/table_query.sql +++ b/src/main/resources/sql/table_query.sql @@ -1,12 +1,12 @@ -CREATE TABLE User -( - id BIGINT AUTO_INCREMENT PRIMARY KEY, - name VARCHAR(255) DEFAULT NULL, - kakao_id VARCHAR(255) DEFAULT NULL, +CREATE TABLE User ( + id BIGINT AUTO_INCREMENT PRIMARY KEY, + name VARCHAR(255) DEFAULT NULL, + birthdate DATE DEFAULT NULL, + kakao_id VARCHAR(255) DEFAULT NULL, phone_number VARCHAR(255) DEFAULT NULL, - gender VARCHAR(10) DEFAULT 'MALE', - created_at DATETIME DEFAULT CURRENT_TIMESTAMP, - updated_at DATETIME DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP + gender VARCHAR(10) DEFAULT 'MALE', + created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP NOT NULL, + updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP NOT NULL ); CREATE TABLE user_profile