Skip to content

Commit

Permalink
Merge pull request #226 from Team-Ampersand/225-refactor/user-role-re…
Browse files Browse the repository at this point in the history
…sponse

225 refactor/user role response
  • Loading branch information
esperar committed Jul 3, 2023
2 parents 6507ab5 + 8f8077e commit 1e2af50
Show file tree
Hide file tree
Showing 33 changed files with 111 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,16 @@ class CreateBoardServiceImpl(
override fun execute(createBoardReqDto: CreateBoardReqDto, multipartFiles: List<MultipartFile>?): Board {
val member: Member = userUtil.fetchCurrentUser()
val createBoardDto: CreateBoardDto = toDto(createBoardReqDto = createBoardReqDto)

if (multipartFiles == null) {
return toEntity(createBoardDto, member)
.let { boardSaveUtil.saveBoard(board = it) }
}

val uploadFile: List<String> = s3Service.uploadFile(multipartFiles)
val board: Board = toEntity(createBoardDto, member)
.let { boardSaveUtil.saveBoard(board = it) }

for (uploadFileUrl: String in uploadFile) {
toEntity(board = board, uploadFileUrl)
.let { boardSaveUtil.saveBoardImage(boardImage = it) }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,12 @@ class DeleteBoardServiceImpl(
private val s3Service: S3Service
) : DeleteBoardService {
override fun execute(boardId: Long) {
val boardInfo: Board = boardRepository.findByIdOrNull(boardId) ?: throw BoardNotExistsException()
val boardInfo: Board = boardRepository.findByIdOrNull(boardId)
?: throw BoardNotExistsException()

val boardImages: List<BoardImage> = boardImageRepository.findAllByBoard_Id(boardId)
if (boardImages.count() { true } == 0) {

if (boardImages.isEmpty()) {
boardRepository.delete(boardInfo)
} else {
for (boardImage in boardImages) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,12 @@ class DeleteMultipleBoardServiceImpl(
override fun execute(deleteMultipleBoardReqDto: DeleteMultipleBoardReqDto) {
deleteMultipleBoardReqDto.boardIdList
.forEach {
val boardInfo: Board = boardRepository.findByIdOrNull(it) ?: throw BoardNotExistsException()
val boardInfo: Board = boardRepository.findByIdOrNull(it)
?: throw BoardNotExistsException()

val boardImages: List<BoardImage> = boardImageRepository.findAllByBoard_Id(it)
if (boardImages.count() { true } == 0) {

if (boardImages.isEmpty()) {
boardRepository.delete(boardInfo)
} else {
for (boardImage in boardImages) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ class GetBoardDetailServiceImpl(
private val boardImageRepository: BoardImageRepository,
) : GetBoardDetailService {
override fun execute(boardId: Long): DetailBoardResDto {
val boardInfo: Board = boardRepository.findByIdOrNull(boardId) ?: throw BoardNotExistsException()
val boardInfo: Board = boardRepository.findByIdOrNull(boardId)
?: throw BoardNotExistsException()

return toResponse(boardInfo)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,12 @@ class ModifyBoardServiceImpl(
private val boardRepository: BoardRepository
) : ModifyBoardService {
override fun execute(modifyBoardReqDto: ModifyBoardReqDto, boardId: Long): Board {
val boardInfo: Board = boardRepository.findByIdOrNull(boardId) ?: throw BoardNotExistsException()
val boardInfo: Board = boardRepository.findByIdOrNull(boardId)
?: throw BoardNotExistsException()

toDto(modifyBoardReqDto)
.let { boardInfo.updateBoard(title = it.title, content = it.content) }

return boardInfo
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,14 @@ class EmailCheckServiceImpl(
) : EmailCheckService {
@Transactional(rollbackFor = [Exception::class])
override fun execute(key: String): Boolean {
val findByKey = emailCertificateRepository.findByKey(key) ?: throw AuthKeyNotFoundException()
val findByKey = emailCertificateRepository.findByKey(key)
?: throw AuthKeyNotFoundException()

if (!findByKey.expiredTime.isAfter(LocalDateTime.now()))
throw AuthKeyTimeOutException()

val emailCertificate = findByKey.verify()

emailCertificateRepository.save(emailCertificate)
return true
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,17 @@ class EmailSendServiceImpl(
override fun execute(emailReqDto: EmailReqDto): String {
val key = keyUtil.keyIssuance()
emailSender.send(emailReqDto.email, key)

if (emailCertificateRepository.existsByEmail(emailReqDto.email))
emailCertificateRepository.deleteByEmail(emailReqDto.email)

val emailCertificate = EmailCertificate(
email = emailReqDto.email,
key = key,
expiredTime = LocalDateTime.now().plusMinutes(5),
authentication = false
)

emailCertificateRepository.save(emailCertificate)
return key
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ class PasswordChangeEmailSendServiceImpl(
override fun execute(emailReqDto: EmailReqDto): String {
if (!memberRepository.existsByEmail(emailReqDto.email))
throw MemberNotFoundException()

return emailSendService.execute(emailReqDto)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ class SignupEmailSendServiceImpl(
override fun execute(emailReqDto: EmailReqDto): String {
if (memberRepository.existsByEmail(emailReqDto.email))
throw MemberAlreadyException()

return emailSendService.execute(emailReqDto)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,13 @@ class ApplyMassageServiceImpl(
) : ApplyMassageService {
override fun execute() {
validDayOfWeekAndHourMassageUtil.validateApply()

val member = userUtil.fetchCurrentUser()
val massageCount = findMassageCountUtil.findMassageCount()

if (massageCount.count >= massageCount.limit)
throw MassageOverException()

massageCheckUtil.isMassageStatusCan(member)
member.updateMassageStatus(MassageStatus.APPLIED)
massageCount.addCount()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,11 @@ class CancelMassageServiceImpl(
) : CancelMassageService {
override fun execute() {
validDayOfWeekAndHourMassageUtil.validateCancel()

val findMassageCount = findMassageCountUtil.findMassageCount()

val member = userUtil.fetchCurrentUser()

massageCheckUtil.isMassageStatusApplied(member)
member.updateMassageStatus(MassageStatus.CANT)
massageRepository.deleteByMember(member)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,14 @@ class GetMassageInfoServiceImpl(
override fun execute(): MassageInfoResDto {
val massageCount = massageCountRepository.findMassageCountById(1L)
val member = userUtil.fetchCurrentUser()

if (isMassageStatusCan(member) && validMassageApplyCant(massageCount))
return MassageInfoResDto(
count = massageCount.count,
massageStatus = MassageStatus.CANT,
limit = massageCount.limit
)

return MassageInfoResDto(
count = massageCount.count,
massageStatus = member.massageStatus,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@ import com.dotori.v2.domain.massage.service.UpdateMassageStatusService
import com.dotori.v2.domain.massage.util.FindMassageCountUtil
import com.dotori.v2.domain.member.domain.repository.MemberRepository
import com.dotori.v2.domain.member.enums.MassageStatus
import org.slf4j.LoggerFactory
import org.springframework.stereotype.Service
import org.springframework.transaction.annotation.Transactional
import java.util.logging.Logger

@Service
@Transactional(rollbackFor = [Exception::class])
Expand All @@ -15,6 +17,9 @@ class UpdateMassageStatusServiceImpl(
private val massageRepository: MassageRepository,
private val massageCountUtil: FindMassageCountUtil
) : UpdateMassageStatusService {

private val log = LoggerFactory.getLogger(this::class.simpleName)

override fun execute() {
updateSelfStudyStatus()
massageRepository.deleteAll()
Expand All @@ -24,6 +29,6 @@ class UpdateMassageStatusServiceImpl(
private fun updateSelfStudyStatus() {
memberRepository.findAllByMassageStatusOrMassageStatus(MassageStatus.APPLIED, MassageStatus.CANT)
.forEach { it.updateMassageStatus(MassageStatus.CAN)
println("it = ${it}")}
log.info("it = $it") }
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.dotori.v2.domain.member.presentation.data.res

import com.dotori.v2.domain.member.enums.Role
import com.fasterxml.jackson.annotation.JsonFormat
import java.time.ZonedDateTime

Expand All @@ -8,4 +9,5 @@ data class RefreshResDto (
val refreshToken: String,
@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd'T'HH:mm:ss")
val expiresAt: ZonedDateTime,
val roles: MutableList<Role>
)
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.dotori.v2.domain.member.presentation.data.res

import com.dotori.v2.domain.member.enums.Role
import com.fasterxml.jackson.annotation.JsonFormat
import java.time.ZonedDateTime

Expand All @@ -8,4 +9,5 @@ data class SignInResDto(
val refreshToken: String,
@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd'T'HH:mm:ss")
val expiresAt: ZonedDateTime,
val roles: MutableList<Role>
)
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,10 @@ class ChangeAuthPasswordServiceImpl(
): ChangeAuthPasswordService {
override fun execute(newPasswordReqDto: NewPasswordReqDto) {
val member = userUtil.fetchCurrentUser()

if (!passwordEncoder.matches(newPasswordReqDto.currentPassword, member.password))
throw PasswordMismatchException()

member.updatePassword(passwordEncoder.encode(newPasswordReqDto.newPassword))
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,13 @@ class ChangePasswordServiceImpl(
override fun execute(newPasswordReqDto: NoAuthNewPasswordReqDto) {
val emailCertificate = emailCertificateRepository.findByEmail(newPasswordReqDto.email)
?: throw EmailAuthNotFoundException()

if (!emailCertificate.authentication)
throw EmailNotBeenException()

val member = (memberRepository.findByEmail(newPasswordReqDto.email)
?: throw MemberNotFoundException())

member.updatePassword(passwordEncoder.encode(newPasswordReqDto.newPassword))
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@ class LogoutServiceImpl(
private val userUtil: UserUtil,
) : LogoutService{
override fun execute(): LogoutResDto =
userUtil.fetchCurrentUser()
.let { it.updateRefreshToken("") }
userUtil.fetchCurrentUser().updateRefreshToken("")
.let { LogoutResDto(it) }

}
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,23 @@ class RefreshTokenServiceImpl(
override fun execute(refreshToken: String): RefreshResDto {
if (!tokenProvider.isRefreshToken(refreshToken))
throw TokenTypeNotValidException()

val email = tokenProvider.getUserEmail(refreshToken)

val member = (memberRepository.findByEmail(email)
?: throw MemberNotFoundException())

val newAccessToken = tokenProvider.createAccessToken(member.email, member.roles)
val newRefreshToken = tokenProvider.createRefreshToken(member.email)
val expiredTime = tokenProvider.accessExpiredTime

member.updateRefreshToken(newRefreshToken)

return RefreshResDto(
newAccessToken,
newRefreshToken,
expiredTime
expiredTime,
roles = member.roles
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,21 @@ class SignInServiceImpl(
override fun execute(signInReqDto: SignInReqDto): SignInResDto {
val member = memberRepository.findByEmail(signInReqDto.email)
?: throw MemberNotFoundException()

if(!passwordEncoder.matches(signInReqDto.password, member.password))
throw PasswordMismatchException()// 패스워드 일치 X

val accessToken = tokenProvider.createAccessToken(member.email, member.roles)
val refreshToken = tokenProvider.createRefreshToken(member.email)
val accessExpiredTime = tokenProvider.accessExpiredTime

member.updateRefreshToken(refreshToken)

return SignInResDto(
accessToken = accessToken,
refreshToken = refreshToken,
expiresAt = accessExpiredTime
expiresAt = accessExpiredTime,
roles = member.roles
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,18 @@ class SignupServiceImpl(
override fun execute(signupReqDto: SignupReqDto): Long {
val emailCertificate = emailCertificateRepository.findByEmail(signupReqDto.email)
?: throw EmailAuthNotFoundException()

if(!emailCertificate.authentication)
throw EmailNotBeenException()

emailCertificateRepository.delete(emailCertificate)

if(memberRepository.existsByEmail(signupReqDto.email))
throw MemberAlreadyException()

val encodedPassword = passwordEncoder.encode(signupReqDto.password)
val member = signupReqDto.toEntity(encodedPassword)

return memberRepository.save(member).id
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,16 @@ class WithdrawalServiceImpl(
) : WithdrawalService {
override fun execute(withdrawalReqDto: WithdrawalReqDto) {
val currentUser = userUtil.fetchCurrentUser()

val member = memberRepository.findByEmail(withdrawalReqDto.email)
?: throw MemberNotFoundException()

if (!passwordEncoder.matches(withdrawalReqDto.password, member.password))
throw PasswordMismatchException()

if (currentUser != member)
throw MemberNotSameException()

memberRepository.delete(member)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,16 @@ class ApplyMusicServiceImpl(
) : ApplyMusicService {
override fun execute(applyMusicReqDto: ApplyMusicReqDto, dayOfWeek: DayOfWeek): Music {
validDayOfWeek(dayOfWeek)

val memberInfo: Member = userUtil.fetchCurrentUser()

isCanApplyMusicStatus(memberInfo)

val music: Music = toDto(applyMusicReqDto)
.let { musicRepository.save(toEntity(it, memberInfo)) }

memberInfo.updateMusicStatus(MusicStatus.APPLIED)

return music
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ class DeleteMusicServiceImpl(
) : DeleteMusicService {
override fun execute(musicId: Long) {
val music: Music = musicRepository.findByIdOrNull(musicId) ?: throw MusicNotFoundException()

musicRepository.delete(music)
music.member.updateMusicStatus(MusicStatus.CAN)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ class DeleteMyMusicServiceImpl(
override fun execute(musicId: Long) {
val music: Music = musicRepository.findByIdOrNull(musicId) ?: throw MusicNotFoundException()
val member: Member = userUtil.fetchCurrentUser()

validMusic(music, member)

musicRepository.delete(music)
music.member.updateMusicStatus(MusicStatus.CAN)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,14 @@ class ApplySelfStudyServiceImpl(
) : ApplySelfStudyService{
override fun execute() {
validDayOfWeekAndHourUtil.validateApply()

val member = userUtil.fetchCurrentUser()

val selfStudyCount = findSelfStudyCountUtil.findSelfStudyCount()

if (selfStudyCount.count >= selfStudyCount.limit)
throw SelfStudyOverException()

selfStudyCheckUtil.isSelfStudyStatusCan(member)
member.updateSelfStudyStatus(SelfStudyStatus.APPLIED)
selfStudyCount.addCount()
Expand Down
Loading

0 comments on commit 1e2af50

Please sign in to comment.