Skip to content

Commit

Permalink
fix: 이름이 익명으로 보이지 않는 문제를 수정한다
Browse files Browse the repository at this point in the history
  • Loading branch information
devbelly committed Aug 16, 2024
1 parent 3347afe commit fe8c644
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import com.dclass.backend.domain.hashtag.HashTagRepository
import com.dclass.backend.domain.hashtag.HashTagTarget.RECRUITMENT
import com.dclass.backend.domain.recruitment.RecruitmentRepository
import com.dclass.backend.domain.recruitment.findByIdOrThrow
import com.dclass.backend.domain.recruitmentanonymous.RecruitmentAnonymousRepository
import com.dclass.backend.domain.recruitmentscrap.RecruitmentScrapRepository
import org.springframework.stereotype.Service
import org.springframework.transaction.annotation.Transactional
Expand All @@ -25,10 +26,17 @@ class RecruitmentService(
private val belongRepository: BelongRepository,
private val hashTagRepository: HashTagRepository,
private val recruitmentScrapRepository: RecruitmentScrapRepository,
private val anonymousRepository: RecruitmentAnonymousRepository
) {
fun getAll(userId: Long, request: RecruitmentScrollPageRequest): RecruitmentsResponse {
val activatedDepartmentId = belongRepository.getOrThrow(userId).activated

val recruitments = recruitmentRepository.findRecruitmentScrollPage(activatedDepartmentId, request)
.map {
it.apply {
if (this.isAnonymous) this.userNickname = "익명"
}
}
val hashTags = hashTagRepository.findRecruitmentHashTagByTargetAndTargetIdIn(
RECRUITMENT,
recruitments.map { it.id },
Expand Down Expand Up @@ -67,7 +75,9 @@ class RecruitmentService(
// TODO getCommentedAndReplied

fun getById(userId: Long, recruitmentId: Long): RecruitmentWithUserAndHashTagDetailResponse {
val anonymousList = anonymousRepository.findByRecruitmentId(recruitmentId)
val recruitment = recruitmentRepository.findRecruitmentById(recruitmentId)
.apply { if (isAnonymous) userNickname = "익명" }
val hashTags = hashTagRepository.findRecruitmentHashTagByTargetAndTargetId(RECRUITMENT, recruitmentId)
val scrapped = recruitmentScrapRepository.existsByUserIdAndRecruitmentId(userId, recruitmentId)
return RecruitmentWithUserAndHashTagDetailResponse(recruitment, hashTags, scrapped)
Expand All @@ -77,6 +87,11 @@ class RecruitmentService(
val activatedDepartmentId = belongRepository.getOrThrow(userId).activated
val recruitment = recruitmentRepository.save(request.toRecruitment(userId, activatedDepartmentId))
val hashTags = hashTagRepository.saveAll(request.hashTags.map { HashTag(it, RECRUITMENT, recruitment.id) })

if (request.isAnonymous && !anonymousRepository.existsByUserIdAndRecruitmentId(userId, recruitment.id)) {
anonymousRepository.save(request.toAnonymousEntity(userId, recruitment.id))
}

return RecruitmentResponse(recruitment)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import com.dclass.backend.domain.hashtag.HashTag
import com.dclass.backend.domain.recruitment.Recruitment
import com.dclass.backend.domain.recruitment.RecruitmentNumber
import com.dclass.backend.domain.recruitment.RecruitmentType
import com.dclass.backend.domain.recruitmentanonymous.RecruitmentAnonymous
import com.dclass.backend.domain.user.User
import java.time.LocalDateTime

Expand Down Expand Up @@ -34,6 +35,10 @@ data class CreateRecruitmentRequest(
isAnonymous = isAnonymous,
)
}

fun toAnonymousEntity(userId: Long, recruitmentId: Long): RecruitmentAnonymous {
return RecruitmentAnonymous(userId, recruitmentId)
}
}

data class RecruitmentResponse(
Expand Down

0 comments on commit fe8c644

Please sign in to comment.