Skip to content

Commit

Permalink
refactor: deleteApplyShare 로직 변경, 토큰 시간 변경
Browse files Browse the repository at this point in the history
  • Loading branch information
Jiwon-cho committed Mar 2, 2024
1 parent f2ea2b8 commit 1e800cc
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@ import org.springframework.data.jpa.repository.JpaRepository
interface ApplyShareRepository : JpaRepository<ApplyShare, Long> {
fun existsByUserAndShare(user: User, share: Share): Boolean

fun findByUserAndShare(user: User, share: Share): ApplyShare
fun countByUser(user: User): Long
}
4 changes: 2 additions & 2 deletions src/main/kotlin/mara/server/domain/share/ShareController.kt
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ class ShareController(private val shareService: ShareService) {

@DeleteMapping("/applies/{id}")
@Operation(summary = "나눔 신청 취소 API")
fun deleteApply(@PathVariable(name = "id") applyId: Long): CommonResponse<String> {
return success(shareService.deleteApplyShare(applyId))
fun deleteApply(@PathVariable(name = "id") shareId: Long): CommonResponse<String> {
return success(shareService.deleteApplyShare(shareId))
}
}
15 changes: 6 additions & 9 deletions src/main/kotlin/mara/server/domain/share/ShareService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import mara.server.exception.IllegalAccessShareException
import mara.server.exception.IllegalAccessShareException.Companion.CREATED_BY_LOGIN_USER
import mara.server.exception.IllegalAccessShareException.Companion.DIFFERENT_USER
import mara.server.exception.IllegalAccessShareException.Companion.DUPLICATED_APPLY
import mara.server.exception.ShareException.Companion.NO_SUCH_APPLY_SHARE
import mara.server.exception.ShareException.Companion.NO_SUCH_INGREDIENT
import mara.server.exception.ShareException.Companion.NO_SUCH_SHARE
import org.springframework.data.domain.Page
Expand Down Expand Up @@ -151,16 +150,14 @@ class ShareService(
}

@Transactional
fun deleteApplyShare(applyId: Long): String {
fun deleteApplyShare(shareId: Long): String {
val user = userService.getCurrentLoginUser()
val applyShare = applyShareRepository.findById(applyId)
.orElseThrow { NoSuchElementException("$NO_SUCH_APPLY_SHARE Id: $applyId") }
if (user.userId != applyShare.user.userId) throw IllegalAccessShareException(DIFFERENT_USER)
/**
신청을 취소하면 사람 수 차감
**/
val share = shareRepository.findById(shareId).orElseThrow { NoSuchElementException("$NO_SUCH_SHARE Id: $shareId") }
val applyShare = applyShareRepository.findByUserAndShare(user, share)

applyShare.share.minusPeopleCount()
applyShareRepository.deleteById(applyId)
applyShareRepository.delete(applyShare)

return deleted
}
}
2 changes: 1 addition & 1 deletion src/main/resources/application-dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ cloud:

jwt:
secret-key: ${jwt-secret-key}
access-duration-mils: 1800000
access-duration-mils: 21600000
refresh-duration-mins: 20160

logging:
Expand Down

0 comments on commit 1e800cc

Please sign in to comment.