Skip to content

Commit

Permalink
[feature/19] 프로필 조회 구현 (#22)
Browse files Browse the repository at this point in the history
* feat: 코드리뷰 반영

* feat: dto data 클래스로 수정

* chore: 불필요한 로그 제거
  • Loading branch information
injoon2019 authored Jul 23, 2024
1 parent 6d19d6e commit 07fadb1
Show file tree
Hide file tree
Showing 7 changed files with 62 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -30,4 +31,9 @@ class UserProfileController(
fun upsertIntroduction(@RequestBody registerIntroductionRequestDto: RegisterIntroductionRequestDto) {
profileFacade.upsertIntroduction(registerIntroductionRequestDto)
}

@GetMapping
fun getProfile(): UserProfileResponseDto {
return profileFacade.getProfile()
}
}
3 changes: 3 additions & 0 deletions src/main/kotlin/com/nexters/bottles/user/domain/User.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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)
Expand Down Expand Up @@ -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개 이하여야 해요"
Expand Down
Original file line number Diff line number Diff line change
@@ -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<QuestionAndAnswer>? = null,
val profileSelect: UserProfileSelect? = null,
) {
}
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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(
Expand All @@ -53,4 +52,9 @@ class UserProfileService(
)
}
}

@Transactional(readOnly = true)
fun findUserProfile(userId: Long): UserProfile? {
return profileRepository.findByUserId(userId)
}
}
12 changes: 12 additions & 0 deletions src/main/kotlin/com/nexters/bottles/user/service/UserService.kt
Original file line number Diff line number Diff line change
@@ -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,
) {
}
16 changes: 8 additions & 8 deletions src/main/resources/sql/table_query.sql
Original file line number Diff line number Diff line change
@@ -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
Expand Down

0 comments on commit 07fadb1

Please sign in to comment.