From bbed8ad35cea1515bae92d9f1761586d6f3aef95 Mon Sep 17 00:00:00 2001 From: Jiwon-cho Date: Sat, 2 Mar 2024 00:47:15 +0900 Subject: [PATCH 1/2] =?UTF-8?q?refactor:=20query=20=EC=A1=B0=ED=9A=8C?= =?UTF-8?q?=EB=AC=B8=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/kotlin/mara/server/domain/share/ShareRepository.kt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/kotlin/mara/server/domain/share/ShareRepository.kt b/src/main/kotlin/mara/server/domain/share/ShareRepository.kt index 77f5361..758919a 100644 --- a/src/main/kotlin/mara/server/domain/share/ShareRepository.kt +++ b/src/main/kotlin/mara/server/domain/share/ShareRepository.kt @@ -98,13 +98,13 @@ class CustomShareRepositoryImpl( .fetch() val query = queryFactory.selectFrom(share) - .where(share.id.`in`(appliedShareIdList).and(share.user.eq(user).and(share.status.eq(status)))) + .where((share.id.`in`(appliedShareIdList).or(share.user.eq(user)).and(share.status.eq(status)))) .offset(pageable.offset) .limit(pageable.pageSize.toLong()) .orderBy(share.createdAt.desc()).fetch() val count = queryFactory.select(share.count()).from(share) - .where(share.id.`in`(appliedShareIdList).and(share.user.eq(user).and(share.status.eq(status)))).fetchOne() + .where((share.id.`in`(appliedShareIdList).or(share.user.eq(user)).and(share.status.eq(status)))).fetchOne() return PageableExecutionUtils.getPage(query, pageable) { count!! } } From abe144767b64b6be045bfb130185cbcfe01902d0 Mon Sep 17 00:00:00 2001 From: Jiwon-cho Date: Sat, 2 Mar 2024 15:16:30 +0900 Subject: [PATCH 2/2] =?UTF-8?q?refactor:=20hotfix=20=EB=B3=91=ED=95=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/kotlin/mara/server/config/cors/CorsConfig.kt | 1 + .../mara/server/domain/share/ApplyShareRepository.kt | 2 +- .../kotlin/mara/server/domain/share/ShareController.kt | 4 ++-- .../kotlin/mara/server/domain/share/ShareService.kt | 10 ++++------ src/main/resources/application-dev.yml | 2 +- 5 files changed, 9 insertions(+), 10 deletions(-) diff --git a/src/main/kotlin/mara/server/config/cors/CorsConfig.kt b/src/main/kotlin/mara/server/config/cors/CorsConfig.kt index ad7d771..40550f0 100644 --- a/src/main/kotlin/mara/server/config/cors/CorsConfig.kt +++ b/src/main/kotlin/mara/server/config/cors/CorsConfig.kt @@ -12,6 +12,7 @@ class CorsConfig : WebMvcConfigurer { .allowedOriginPatterns("*") // 모든 도메인에 대해 액세스 허용 .allowedMethods("GET", "POST", "PUT", "PATCH", "DELETE", "OPTIONS") // 허용할 HTTP 메서드 .allowedHeaders("*") // 모든 헤더 허용 + .exposedHeaders("*") .allowCredentials(true) // 자격 증명 허용 .maxAge(3600) // CORS preflight 요청 결과 캐싱 시간 (초 단위) } diff --git a/src/main/kotlin/mara/server/domain/share/ApplyShareRepository.kt b/src/main/kotlin/mara/server/domain/share/ApplyShareRepository.kt index 3c3c142..00a9a43 100644 --- a/src/main/kotlin/mara/server/domain/share/ApplyShareRepository.kt +++ b/src/main/kotlin/mara/server/domain/share/ApplyShareRepository.kt @@ -5,6 +5,6 @@ import org.springframework.data.jpa.repository.JpaRepository interface ApplyShareRepository : JpaRepository { fun existsByUserAndShare(user: User, share: Share): Boolean - + fun findByUserAndShare(user: User, share: Share): ApplyShare fun countByUser(user: User): Long } diff --git a/src/main/kotlin/mara/server/domain/share/ShareController.kt b/src/main/kotlin/mara/server/domain/share/ShareController.kt index cc083b9..e7d6b3a 100644 --- a/src/main/kotlin/mara/server/domain/share/ShareController.kt +++ b/src/main/kotlin/mara/server/domain/share/ShareController.kt @@ -70,7 +70,7 @@ class ShareController(private val shareService: ShareService) { @DeleteMapping("/applies/{id}") @Operation(summary = "나눔 신청 취소 API") - fun deleteApply(@PathVariable(name = "id") applyId: Long): CommonResponse { - return success(shareService.deleteApplyShare(applyId)) + fun deleteApply(@PathVariable(name = "id") shareId: Long): CommonResponse { + return success(shareService.deleteApplyShare(shareId)) } } diff --git a/src/main/kotlin/mara/server/domain/share/ShareService.kt b/src/main/kotlin/mara/server/domain/share/ShareService.kt index 9315660..e934280 100644 --- a/src/main/kotlin/mara/server/domain/share/ShareService.kt +++ b/src/main/kotlin/mara/server/domain/share/ShareService.kt @@ -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 @@ -151,16 +150,15 @@ 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 } } diff --git a/src/main/resources/application-dev.yml b/src/main/resources/application-dev.yml index ea0fb1f..5659904 100644 --- a/src/main/resources/application-dev.yml +++ b/src/main/resources/application-dev.yml @@ -35,7 +35,7 @@ cloud: jwt: secret-key: ${jwt-secret-key} - access-duration-mils: 1800000 + access-duration-mils: 21600000 refresh-duration-mins: 20160 logging: