From 127fbe8ba46531646e14ec6566172ea5f9f197f8 Mon Sep 17 00:00:00 2001 From: hwgyun Date: Sun, 23 Feb 2025 21:47:08 +0900 Subject: [PATCH] =?UTF-8?q?RequestUtils=20key=EA=B0=92=EC=9D=84=20enum=20c?= =?UTF-8?q?lass=EB=A1=9C=20=EB=B0=9B=EB=8F=84=EB=A1=9D=20=EC=88=98?= =?UTF-8?q?=EC=A0=95=20(#299)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * RequestUtils key값을 enum class로 받도록 수정 * 🐛 RequestUtils 메소드가 파라미터를 enum class로 받도록 수정 --- .../application/service/CommentLikeService.kt | 4 ++-- .../comment/application/service/CommentService.kt | 8 ++++---- .../application/service/CommunityPostLikeService.kt | 8 ++++---- .../application/service/CommunityPostService.kt | 12 ++++++------ .../application/service/ComplaintPostService.kt | 8 ++++---- .../api/lost/application/service/LostPostService.kt | 8 ++++---- .../api/member/application/service/MemberService.kt | 9 +++++---- .../service/CommunityPostReportService.kt | 2 +- .../application/service/LostPostReportService.kt | 2 +- .../common/interceptor/AuthenticationInterceptor.kt | 2 +- .../admin/application/service/AdminServiceTest.kt | 6 +++--- .../application/service/CommentLikeServiceTest.kt | 2 +- .../application/service/CommentServiceTest.kt | 4 ++-- .../application/service/CommunityPostServiceTest.kt | 4 ++-- .../application/service/ComplaintPostServiceTest.kt | 2 +- .../lost/application/service/LostPostServiceTest.kt | 6 +++--- .../member/application/service/MemberServiceTest.kt | 4 ++-- .../service/CommunityPostReportServiceTest.kt | 12 ++++++------ .../application/service/LostPostReportServiceTest.kt | 12 ++++++------ .../train/application/service/TrainServiceTest.kt | 2 +- .../team/ahachul_backend/common/config/JpaConfig.kt | 3 +-- .../ahachul_backend/common/utils/RequestUtils.kt | 12 ++++++++---- 22 files changed, 68 insertions(+), 64 deletions(-) diff --git a/application/src/main/kotlin/backend/team/ahachul_backend/api/comment/application/service/CommentLikeService.kt b/application/src/main/kotlin/backend/team/ahachul_backend/api/comment/application/service/CommentLikeService.kt index 762729dc..49edf603 100644 --- a/application/src/main/kotlin/backend/team/ahachul_backend/api/comment/application/service/CommentLikeService.kt +++ b/application/src/main/kotlin/backend/team/ahachul_backend/api/comment/application/service/CommentLikeService.kt @@ -24,7 +24,7 @@ class CommentLikeService( @Transactional override fun like(commentId: Long) { - val memberId = RequestUtils.getAttribute("memberId")!!.toLong() + val memberId = RequestUtils.getAttribute(RequestUtils.Attribute.MEMBER_ID)!!.toLong() if (existCommentLike(commentId, memberId)) { throw CommonException(ResponseCode.INVALID_DOMAIN) @@ -41,7 +41,7 @@ class CommentLikeService( @Transactional override fun notLike(commentId: Long) { - val memberId = RequestUtils.getAttribute("memberId")!!.toLong() + val memberId = RequestUtils.getAttribute(RequestUtils.Attribute.MEMBER_ID)!!.toLong() if (notExistCommentLike(commentId, memberId)) { throw CommonException(ResponseCode.INVALID_DOMAIN) diff --git a/application/src/main/kotlin/backend/team/ahachul_backend/api/comment/application/service/CommentService.kt b/application/src/main/kotlin/backend/team/ahachul_backend/api/comment/application/service/CommentService.kt index d5553475..b26b569b 100644 --- a/application/src/main/kotlin/backend/team/ahachul_backend/api/comment/application/service/CommentService.kt +++ b/application/src/main/kotlin/backend/team/ahachul_backend/api/comment/application/service/CommentService.kt @@ -39,7 +39,7 @@ class CommentService( PostType.COMPLAINT -> complaintPostReader.getComplaintPost(command.postId).createdBy }.toLongOrNull() - val loginMemberId = RequestUtils.getAttribute("memberId")?.toLong() + val loginMemberId = RequestUtils.getAttribute(RequestUtils.Attribute.MEMBER_ID)?.toLong() val isPostWriterEqualToLoginMember = postWriterId != null && loginMemberId == postWriterId val comments = commentReader.searchComments(command).map { @@ -81,7 +81,7 @@ class CommentService( @Transactional override fun createComment(command: CreateCommentCommand): CreateCommentDto.Response { - val memberId = RequestUtils.getAttribute("memberId")!! + val memberId = RequestUtils.getAttribute(RequestUtils.Attribute.MEMBER_ID)!! val upperComment = command.upperCommentId?.let { commentReader.findById(it) } val member = memberReader.getMember(memberId.toLong()) val post = getPost(command.postType, command.postId) @@ -92,7 +92,7 @@ class CommentService( @Transactional override fun updateComment(command: UpdateCommentCommand): UpdateCommentDto.Response { - val memberId = RequestUtils.getAttribute("memberId")!! + val memberId = RequestUtils.getAttribute(RequestUtils.Attribute.MEMBER_ID)!! val comment = commentReader.getById(command.id) comment.checkMe(memberId) comment.update(command.content) @@ -101,7 +101,7 @@ class CommentService( @Transactional override fun deleteComment(command: DeleteCommentCommand): DeleteCommentDto.Response { - val memberId = RequestUtils.getAttribute("memberId")!! + val memberId = RequestUtils.getAttribute(RequestUtils.Attribute.MEMBER_ID)!! val comment = commentReader.getById(command.id) comment.checkMe(memberId) comment.delete() diff --git a/application/src/main/kotlin/backend/team/ahachul_backend/api/community/application/service/CommunityPostLikeService.kt b/application/src/main/kotlin/backend/team/ahachul_backend/api/community/application/service/CommunityPostLikeService.kt index eb536fcf..9346b286 100644 --- a/application/src/main/kotlin/backend/team/ahachul_backend/api/community/application/service/CommunityPostLikeService.kt +++ b/application/src/main/kotlin/backend/team/ahachul_backend/api/community/application/service/CommunityPostLikeService.kt @@ -29,7 +29,7 @@ class CommunityPostLikeService ( @Transactional override fun like(postId: Long) { - val memberId = RequestUtils.getAttribute("memberId")!!.toLong() + val memberId = RequestUtils.getAttribute(RequestUtils.Attribute.MEMBER_ID)!!.toLong() val postLike = communityPostLikeReader.find(postId, memberId) if (postLike?.likeYn == YNType.Y) { throw CommonException(ResponseCode.ALREADY_LIKED_POST) @@ -55,7 +55,7 @@ class CommunityPostLikeService ( @Transactional override fun notLike(postId: Long) { - val memberId = RequestUtils.getAttribute("memberId")!!.toLong() + val memberId = RequestUtils.getAttribute(RequestUtils.Attribute.MEMBER_ID)!!.toLong() communityPostLikeReader.find(postId, memberId)?.let { if (it.likeYn == YNType.N) { throw CommonException(ResponseCode.REJECT_BY_HATE_STATUS) @@ -67,7 +67,7 @@ class CommunityPostLikeService ( @Transactional override fun hate(postId: Long) { - val memberId = RequestUtils.getAttribute("memberId")!!.toLong() + val memberId = RequestUtils.getAttribute(RequestUtils.Attribute.MEMBER_ID)!!.toLong() val postLike = communityPostLikeReader.find(postId, memberId) if (postLike?.likeYn == YNType.N) { throw CommonException(ResponseCode.ALREADY_HATED_POST) @@ -87,7 +87,7 @@ class CommunityPostLikeService ( @Transactional override fun notHate(postId: Long) { - val memberId = RequestUtils.getAttribute("memberId")!!.toLong() + val memberId = RequestUtils.getAttribute(RequestUtils.Attribute.MEMBER_ID)!!.toLong() communityPostLikeReader.find(postId, memberId)?.let { if (it.likeYn == YNType.Y) { throw CommonException(ResponseCode.REJECT_BY_LIKE_STATUS) diff --git a/application/src/main/kotlin/backend/team/ahachul_backend/api/community/application/service/CommunityPostService.kt b/application/src/main/kotlin/backend/team/ahachul_backend/api/community/application/service/CommunityPostService.kt index 57de9616..7b0c82f2 100644 --- a/application/src/main/kotlin/backend/team/ahachul_backend/api/community/application/service/CommunityPostService.kt +++ b/application/src/main/kotlin/backend/team/ahachul_backend/api/community/application/service/CommunityPostService.kt @@ -46,7 +46,7 @@ class CommunityPostService( private val logger = NamedLogger("HASHTAG_LOGGER") override fun searchCommunityPosts(command: SearchCommunityPostCommand): PageInfoDto { - val userId: String? = RequestUtils.getAttribute("memberId") + val userId: String? = RequestUtils.getAttribute(RequestUtils.Attribute.MEMBER_ID) val subwayLine = command.subwayLineId?.let { subwayLineReader.getById(it) } val searchCommunityPosts = communityPostReader.searchCommunityPosts( @@ -66,7 +66,7 @@ class CommunityPostService( } override fun searchCommunityHotPosts(command: SearchCommunityHotPostCommand): PageInfoDto { - val userId: String? = RequestUtils.getAttribute("memberId") + val userId: String? = RequestUtils.getAttribute(RequestUtils.Attribute.MEMBER_ID) val subwayLine = command.subwayLineId?.let { subwayLineReader.getById(it) } val searchCommunityHotPosts = communityPostReader.searchCommunityHotPosts( @@ -86,7 +86,7 @@ class CommunityPostService( } override fun getCommunityPost(command: GetCommunityPostCommand): GetCommunityPostDto.Response { - val userId: String? = RequestUtils.getAttribute("memberId") + val userId: String? = RequestUtils.getAttribute(RequestUtils.Attribute.MEMBER_ID) val communityPost = communityPostReader.getByCustom(command.id, userId) if (communityPost.status == CommunityPostType.DELETED) { @@ -106,7 +106,7 @@ class CommunityPostService( @Transactional override fun createCommunityPost(command: CreateCommunityPostCommand): CreateCommunityPostDto.Response { - val memberId = RequestUtils.getAttribute("memberId")!! + val memberId = RequestUtils.getAttribute(RequestUtils.Attribute.MEMBER_ID)!! val member = memberReader.getMember(memberId.toLong()) val subwayLine = subwayLineReader.getById(command.subwayLineId) val communityPost = communityPostWriter.save(CommunityPostEntity.of(command, member, subwayLine)) @@ -124,7 +124,7 @@ class CommunityPostService( @Transactional override fun updateCommunityPost(command: UpdateCommunityPostCommand): UpdateCommunityPostDto.Response { - val memberId = RequestUtils.getAttribute("memberId")!! + val memberId = RequestUtils.getAttribute(RequestUtils.Attribute.MEMBER_ID)!! val communityPost = communityPostReader.getCommunityPost(command.id) communityPost.checkMe(memberId) communityPost.update(command) @@ -142,7 +142,7 @@ class CommunityPostService( @Transactional override fun deleteCommunityPost(command: DeleteCommunityPostCommand): DeleteCommunityPostDto.Response { - val memberId = RequestUtils.getAttribute("memberId")!! + val memberId = RequestUtils.getAttribute(RequestUtils.Attribute.MEMBER_ID)!! val entity = communityPostReader.getCommunityPost(command.id) entity.checkMe(memberId) entity.delete() diff --git a/application/src/main/kotlin/backend/team/ahachul_backend/api/complaint/application/service/ComplaintPostService.kt b/application/src/main/kotlin/backend/team/ahachul_backend/api/complaint/application/service/ComplaintPostService.kt index 0476c79d..7df59c4e 100644 --- a/application/src/main/kotlin/backend/team/ahachul_backend/api/complaint/application/service/ComplaintPostService.kt +++ b/application/src/main/kotlin/backend/team/ahachul_backend/api/complaint/application/service/ComplaintPostService.kt @@ -89,7 +89,7 @@ class ComplaintPostService( @Transactional override fun createComplaintPost(command: CreateComplaintPostCommand): CreateComplaintPostDto.Response { - val memberId = RequestUtils.getAttribute("memberId")!! + val memberId = RequestUtils.getAttribute(RequestUtils.Attribute.MEMBER_ID)!! val member = memberReader.getMember(memberId.toLong()) val subwayLine = subwayLineReader.getById(command.subwayLineId) @@ -110,7 +110,7 @@ class ComplaintPostService( @Transactional override fun updateComplaintPost(command: UpdateComplaintPostCommand): UpdateComplaintPostDto.Response { - val memberId = RequestUtils.getAttribute("memberId")!! + val memberId = RequestUtils.getAttribute(RequestUtils.Attribute.MEMBER_ID)!! val complaintPost = complaintPostReader.getComplaintPost(command.id) complaintPost.checkMe(memberId) @@ -126,7 +126,7 @@ class ComplaintPostService( @Transactional override fun updateComplaintPostStatus(command: UpdateComplaintPostStatusCommand): UpdateComplaintPostStatusDto.Response { - val memberId = RequestUtils.getAttribute("memberId")!! + val memberId = RequestUtils.getAttribute(RequestUtils.Attribute.MEMBER_ID)!! val complaintPost = complaintPostReader.getComplaintPost(command.id) if (complaintPost.status == ComplaintPostType.DELETED) { @@ -141,7 +141,7 @@ class ComplaintPostService( @Transactional override fun deleteComplaintPost(postId: Long): DeleteComplaintPostDto.Response { - val memberId = RequestUtils.getAttribute("memberId")!! + val memberId = RequestUtils.getAttribute(RequestUtils.Attribute.MEMBER_ID)!! val complaintPost = complaintPostReader.getComplaintPost(postId) if (complaintPost.status == ComplaintPostType.DELETED) { diff --git a/application/src/main/kotlin/backend/team/ahachul_backend/api/lost/application/service/LostPostService.kt b/application/src/main/kotlin/backend/team/ahachul_backend/api/lost/application/service/LostPostService.kt index 072cbb60..436c1e82 100644 --- a/application/src/main/kotlin/backend/team/ahachul_backend/api/lost/application/service/LostPostService.kt +++ b/application/src/main/kotlin/backend/team/ahachul_backend/api/lost/application/service/LostPostService.kt @@ -153,7 +153,7 @@ class LostPostService( @Transactional override fun createLostPost(command: CreateLostPostCommand): CreateLostPostDto.Response { - val memberId = RequestUtils.getAttribute("memberId")!! + val memberId = RequestUtils.getAttribute(RequestUtils.Attribute.MEMBER_ID)!! val member = memberReader.getMember(memberId.toLong()) val subwayLine = subwayLineReader.getById(command.subwayLine) val category = command.categoryName?.let { categoryReader.getCategoryByName(it) } @@ -175,7 +175,7 @@ class LostPostService( @Transactional override fun updateLostPost(command: UpdateLostPostCommand): UpdateLostPostDto.Response { - val memberId = RequestUtils.getAttribute("memberId")!! + val memberId = RequestUtils.getAttribute(RequestUtils.Attribute.MEMBER_ID)!! val entity = lostPostReader.getLostPost(command.id) entity.checkMe(memberId) @@ -204,7 +204,7 @@ class LostPostService( @Transactional override fun updateLostPostStatus(command: UpdateLostPostStatusCommand): UpdateLostPostStatusDto.Response { - val memberId = RequestUtils.getAttribute("memberId")!! + val memberId = RequestUtils.getAttribute(RequestUtils.Attribute.MEMBER_ID)!! val entity = lostPostReader.getLostPost(command.id) if (entity.origin == LostOrigin.LOST112) { @@ -219,7 +219,7 @@ class LostPostService( @Transactional override fun deleteLostPost(id: Long): DeleteLostPostDto.Response { - val memberId = RequestUtils.getAttribute("memberId")!! + val memberId = RequestUtils.getAttribute(RequestUtils.Attribute.MEMBER_ID)!! val entity = lostPostReader.getLostPost(id) entity.checkMe(memberId) entity.delete() diff --git a/application/src/main/kotlin/backend/team/ahachul_backend/api/member/application/service/MemberService.kt b/application/src/main/kotlin/backend/team/ahachul_backend/api/member/application/service/MemberService.kt index c9765160..6e22446f 100644 --- a/application/src/main/kotlin/backend/team/ahachul_backend/api/member/application/service/MemberService.kt +++ b/application/src/main/kotlin/backend/team/ahachul_backend/api/member/application/service/MemberService.kt @@ -30,13 +30,13 @@ class MemberService( ) : MemberUseCase { override fun getMember(): GetMemberDto.Response { - val member = memberReader.getMember(RequestUtils.getAttribute("memberId")!!.toLong()) + val member = memberReader.getMember(RequestUtils.getAttribute(RequestUtils.Attribute.MEMBER_ID)!!.toLong()) return GetMemberDto.Response.of(member) } @Transactional override fun updateMember(command: UpdateMemberCommand): UpdateMemberDto.Response { - val member = memberReader.getMember(RequestUtils.getAttribute("memberId")!!.toLong()) + val member = memberReader.getMember(RequestUtils.getAttribute(RequestUtils.Attribute.MEMBER_ID)!!.toLong()) command.nickname?.let { member.changeNickname(it) } command.gender?.let { member.changeGender(it) } command.ageRange?.let { member.changeAgeRange(it) } @@ -55,7 +55,7 @@ class MemberService( @Transactional override fun bookmarkStation(command: BookmarkStationCommands): GetBookmarkStationDto.Response { - val member = memberReader.getMember(RequestUtils.getAttribute("memberId")!!.toLong()) + val member = memberReader.getMember(RequestUtils.getAttribute(RequestUtils.Attribute.MEMBER_ID)!!.toLong()) val bookmarkStations = memberStationReader.getByMember(member) if (isEqualsAlreadyRegisteredStation(bookmarkStations, command.stations)) { @@ -71,7 +71,8 @@ class MemberService( } override fun getBookmarkStation(): GetBookmarkStationDto.Response { - val member = memberReader.getMember(RequestUtils.getAttribute("memberId")!!.toLong()) + val member = memberReader.getMember(RequestUtils.getAttribute(RequestUtils.Attribute.MEMBER_ID)!!.toLong()) + val bookmarkStations = memberStationReader.getByMember(member) return createBookmarkStationResponse(bookmarkStations) diff --git a/application/src/main/kotlin/backend/team/ahachul_backend/api/report/application/service/CommunityPostReportService.kt b/application/src/main/kotlin/backend/team/ahachul_backend/api/report/application/service/CommunityPostReportService.kt index 5fb2757d..12bef49a 100644 --- a/application/src/main/kotlin/backend/team/ahachul_backend/api/report/application/service/CommunityPostReportService.kt +++ b/application/src/main/kotlin/backend/team/ahachul_backend/api/report/application/service/CommunityPostReportService.kt @@ -24,7 +24,7 @@ class CommunityPostReportService( ): ReportUseCase { override fun save(targetId: Long): CreateReportDto.Response { - val memberId = RequestUtils.getAttribute("memberId")!! + val memberId = RequestUtils.getAttribute(RequestUtils.Attribute.MEMBER_ID)!! val sourceMember = memberReader.getMember(memberId.toLong()) val targetPost = communityPostReader.getCommunityPost(targetId) val targetMember = targetPost.member!! diff --git a/application/src/main/kotlin/backend/team/ahachul_backend/api/report/application/service/LostPostReportService.kt b/application/src/main/kotlin/backend/team/ahachul_backend/api/report/application/service/LostPostReportService.kt index 58b1c87d..0cd0d0cb 100644 --- a/application/src/main/kotlin/backend/team/ahachul_backend/api/report/application/service/LostPostReportService.kt +++ b/application/src/main/kotlin/backend/team/ahachul_backend/api/report/application/service/LostPostReportService.kt @@ -25,7 +25,7 @@ class LostPostReportService( override fun save(targetId: Long): CreateReportDto.Response { - val memberId = RequestUtils.getAttribute("memberId")!! + val memberId = RequestUtils.getAttribute(RequestUtils.Attribute.MEMBER_ID)!! val sourceMember = memberReader.getMember(memberId.toLong()) val targetPost = lostPostReader.getLostPost(targetId) diff --git a/application/src/main/kotlin/backend/team/ahachul_backend/common/interceptor/AuthenticationInterceptor.kt b/application/src/main/kotlin/backend/team/ahachul_backend/common/interceptor/AuthenticationInterceptor.kt index 7fc1ff68..3593859b 100644 --- a/application/src/main/kotlin/backend/team/ahachul_backend/common/interceptor/AuthenticationInterceptor.kt +++ b/application/src/main/kotlin/backend/team/ahachul_backend/common/interceptor/AuthenticationInterceptor.kt @@ -40,7 +40,7 @@ class AuthenticationInterceptor( val verifiedJwtToken = jwtUtils.verify(jwtTokenExcludePrefix) val authenticatedMemberId = verifiedJwtToken.body.subject - RequestUtils.setAttribute("memberId", authenticatedMemberId) + RequestUtils.setAttribute(RequestUtils.Attribute.MEMBER_ID, authenticatedMemberId) } catch (e: Exception) { if (!authentication.required) { return true diff --git a/application/src/test/kotlin/backend/team/ahachul_backend/admin/application/service/AdminServiceTest.kt b/application/src/test/kotlin/backend/team/ahachul_backend/admin/application/service/AdminServiceTest.kt index 49738756..8d6946a8 100644 --- a/application/src/test/kotlin/backend/team/ahachul_backend/admin/application/service/AdminServiceTest.kt +++ b/application/src/test/kotlin/backend/team/ahachul_backend/admin/application/service/AdminServiceTest.kt @@ -43,7 +43,7 @@ class AdminServiceTest( member = memberRepository.save(createMember("닉네임1")) otherMember = memberRepository.save(createMember("닉네임2")) manager = memberRepository.save(createMember("관리자")) - member!!.id.let { RequestUtils.setAttribute("memberId", it) } + member!!.id.let { RequestUtils.setAttribute(RequestUtils.Attribute.MEMBER_ID, it) } subwayLine = createSubwayLine() } @@ -74,10 +74,10 @@ class AdminServiceTest( // when communityPostReportService.save(target.id) - RequestUtils.setAttribute("memberId", otherMember2.id) + RequestUtils.setAttribute(RequestUtils.Attribute.MEMBER_ID, otherMember2.id) communityPostReportService.save(target.id) - RequestUtils.setAttribute("memberId", otherMember3.id) + RequestUtils.setAttribute(RequestUtils.Attribute.MEMBER_ID, otherMember3.id) communityPostReportService.save(target.id) val command = ActionReportCommand(target.member!!.id, "post") diff --git a/application/src/test/kotlin/backend/team/ahachul_backend/api/comment/application/service/CommentLikeServiceTest.kt b/application/src/test/kotlin/backend/team/ahachul_backend/api/comment/application/service/CommentLikeServiceTest.kt index 422a6bf9..e4ba9061 100644 --- a/application/src/test/kotlin/backend/team/ahachul_backend/api/comment/application/service/CommentLikeServiceTest.kt +++ b/application/src/test/kotlin/backend/team/ahachul_backend/api/comment/application/service/CommentLikeServiceTest.kt @@ -56,7 +56,7 @@ class CommentLikeServiceTest( ) ) - member.id.let { RequestUtils.setAttribute("memberId", it) } + member.id.let { RequestUtils.setAttribute(RequestUtils.Attribute.MEMBER_ID, it) } subwayLine = subwayLineRepository.save(SubwayLineEntity(name = "1호선", regionType = RegionType.METROPOLITAN)) diff --git a/application/src/test/kotlin/backend/team/ahachul_backend/api/comment/application/service/CommentServiceTest.kt b/application/src/test/kotlin/backend/team/ahachul_backend/api/comment/application/service/CommentServiceTest.kt index 35bfdacc..edd55605 100644 --- a/application/src/test/kotlin/backend/team/ahachul_backend/api/comment/application/service/CommentServiceTest.kt +++ b/application/src/test/kotlin/backend/team/ahachul_backend/api/comment/application/service/CommentServiceTest.kt @@ -58,7 +58,7 @@ class CommentServiceTest( private val membersCount: Int = 5 private fun loginWithMemberId(memberId: Long) { - RequestUtils.setAttribute("memberId", memberId) + RequestUtils.setAttribute(RequestUtils.Attribute.MEMBER_ID, memberId) } @BeforeEach fun setup() { @@ -73,7 +73,7 @@ class CommentServiceTest( status = MemberStatusType.ACTIVE ) ) - member.id.let { RequestUtils.setAttribute("memberId", it) } + member.id.let { RequestUtils.setAttribute(RequestUtils.Attribute.MEMBER_ID, it) } lateinit var postWriter: MemberEntity for (i in 1..membersCount) { diff --git a/application/src/test/kotlin/backend/team/ahachul_backend/api/community/application/service/CommunityPostServiceTest.kt b/application/src/test/kotlin/backend/team/ahachul_backend/api/community/application/service/CommunityPostServiceTest.kt index 94acbeb5..8679d794 100644 --- a/application/src/test/kotlin/backend/team/ahachul_backend/api/community/application/service/CommunityPostServiceTest.kt +++ b/application/src/test/kotlin/backend/team/ahachul_backend/api/community/application/service/CommunityPostServiceTest.kt @@ -55,7 +55,7 @@ class CommunityPostServiceTest( status = MemberStatusType.ACTIVE ) ) - member!!.id.let { RequestUtils.setAttribute("memberId", it) } + member!!.id.let { RequestUtils.setAttribute(RequestUtils.Attribute.MEMBER_ID, it) } subwayLine = subwayLineRepository.save(SubwayLineEntity(name = "1호선", regionType = RegionType.METROPOLITAN)) } @@ -132,7 +132,7 @@ class CommunityPostServiceTest( ) val (postId, _, _, _, _) = communityPostUseCase.createCommunityPost(createCommand) - RequestUtils.setAttribute("memberId", 2) + RequestUtils.setAttribute(RequestUtils.Attribute.MEMBER_ID, 2) val updateCommand = UpdateCommunityPostCommand( id = postId, diff --git a/application/src/test/kotlin/backend/team/ahachul_backend/api/complaint/application/service/ComplaintPostServiceTest.kt b/application/src/test/kotlin/backend/team/ahachul_backend/api/complaint/application/service/ComplaintPostServiceTest.kt index a277c21c..cbe27c2e 100644 --- a/application/src/test/kotlin/backend/team/ahachul_backend/api/complaint/application/service/ComplaintPostServiceTest.kt +++ b/application/src/test/kotlin/backend/team/ahachul_backend/api/complaint/application/service/ComplaintPostServiceTest.kt @@ -48,7 +48,7 @@ class ComplaintPostServiceTest( status = MemberStatusType.ACTIVE ) ) - member.id.let { RequestUtils.setAttribute("memberId", it)} + member.id.let { RequestUtils.setAttribute(RequestUtils.Attribute.MEMBER_ID, it)} subwayLine = subwayLineRepository.save( SubwayLineEntity( name = "1호선", diff --git a/application/src/test/kotlin/backend/team/ahachul_backend/api/lost/application/service/LostPostServiceTest.kt b/application/src/test/kotlin/backend/team/ahachul_backend/api/lost/application/service/LostPostServiceTest.kt index 941d0255..ee1eb33d 100644 --- a/application/src/test/kotlin/backend/team/ahachul_backend/api/lost/application/service/LostPostServiceTest.kt +++ b/application/src/test/kotlin/backend/team/ahachul_backend/api/lost/application/service/LostPostServiceTest.kt @@ -55,7 +55,7 @@ class LostPostServiceTest( status = MemberStatusType.ACTIVE ) ) - member.id.let { RequestUtils.setAttribute("memberId", it)} + member.id.let { RequestUtils.setAttribute(RequestUtils.Attribute.MEMBER_ID, it)} subwayLine = createSubwayLine("1호선") category = createCategory("휴대폰") } @@ -203,7 +203,7 @@ class LostPostServiceTest( ) // when, then - RequestUtils.setAttribute("memberId", member.id + 1) + RequestUtils.setAttribute(RequestUtils.Attribute.MEMBER_ID, member.id + 1) assertThatThrownBy { lostPostUseCase.updateLostPost(updateCommand) @@ -281,7 +281,7 @@ class LostPostServiceTest( val entity = lostPostUseCase.createLostPost(createCommand) // when, then - RequestUtils.setAttribute("memberId", member.id + 1) + RequestUtils.setAttribute(RequestUtils.Attribute.MEMBER_ID, member.id + 1) assertThatThrownBy { lostPostUseCase.deleteLostPost(entity.id) diff --git a/application/src/test/kotlin/backend/team/ahachul_backend/api/member/application/service/MemberServiceTest.kt b/application/src/test/kotlin/backend/team/ahachul_backend/api/member/application/service/MemberServiceTest.kt index 57c03e9e..765beb74 100644 --- a/application/src/test/kotlin/backend/team/ahachul_backend/api/member/application/service/MemberServiceTest.kt +++ b/application/src/test/kotlin/backend/team/ahachul_backend/api/member/application/service/MemberServiceTest.kt @@ -70,7 +70,7 @@ class MemberServiceTest( ageRange = "20", status = MemberStatusType.ACTIVE )) - member!!.id.let { RequestUtils.setAttribute("memberId", it) } + member!!.id.let { RequestUtils.setAttribute(RequestUtils.Attribute.MEMBER_ID, it) } } @ParameterizedTest @@ -102,7 +102,7 @@ class MemberServiceTest( val result = memberUseCase.getMember() // then - assertThat(result.memberId).isEqualTo(RequestUtils.getAttribute("memberId")!!.toLong()) + assertThat(result.memberId).isEqualTo(RequestUtils.getAttribute(RequestUtils.Attribute.MEMBER_ID)!!.toLong()) assertThat(result.email).isEqualTo("email") assertThat(result.gender).isEqualTo(GenderType.MALE) assertThat(result.ageRange).isEqualTo("20") diff --git a/application/src/test/kotlin/backend/team/ahachul_backend/api/report/application/service/CommunityPostReportServiceTest.kt b/application/src/test/kotlin/backend/team/ahachul_backend/api/report/application/service/CommunityPostReportServiceTest.kt index deeb8cd8..a4568fa1 100644 --- a/application/src/test/kotlin/backend/team/ahachul_backend/api/report/application/service/CommunityPostReportServiceTest.kt +++ b/application/src/test/kotlin/backend/team/ahachul_backend/api/report/application/service/CommunityPostReportServiceTest.kt @@ -38,7 +38,7 @@ class CommunityPostReportServiceTest( @BeforeEach fun setup() { member = memberRepository.save(createMember("닉네임1")) - member!!.id.let { RequestUtils.setAttribute("memberId", it) } + member!!.id.let { RequestUtils.setAttribute(RequestUtils.Attribute.MEMBER_ID, it) } otherMember = memberRepository.save(createMember("닉네임2")) subwayLine = createSubwayLine() } @@ -65,7 +65,7 @@ class CommunityPostReportServiceTest( val target = communityPostRepository.save(createCommunityPost()) // when, then - otherMember!!.id.let { RequestUtils.setAttribute("memberId", it) } + otherMember!!.id.let { RequestUtils.setAttribute(RequestUtils.Attribute.MEMBER_ID, it) } Assertions.assertThatThrownBy { communityPostReportService.save(target.id) @@ -102,16 +102,16 @@ class CommunityPostReportServiceTest( // when communityPostReportService.save(target.id) - RequestUtils.setAttribute("memberId", otherMember2.id) + RequestUtils.setAttribute(RequestUtils.Attribute.MEMBER_ID, otherMember2.id) communityPostReportService.save(target.id) - RequestUtils.setAttribute("memberId", otherMember3.id) + RequestUtils.setAttribute(RequestUtils.Attribute.MEMBER_ID, otherMember3.id) communityPostReportService.save(target.id) - RequestUtils.setAttribute("memberId", otherMember4.id) + RequestUtils.setAttribute(RequestUtils.Attribute.MEMBER_ID, otherMember4.id) communityPostReportService.save(target.id) - RequestUtils.setAttribute("memberId", otherMember5.id) + RequestUtils.setAttribute(RequestUtils.Attribute.MEMBER_ID, otherMember5.id) communityPostReportService.save(target.id) // then diff --git a/application/src/test/kotlin/backend/team/ahachul_backend/api/report/application/service/LostPostReportServiceTest.kt b/application/src/test/kotlin/backend/team/ahachul_backend/api/report/application/service/LostPostReportServiceTest.kt index e153df70..b739e88c 100644 --- a/application/src/test/kotlin/backend/team/ahachul_backend/api/report/application/service/LostPostReportServiceTest.kt +++ b/application/src/test/kotlin/backend/team/ahachul_backend/api/report/application/service/LostPostReportServiceTest.kt @@ -45,7 +45,7 @@ class LostPostReportServiceTest( member = memberRepository.save(createMember("닉네임1")) otherMember = memberRepository.save(createMember("닉네임2")) manager = memberRepository.save(createMember("관리자")) - member!!.id.let { RequestUtils.setAttribute("memberId", it) } + member!!.id.let { RequestUtils.setAttribute(RequestUtils.Attribute.MEMBER_ID, it) } subwayLine = createSubwayLine() category = categoryRepository.save(CategoryEntity(name = "핸드폰")) } @@ -72,7 +72,7 @@ class LostPostReportServiceTest( val target = lostPostRepository.save(createLostPost()) // when, then - otherMember!!.id.let { RequestUtils.setAttribute("memberId", it) } + otherMember!!.id.let { RequestUtils.setAttribute(RequestUtils.Attribute.MEMBER_ID, it) } Assertions.assertThatThrownBy { lostPostReportService.save(target.id) @@ -110,16 +110,16 @@ class LostPostReportServiceTest( // when lostPostReportService.save(target.id) - RequestUtils.setAttribute("memberId", otherMember2.id) + RequestUtils.setAttribute(RequestUtils.Attribute.MEMBER_ID, otherMember2.id) lostPostReportService.save(target.id) - RequestUtils.setAttribute("memberId", otherMember3.id) + RequestUtils.setAttribute(RequestUtils.Attribute.MEMBER_ID, otherMember3.id) lostPostReportService.save(target.id) - RequestUtils.setAttribute("memberId", otherMember4.id) + RequestUtils.setAttribute(RequestUtils.Attribute.MEMBER_ID, otherMember4.id) lostPostReportService.save(target.id) - RequestUtils.setAttribute("memberId", otherMember5.id) + RequestUtils.setAttribute(RequestUtils.Attribute.MEMBER_ID, otherMember5.id) lostPostReportService.save(target.id) // then diff --git a/application/src/test/kotlin/backend/team/ahachul_backend/api/train/application/service/TrainServiceTest.kt b/application/src/test/kotlin/backend/team/ahachul_backend/api/train/application/service/TrainServiceTest.kt index 186cd2b8..65a5eacb 100644 --- a/application/src/test/kotlin/backend/team/ahachul_backend/api/train/application/service/TrainServiceTest.kt +++ b/application/src/test/kotlin/backend/team/ahachul_backend/api/train/application/service/TrainServiceTest.kt @@ -57,7 +57,7 @@ class TrainServiceTest( status = MemberStatusType.ACTIVE ) ) - member.id.let { RequestUtils.setAttribute("memberId", it) } + member.id.let { RequestUtils.setAttribute(RequestUtils.Attribute.MEMBER_ID, it) } } @Test diff --git a/core/src/main/kotlin/backend/team/ahachul_backend/common/config/JpaConfig.kt b/core/src/main/kotlin/backend/team/ahachul_backend/common/config/JpaConfig.kt index 7c9eb987..49ce0357 100644 --- a/core/src/main/kotlin/backend/team/ahachul_backend/common/config/JpaConfig.kt +++ b/core/src/main/kotlin/backend/team/ahachul_backend/common/config/JpaConfig.kt @@ -18,13 +18,12 @@ class JpaConfig( ) { companion object { - private const val MEMBER_ID = "memberId" private const val UNAUTHORIZED_VALUE = "SYSTEM" } @Bean fun auditorProvider() = AuditorAware { - val memberId: String = RequestUtils.getAttribute(MEMBER_ID) ?: UNAUTHORIZED_VALUE + val memberId: String = RequestUtils.getAttribute(RequestUtils.Attribute.MEMBER_ID) ?: UNAUTHORIZED_VALUE Optional.of(memberId) } diff --git a/core/src/main/kotlin/backend/team/ahachul_backend/common/utils/RequestUtils.kt b/core/src/main/kotlin/backend/team/ahachul_backend/common/utils/RequestUtils.kt index 4c68de57..3ce7fdde 100644 --- a/core/src/main/kotlin/backend/team/ahachul_backend/common/utils/RequestUtils.kt +++ b/core/src/main/kotlin/backend/team/ahachul_backend/common/utils/RequestUtils.kt @@ -4,16 +4,20 @@ import org.springframework.web.context.request.RequestAttributes import org.springframework.web.context.request.RequestContextHolder class RequestUtils { + enum class Attribute (val key: String) { + MEMBER_ID("memberId") + } companion object { - fun setAttribute(key: String, value: Any) { + fun setAttribute(attribute: Attribute, value: Any) { RequestContextHolder.getRequestAttributes() - ?.setAttribute(key, value, RequestAttributes.SCOPE_REQUEST) + ?.setAttribute(attribute.key, value, RequestAttributes.SCOPE_REQUEST) + } - fun getAttribute(key: String): String? { + fun getAttribute(attribute: Attribute): String? { return RequestContextHolder.getRequestAttributes() - ?.getAttribute(key, RequestAttributes.SCOPE_REQUEST) + ?.getAttribute(attribute.key, RequestAttributes.SCOPE_REQUEST) ?.toString() } }