Skip to content
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

[FO-898] 프로필 모집 등록,수정 API 리팩토링 #400

Merged
merged 1 commit into from
Feb 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,10 @@ data class JobOpening(
recruitmentStartDate = request.secondPage.recruitmentStartDate
recruitmentEndDate = request.secondPage.recruitmentEndDate
representativeImageUrl = request.secondPage.representativeImageUrl
imageUrls.clear()
request.secondPage.imageUrls.forEach {
addJobOpeningImage(JobOpeningImage(it))
}

casting = request.thirdPage.casting
numberOfRecruits = request.thirdPage.numberOfRecruits
Expand Down Expand Up @@ -132,6 +136,7 @@ data class JobOpening(
recruitmentStartDate = null
recruitmentEndDate = null
representativeImageUrl = ""
imageUrls.clear()
casting = ""
numberOfRecruits = -1
careers = listOf()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,11 @@ class DeleteJobOpeningService(
@Transactional
suspend fun deleteJobOpening(email: String, jobOpeningId: Long) {
val userId = userRepository.findByEmail(email) ?: throw NotFoundUserException()

val jobOpening = jobOpeningRepository.findByTypeAndId(null, jobOpeningId) ?: throw NotFoundJobOpeningException()

if (jobOpening.userId != userId) {
throw InvalidJobOpeningUserIdException()
}

jobOpening.delete()
jobOpeningRepository.save(jobOpening)
jobOpeningDomainRepository.deleteByJobOpeningId(jobOpeningId)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,9 @@ data class JobOpeningDto(
@Schema(description = "스크랩 여부", example = "false")
val isScrap: Boolean = false,
@Schema(description = "닉네임", example = "김매니저")
val nickname: String,
val userNickname: String,
@Schema(description = "프로필 이미지", example = "https://www.naver.com")
val profileUrl: String,
val userProfileUrl: String,
@Schema(description = "작성일", example = "2021-10-10")
val createdAt: LocalDateTime,
@Schema(description = "유저 직업", example = "ACTOR")
Expand Down Expand Up @@ -124,8 +124,8 @@ data class JobOpeningDto(
viewCount = jobOpening.viewCount,
scrapCount = jobOpening.scrapCount,
isScrap = userJobOpeningScrapMap[jobOpening.id!!] != null,
nickname = nickname,
profileUrl = profileUrl,
userNickname = nickname,
userProfileUrl = profileUrl,
createdAt = jobOpening.createdAt,
userJob = job,
isVerified = isVerified
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,18 @@ class ValidateProfileFacade(
private val validateProfileService: ValidateProfileService,
) {

suspend fun validateBasicPage(basicPageValidation: ValidateProfileDto.BasicPageValidation) =
validateProfileService.validateBasicPage(basicPageValidation)
suspend fun validateBasicPage(secondPage: ValidateProfileDto.SecondPage) =
validateProfileService.validateBasicPage(secondPage)

suspend fun validateDetailPage(email: String, detailPageValidation: ValidateProfileDto.DetailPageValidation) =
validateProfileService.validateDetailPage(email, detailPageValidation)
suspend fun validateDetailPage(email: String, thirdPage: ValidateProfileDto.ThirdPage) =
validateProfileService.validateDetailPage(email, thirdPage)

suspend fun validateDescriptionPage(descriptionPageValidation: ValidateProfileDto.DescriptionPageValidation) =
validateProfileService.validateDescriptionPage(descriptionPageValidation)
suspend fun validateDescriptionPage(fourthPage: ValidateProfileDto.FourthPage) =
validateProfileService.validateDescriptionPage(fourthPage)

suspend fun validateCareerPage(careerPageValidation: ValidateProfileDto.CareerPageValidation) =
validateProfileService.validateCareerPage(careerPageValidation)
suspend fun validateCareerPage(fifthPage: ValidateProfileDto.FifthPage) =
validateProfileService.validateCareerPage(fifthPage)

suspend fun validateInterestPage(interestPageValidation: ValidateProfileDto.InterestPageValidation) =
validateProfileService.validateInterestPage(interestPageValidation)
suspend fun validateInterestPage(sixthPage: ValidateProfileDto.SixthPage) =
validateProfileService.validateInterestPage(sixthPage)
}
106 changes: 66 additions & 40 deletions server/src/main/kotlin/com/fone/profile/domain/entity/Profile.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package com.fone.profile.domain.entity

import com.fone.common.entity.BaseEntity
import com.fone.common.entity.Career
import com.fone.common.entity.ContactMethod
import com.fone.common.entity.Gender
import com.fone.common.entity.Type
import com.fone.profile.presentation.dto.RegisterProfileDto.RegisterProfileRequest
Expand All @@ -26,34 +27,48 @@ data class Profile(
@Column
@GeneratedValue(strategy = GenerationType.IDENTITY)
var id: Long? = null,

// page1
@Enumerated(EnumType.STRING) var contactMethod: ContactMethod,
@Column(length = 300) var contact: String,

// page2
@Column(length = 10) var name: String,
@Column var hookingComment: String,
@Column var birthday: LocalDate?,
@Enumerated(EnumType.STRING) var gender: Gender,
@Column var height: Int,
@Column var weight: Int,
@OneToMany(
mappedBy = "profile",
cascade = [CascadeType.PERSIST, CascadeType.MERGE],
orphanRemoval = true
) var profileImages: MutableList<ProfileImage> = mutableListOf(),
@Column var representativeImageUrl: String,

// page3
@Column var birthday: LocalDate,
@Enumerated(EnumType.STRING) var gender: Gender?,
@Column var height: Int?,
@Column var weight: Int?,
@Column var email: String,
@Column(length = 300) var sns: String,
@Column(length = 50) var specialty: String,
@OneToMany(
cascade = [CascadeType.PERSIST, CascadeType.MERGE],
orphanRemoval = true
)
@JoinColumn(name = "profile_id")
var snsUrls: Set<ProfileSns>,
@Column(length = 50) var specialty: String,

// page4
@Column(length = 500) var details: String,

// page5
@Enumerated(EnumType.STRING) var career: Career,
@Column(length = 500) var careerDetail: String,

// etc
@Enumerated(EnumType.STRING) var type: Type,
@Column var userId: Long,
@Column var viewCount: Long,
@Column var viewCount: Long = 0,
@Column var wantCount: Long = 0,
@Column var isDeleted: Boolean = false,
@Column var representativeImageUrl: String,
@OneToMany(
mappedBy = "profile",
cascade = [CascadeType.PERSIST, CascadeType.MERGE],
orphanRemoval = true
) var profileImages: MutableList<ProfileImage> = mutableListOf(),
) : BaseEntity() {

fun view() {
Expand All @@ -65,43 +80,54 @@ data class Profile(
}

fun put(request: RegisterProfileRequest) {
name = request.name
hookingComment = request.hookingComment
birthday = request.birthday
gender = request.gender
height = request.height
weight = request.weight
email = request.email
sns = request.sns ?: ""
snsUrls = request.snsUrls.map(ProfileSnsUrl::toEntity).toSet()
specialty = request.specialty
details = request.details
career = request.career
careerDetail = request.careerDetail ?: ""
type = request.type
representativeImageUrl = request.representativeImageUrl
this.profileImages = mutableListOf()
request.profileImages.forEach {
this.addProfileImage(ProfileImage(it))
// page1
contactMethod = request.firstPage.contactMethod
contact = request.firstPage.contact

// page2
name = request.secondPage.name
hookingComment = request.secondPage.hookingComment
representativeImageUrl = request.secondPage.representativeImageUrl
profileImages = mutableListOf()
request.secondPage.profileImages.forEach {
addProfileImage(ProfileImage(it))
}

// page3
birthday = request.thirdPage.birthday
gender = request.thirdPage.gender
height = request.thirdPage.height
weight = request.thirdPage.weight
email = request.thirdPage.email
specialty = request.thirdPage.specialty
snsUrls = request.thirdPage.snsUrls.map(ProfileSnsUrl::toEntity).toSet()

// page4
details = request.fourthPage.details

// page5
career = request.fifthPage.career
careerDetail = request.fifthPage.careerDetail

// page6
type = request.type
}

fun delete() {
contact = ""
name = ""
hookingComment = ""
birthday = null
gender = Gender.IRRELEVANT
height = 0
weight = 0
representativeImageUrl = ""
profileImages = mutableListOf()
gender = null
height = null
weight = null
email = ""
sns = ""
snsUrls = emptySet()
specialty = ""
snsUrls = setOf()
details = ""
career = Career.IRRELEVANT
careerDetail = ""
type = Type.ACTOR
isDeleted = true
this.profileImages = mutableListOf()
}

/* 연관관계 메서드 */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import com.fone.profile.domain.repository.ProfileCategoryRepository
import com.fone.profile.domain.repository.ProfileDomainRepository
import com.fone.profile.domain.repository.ProfileRepository
import org.springframework.stereotype.Service
import javax.transaction.Transactional

@Service
class DeleteProfileService(
Expand All @@ -17,6 +18,7 @@ class DeleteProfileService(
private val userRepository: UserCommonRepository,
) {

@Transactional
suspend fun deleteProfile(email: String, profileId: Long) {
val userId = userRepository.findByEmail(email) ?: throw NotFoundUserException()
val profile = profileRepository.findByTypeAndId(null, profileId) ?: throw NotFoundProfileException()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class PutProfileService(
val userProfileWants = profileWantRepository.findByUserId(user.id!!)

profileDomainRepository.deleteByProfileId(profile.id!!)
val profileDomains = request.domains?.map {
val profileDomains = request.thirdPage.domains?.map {
ProfileDomain(
profile.id!!,
it
Expand All @@ -51,7 +51,7 @@ class PutProfileService(
profileDomainRepository.saveAll(profileDomains)

profileCategoryRepository.deleteByProfileId(profile.id!!)
val profileCategories = request.categories.map {
val profileCategories = request.sixthPage.categories.map {
ProfileCategory(
profile.id!!,
it
Expand All @@ -64,8 +64,8 @@ class PutProfileService(
return RegisterProfileResponse(
profile,
userProfileWants,
request.domains,
request.categories,
request.thirdPage.domains,
request.sixthPage.categories,
profileUser?.nickname ?: "",
profileUser?.profileUrl ?: "",
profileUser?.job ?: Job.ACTOR
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class RegisterProfileService(
val user = userRepository.findByEmail(email) ?: throw NotFoundUserException()
return with(request) {
val profile = toEntity(user.id!!)
profileImages.forEach {
secondPage.profileImages.forEach {
profile.addProfileImage(
ProfileImage(
it
Expand All @@ -42,14 +42,14 @@ class RegisterProfileService(

profileRepository.save(profile)

val profileDomains = domains?.map {
val profileDomains = thirdPage.domains?.map {
ProfileDomain(
profile.id!!,
it
)
}

val profileCategories = categories.map {
val profileCategories = sixthPage.categories.map {
ProfileCategory(
profile.id!!,
it
Expand All @@ -66,8 +66,8 @@ class RegisterProfileService(
RegisterProfileResponse(
profile,
userProfileWants,
domains,
categories,
thirdPage.domains,
sixthPage.categories,
profileUser?.nickname ?: "",
profileUser?.profileUrl ?: "",
profileUser?.job ?: Job.ACTOR
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class ValidateProfileService(
private val urlValidator = URLValidator()
private val emailRegex = Regex("^[a-zA-Z0-9_!#$%&'*+/=?`{|}~^.-]+@[a-zA-Z0-9.-]+$")

fun validateBasicPage(request: ValidateProfileDto.BasicPageValidation) {
fun validateBasicPage(request: ValidateProfileDto.SecondPage) {
if (request.name.isBlank()) {
throw RequestValidationException("본인의 이름을 입력해 주세요.")
}
Expand All @@ -31,7 +31,7 @@ class ValidateProfileService(

suspend fun validateDetailPage(
email: String,
request: ValidateProfileDto.DetailPageValidation,
request: ValidateProfileDto.ThirdPage,
) {
if (LocalDate.now().year - request.birthday.year > 100) {
throw RequestValidationException("100세 이상의 나이는 입력할 수 없습니다.")
Expand Down Expand Up @@ -68,18 +68,18 @@ class ValidateProfileService(
}
}

fun validateDescriptionPage(descriptionPageValidation: ValidateProfileDto.DescriptionPageValidation) {
if (descriptionPageValidation.details.length < 8) {
fun validateDescriptionPage(fourthPage: ValidateProfileDto.FourthPage) {
if (fourthPage.details.length < 8) {
throw RequestValidationException("최소 8자 이상의 상세 요강을 입력해주세요.")
}
}

fun validateCareerPage(careerPageValidation: ValidateProfileDto.CareerPageValidation) {
fun validateCareerPage(fifthPage: ValidateProfileDto.FifthPage) {
// 검증 할 것 없음
return
}

fun validateInterestPage(interestPageValidation: ValidateProfileDto.InterestPageValidation) {
fun validateInterestPage(sixthPage: ValidateProfileDto.SixthPage) {
// 검증 할 것 없음
return
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,20 @@ class WantProfileService(

profileWantRepository.findByUserIdAndProfileId(userId, profileId)?.let {
profileWantRepository.delete(it)

val profile = profileRepository.findByTypeAndId(null, profileId) ?: throw NotFoundProfileException()

profile.wantCount -= 1

profileRepository.save(profile)
return
}

profileRepository.findByTypeAndId(null, profileId) ?: throw NotFoundProfileException()
val profile = profileRepository.findByTypeAndId(null, profileId) ?: throw NotFoundProfileException()

profile.wantCount += 1

profileWantRepository.save(ProfileWant(userId, profileId))
profileRepository.save(profile)
}
}
Loading
Loading