Skip to content

Commit

Permalink
#62 - 유저는 차단된 유저 목록을 관리할 수 있다. (#79)
Browse files Browse the repository at this point in the history
* refactor: SignUp, SignIn Response 변경

* refactor: message delete 분리

senderDelete, receiverDelete로 분리

* refactor: BlockUser 컬럼 추가

messageId 추가

* refactor: 메시지 목록에 차단된 메시지 쿼리 수정

* feat: 차단된 메시지 목록 서비스 개발

* refactor: 차단 api 분리

* refactor: 수정사항에 따른 테스트 일부 수정

* refactor: SecurityConfig, CustomUrlFilter 설정 추가

* refactor: message block url 변경

* refactor: messages -> messageIds 로 변경

* refactor: BlockedUser 수정
  • Loading branch information
sectionr0 authored Aug 8, 2024
1 parent 98e6974 commit 55eadc5
Show file tree
Hide file tree
Showing 39 changed files with 600 additions and 249 deletions.
6 changes: 4 additions & 2 deletions app/src/main/kotlin/com/wespot/auth/AuthController.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import com.wespot.auth.dto.request.AuthLoginRequest
import com.wespot.auth.dto.request.RefreshTokenRequest
import com.wespot.auth.dto.request.SignUpRequest
import com.wespot.auth.dto.response.SignUpResponse
import com.wespot.auth.dto.response.TokenAndUserDetailResponse
import com.wespot.auth.dto.response.TokenResponse
import com.wespot.auth.service.AuthService
import org.springframework.http.HttpStatus
Expand All @@ -26,7 +27,8 @@ class AuthController(
val response = authService.socialAccess(request)

return if (response is SignUpResponse) {
ResponseEntity.status(HttpStatus.ACCEPTED).body(response)
ResponseEntity.status(HttpStatus.ACCEPTED)
.body(response)
} else {
ResponseEntity.ok()
.body(response)
Expand All @@ -36,7 +38,7 @@ class AuthController(
@PostMapping("/signup")
fun signUp(
@RequestBody request: SignUpRequest
): ResponseEntity<TokenResponse> {
): ResponseEntity<TokenAndUserDetailResponse> {
val signUp = authService.signUp(request)

return ResponseEntity.ok()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,18 @@ class CustomUrlFilter(
"/api/v1/auth/login",
"/api/v1/auth/signup",
"/api/v1/auth/revoke",
"/api/v1/check-profanity",
"/api/v1/schools/search",
"/api/v1/users/me",
"/api/v1/users/backgrounds",
"/api/v1/users/characters",
"/api/v1/users/search",
"/api/v1/messages",
"/api/v1/messages/send",
"/api/v1/messages/status/me",
"/api/v1/messages/check-profanity",
"/api/v1/messages/scheduled",
"/api/v1/messages/block",
"/api/v1/messages/unblock",
"/api/v1/messages/**",
"/api/v1/votes/**",
"/api/v1/reports/**",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ class SecurityConfig(
"/api/v1/users/backgrounds",
"/api/v1/users/characters",
"/api/v1/users/search",
"/api/v1/schools/search",
"/api/v1/check-profanity",
).permitAll()
.anyRequest().authenticated()
}
Expand Down
16 changes: 12 additions & 4 deletions app/src/main/kotlin/com/wespot/message/GetMessageController.kt
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
package com.wespot.message

import com.wespot.message.dto.response.MessageListResponse
import com.wespot.message.dto.response.MessageResponse
import com.wespot.message.dto.response.MessageSimpleListResponse
import com.wespot.message.dto.response.SendMessageStatusResponse
import com.wespot.message.dto.response.*
import com.wespot.message.port.`in`.GetMessageUseCase
import org.springframework.http.ResponseEntity
import org.springframework.web.bind.annotation.*
Expand Down Expand Up @@ -55,4 +52,15 @@ class GetMessageController(
.body(response)
}

@GetMapping("/blocked")
fun getBlockedMessages(
@RequestParam(required = false, defaultValue = "0") cursorId: Long,
): ResponseEntity<MessageBlockedListResponse> {
val response = getMessageUseCase.getBlockedMessages(cursorId)

return ResponseEntity.ok()
.body(response)
}


}
17 changes: 11 additions & 6 deletions app/src/main/kotlin/com/wespot/user/BlockedUserController.kt
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package com.wespot.user

import com.wespot.user.dto.response.BlockedUserResponse
import com.wespot.user.port.`in`.BlockedUserUseCase
import org.springframework.http.ResponseEntity
import org.springframework.web.bind.annotation.DeleteMapping
import org.springframework.web.bind.annotation.PathVariable
import org.springframework.web.bind.annotation.PostMapping
import org.springframework.web.bind.annotation.RequestMapping
Expand All @@ -14,12 +16,15 @@ class BlockedUserController(
) {

@PostMapping("/{messageId}/block")
fun blockUser(@PathVariable messageId: Long): ResponseEntity<Unit> {
return if (blockedUserUseCase.blockedUser(messageId)) {
ResponseEntity.ok().build()
} else {
ResponseEntity.noContent().build()
}
fun blockUser(@PathVariable messageId: Long): ResponseEntity<BlockedUserResponse> {
val blockedUser = blockedUserUseCase.blockedUser(messageId)
return ResponseEntity.ok().body(blockedUser)
}

@PostMapping("/{messageId}/unblock")
fun unblockUser(@PathVariable messageId: Long): ResponseEntity<Unit> {
blockedUserUseCase.unblockedUser(messageId)
return ResponseEntity.noContent().build()
}

}
31 changes: 23 additions & 8 deletions app/src/test/kotlin/com/wespot/auth/service/AuthServiceTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@ import com.wespot.auth.dto.AuthData
import com.wespot.auth.dto.request.AuthLoginRequest
import com.wespot.auth.dto.request.RefreshTokenRequest
import com.wespot.auth.dto.request.SignInRequest
import com.wespot.auth.dto.response.SignUpResponse
import com.wespot.auth.dto.response.SocialResponse
import com.wespot.auth.dto.response.TokenResponse
import com.wespot.auth.dto.response.*
import com.wespot.auth.fixture.AuthFixture
import com.wespot.auth.port.out.AuthDataPort
import com.wespot.auth.port.out.RefreshTokenPort
Expand Down Expand Up @@ -130,10 +128,16 @@ class AuthServiceTest : BehaviorSpec({

`when`("기존 사용자가 loginAccess를 호출할 때") {
val user = UserFixture.createWithId(1)
val tokenResponse = TokenResponse(
val tokenResponse = TokenAndUserDetailResponse(
accessToken = "accessToken",
refreshToken = "refreshToken",
refreshTokenExpiredAt = refreshTokenExpiredAt
refreshTokenExpiredAt = refreshTokenExpiredAt,
setting = SettingResponse(
isMessageNotification = false,
isVoteNotification = false,
isMarketingNotification = user.userConsent.consentValue ?: false
),
name = user.name
)

every { userPort.findByEmail(formatSocialEmail) } returns user
Expand Down Expand Up @@ -168,13 +172,24 @@ class AuthServiceTest : BehaviorSpec({
val authData = AuthFixture.createAuthData()
val user = AuthFixture.createUser()
val refreshTokenExpiredAt = getExpirationLocalDateTime(60 * 60 * 24 * 30).toString()

val generateToken = AuthFixture.createTokenResponse(refreshTokenExpiredAt)
val tokenAndUserDetailResponse = TokenAndUserDetailResponse(
accessToken = generateToken.accessToken,
refreshToken = generateToken.refreshToken,
refreshTokenExpiredAt = generateToken.refreshTokenExpiredAt,
setting = SettingResponse(
isMessageNotification = false,
isVoteNotification = false,
isMarketingNotification = signUpRequest.consents.marketing
),
name = user.name
)
every { authService.checkSignUpToken(signUpRequest.signUpToken) } returns authData
every { authService.createUser(authData, signUpRequest) } returns user
every { userPort.existsBySchoolIdAndGradeAndClassNumber(any(), any(), any()) } returns true
every { userPort.save(any()) } returns user
every { authService.saveRelatedEntities(user, signUpRequest) } just Runs
every { authService.signIn(any()) } returns AuthFixture.createTokenResponse(refreshTokenExpiredAt)
every { authService.signIn(any()) } returns tokenAndUserDetailResponse

`when`("사용자가 signUp을 호출할 때") {
val response = authService.signUp(signUpRequest)
Expand All @@ -196,7 +211,7 @@ class AuthServiceTest : BehaviorSpec({
email = authData.email,
password = "${authData.email}$secretKey"
)
authService.signIn(signInRequest) shouldBe AuthFixture.createTokenResponse(refreshTokenExpiredAt)
authService.signIn(signInRequest) shouldBe tokenAndUserDetailResponse
}

then("TokenResponse를 반환한다") {
Expand Down
4 changes: 2 additions & 2 deletions app/src/test/kotlin/com/wespot/message/domain/MessageTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ class MessageTest : BehaviorSpec({
val reportedMessage = message.reported(2)

then("메시지 신고 처리가 된다.") {
reportedMessage.isDeleted shouldBe true
reportedMessage.isReceiverDeleted shouldBe true
reportedMessage.isReported shouldBe true
reportedMessage.deletedAt shouldBe now
reportedMessage.receiverDeletedAt shouldBe now
reportedMessage.updatedAt shouldBe now
}
}
Expand Down
18 changes: 12 additions & 6 deletions app/src/test/kotlin/com/wespot/message/fixture/MessageFixture.kt
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,10 @@ object MessageFixture {
updatedAt = LocalDateTime.now(),
receivedAt = LocalDateTime.now(),
isReported = false,
isDeleted = false,
deletedAt = null
isSenderDeleted = false,
senderDeletedAt = null,
isReceiverDeleted = false,
receiverDeletedAt = null
)

fun createWithIdAndSenderIdAndReceiverId(id: Long, senderId: Long, receiverId: Long) = Message(
Expand All @@ -43,8 +45,10 @@ object MessageFixture {
updatedAt = LocalDateTime.now(),
receivedAt = LocalDateTime.now(),
isReported = false,
isDeleted = false,
deletedAt = null
isSenderDeleted = false,
senderDeletedAt = null,
isReceiverDeleted = false,
receiverDeletedAt = null
)

fun createMessageWithReceived(
Expand All @@ -69,8 +73,10 @@ object MessageFixture {
createdAt = LocalDateTime.now(),
updatedAt = LocalDateTime.now(),
isReported = false,
isDeleted = false,
deletedAt = null
isSenderDeleted = false,
senderDeletedAt = null,
isReceiverDeleted = false,
receiverDeletedAt = null
)
}

Expand Down
Loading

0 comments on commit 55eadc5

Please sign in to comment.