-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
282 additions
and
16 deletions.
There are no files selected for viewing
15 changes: 15 additions & 0 deletions
15
simtong-application/src/main/kotlin/team/comit/simtong/domain/file/spi/CheckFilePort.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package team.comit.simtong.domain.file.spi | ||
|
||
/** | ||
* | ||
* 파일 확인을 요청하는 CheckFilePort | ||
* | ||
* @author Chokyunghyeon | ||
* @date 2022/10/11 | ||
* @version 1.0.0 | ||
**/ | ||
interface CheckFilePort { | ||
|
||
fun existsPath(path: String): Boolean | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 13 additions & 0 deletions
13
...plication/src/main/kotlin/team/comit/simtong/domain/user/dto/ChangeProfileImageRequest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package team.comit.simtong.domain.user.dto | ||
|
||
/** | ||
* | ||
* 프로필 사진 변경 요청 정보를 전달하는 ChangeProfileImageRequest | ||
* | ||
* @author Chokyunghyeon | ||
* @date 2022/10/03 | ||
* @version 1.0.0 | ||
**/ | ||
data class ChangeProfileImageRequest( | ||
val profileImagePath: String | ||
) |
43 changes: 43 additions & 0 deletions
43
...ation/src/main/kotlin/team/comit/simtong/domain/user/usecase/ChangeProfileImageUseCase.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package team.comit.simtong.domain.user.usecase | ||
|
||
import team.comit.simtong.domain.file.exception.NotFoundFilePathException | ||
import team.comit.simtong.domain.file.spi.CheckFilePort | ||
import team.comit.simtong.domain.user.dto.ChangeProfileImageRequest | ||
import team.comit.simtong.domain.user.exception.UserNotFoundException | ||
import team.comit.simtong.domain.user.spi.CommandUserPort | ||
import team.comit.simtong.domain.user.spi.QueryUserPort | ||
import team.comit.simtong.domain.user.spi.UserSecurityPort | ||
import team.comit.simtong.global.annotation.UseCase | ||
|
||
/** | ||
* | ||
* 프로필 사진 변경을 담당하는 ChangeProfileImageUseCase | ||
* | ||
* @author Chokyunghyeon | ||
* @date 2022/10/03 | ||
* @version 1.0.0 | ||
**/ | ||
@UseCase | ||
class ChangeProfileImageUseCase( | ||
private val queryUserPort: QueryUserPort, | ||
private val userSecurityPort: UserSecurityPort, | ||
private val commandUserPort: CommandUserPort, | ||
private val checkFilePort: CheckFilePort | ||
) { | ||
|
||
fun execute(request: ChangeProfileImageRequest) { | ||
if (!checkFilePort.existsPath(request.profileImagePath)) { | ||
throw NotFoundFilePathException.EXCEPTION | ||
} | ||
|
||
val currentUserId = userSecurityPort.getCurrentUserId() | ||
val user = queryUserPort.queryUserById(currentUserId) ?: throw UserNotFoundException.EXCEPTION | ||
|
||
commandUserPort.save( | ||
user.copy( | ||
profileImagePath = request.profileImagePath | ||
) | ||
) | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
120 changes: 120 additions & 0 deletions
120
.../src/test/kotlin/team/comit/simtong/domain/user/usecase/ChangeProfileImageUseCaseTests.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,120 @@ | ||
package team.comit.simtong.domain.user.usecase | ||
|
||
import org.junit.jupiter.api.BeforeEach | ||
import org.junit.jupiter.api.Test | ||
import org.junit.jupiter.api.assertDoesNotThrow | ||
import org.junit.jupiter.api.assertThrows | ||
import org.junit.jupiter.api.extension.ExtendWith | ||
import org.mockito.BDDMockito.given | ||
import org.springframework.boot.test.mock.mockito.MockBean | ||
import org.springframework.test.context.junit.jupiter.SpringExtension | ||
import team.comit.simtong.domain.file.exception.NotFoundFilePathException | ||
import team.comit.simtong.domain.file.spi.CheckFilePort | ||
import team.comit.simtong.domain.user.dto.ChangeProfileImageRequest | ||
import team.comit.simtong.domain.user.exception.UserNotFoundException | ||
import team.comit.simtong.domain.user.model.Authority | ||
import team.comit.simtong.domain.user.model.User | ||
import team.comit.simtong.domain.user.spi.CommandUserPort | ||
import team.comit.simtong.domain.user.spi.QueryUserPort | ||
import team.comit.simtong.domain.user.spi.UserSecurityPort | ||
import java.util.UUID | ||
|
||
@ExtendWith(SpringExtension::class) | ||
class ChangeProfileImageUseCaseTests { | ||
|
||
@MockBean | ||
private lateinit var queryUserPort: QueryUserPort | ||
|
||
@MockBean | ||
private lateinit var userSecurityPort: UserSecurityPort | ||
|
||
@MockBean | ||
private lateinit var commandUserPort: CommandUserPort | ||
|
||
@MockBean | ||
private lateinit var checkFilePort: CheckFilePort | ||
|
||
private lateinit var changeProfileImageUseCase: ChangeProfileImageUseCase | ||
|
||
private val id = UUID.randomUUID() | ||
|
||
private val requestStub: ChangeProfileImageRequest by lazy { | ||
ChangeProfileImageRequest( | ||
profileImagePath = "test path" | ||
) | ||
} | ||
|
||
private val userStub: User by lazy { | ||
User( | ||
id = id, | ||
nickname = "test nickname", | ||
name = "test name", | ||
email = "test email", | ||
password = "test password", | ||
employeeNumber = 1234567890, | ||
authority = Authority.ROLE_COMMON, | ||
spotId = id, | ||
teamId = id, | ||
profileImagePath = "test path" | ||
) | ||
} | ||
|
||
@BeforeEach | ||
fun setUp() { | ||
changeProfileImageUseCase = ChangeProfileImageUseCase( | ||
queryUserPort, | ||
userSecurityPort, | ||
commandUserPort, | ||
checkFilePort | ||
) | ||
} | ||
|
||
@Test | ||
fun `프로필 사진 변경 성공`() { | ||
// given | ||
given(checkFilePort.existsPath(requestStub.profileImagePath)) | ||
.willReturn(true) | ||
|
||
given(userSecurityPort.getCurrentUserId()) | ||
.willReturn(id) | ||
|
||
given(queryUserPort.queryUserById(id)) | ||
.willReturn(userStub) | ||
|
||
// when & then | ||
assertDoesNotThrow { | ||
changeProfileImageUseCase.execute(requestStub) | ||
} | ||
} | ||
|
||
@Test | ||
fun `업로드되지 않은 사진 경로`() { | ||
// given | ||
given(checkFilePort.existsPath(requestStub.profileImagePath)) | ||
.willReturn(false) | ||
|
||
// when & then | ||
assertThrows<NotFoundFilePathException> { | ||
changeProfileImageUseCase.execute(requestStub) | ||
} | ||
} | ||
|
||
@Test | ||
fun `유저를 찾을 수 없음`() { | ||
// given | ||
given(checkFilePort.existsPath(requestStub.profileImagePath)) | ||
.willReturn(true) | ||
|
||
given(userSecurityPort.getCurrentUserId()) | ||
.willReturn(id) | ||
|
||
given(queryUserPort.queryUserById(id)) | ||
.willReturn(null) | ||
|
||
// when & then | ||
assertThrows<UserNotFoundException> { | ||
changeProfileImageUseCase.execute(requestStub) | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 13 additions & 0 deletions
13
...ain/src/main/kotlin/team/comit/simtong/domain/file/exception/NotFoundFilePathException.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package team.comit.simtong.domain.file.exception | ||
|
||
import team.comit.simtong.domain.file.error.FileErrorCode | ||
import team.comit.simtong.global.error.BusinessException | ||
|
||
class NotFoundFilePathException private constructor() : BusinessException(FileErrorCode.NOT_FOUND_FILE_PATH) { | ||
|
||
companion object { | ||
@JvmField | ||
val EXCEPTION = NotFoundFilePathException() | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.