Skip to content

Commit

Permalink
RequestUtils key값을 enum class로 받도록 수정 (#299)
Browse files Browse the repository at this point in the history
* RequestUtils key값을 enum class로 받도록 수정

* 🐛 RequestUtils 메소드가 파라미터를 enum class로 받도록 수정
  • Loading branch information
hwgyun authored Feb 23, 2025
1 parent db4c5a9 commit 127fbe8
Show file tree
Hide file tree
Showing 22 changed files with 68 additions and 64 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ class CommunityPostService(
private val logger = NamedLogger("HASHTAG_LOGGER")

override fun searchCommunityPosts(command: SearchCommunityPostCommand): PageInfoDto<SearchCommunityPostDto.Response> {
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(
Expand All @@ -66,7 +66,7 @@ class CommunityPostService(
}

override fun searchCommunityHotPosts(command: SearchCommunityHotPostCommand): PageInfoDto<SearchCommunityPostDto.Response> {
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(
Expand All @@ -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) {
Expand All @@ -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))
Expand All @@ -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)
Expand All @@ -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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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)

Expand All @@ -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) {
Expand All @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) }
Expand All @@ -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)

Expand Down Expand Up @@ -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) {
Expand All @@ -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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) }
Expand All @@ -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)) {
Expand All @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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!!
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}

Expand Down Expand Up @@ -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")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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))

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}

Expand Down Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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호선",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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("휴대폰")
}
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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")
Expand Down
Loading

0 comments on commit 127fbe8

Please sign in to comment.