-
Notifications
You must be signed in to change notification settings - Fork 1
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
23 changed files
with
370 additions
and
4 deletions.
There are no files selected for viewing
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
26 changes: 26 additions & 0 deletions
26
Whatnow-Api/src/main/kotlin/com/depromeet/whatnow/api/promise/dto/PromiseCreateDto.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,26 @@ | ||
package com.depromeet.whatnow.api.promise.dto | ||
|
||
import com.depromeet.whatnow.common.vo.PlaceVo | ||
import com.depromeet.whatnow.domains.promise.domain.Promise | ||
import java.time.LocalDateTime | ||
|
||
data class PromiseCreateDto( | ||
val title: String, | ||
val mainUserId: Long, | ||
val meetPlace: PlaceVo?, | ||
val endTime: LocalDateTime, | ||
val inviteCode: String, | ||
) { | ||
companion object { | ||
fun of(p: Promise?, inviteCode: String): PromiseCreateDto { | ||
// Check if p is null and handle the null case appropriately | ||
if (p == null) { | ||
// Return a default or placeholder value for PromiseDto | ||
return PromiseCreateDto("", 1L, null, LocalDateTime.now(), "") | ||
} | ||
|
||
// Process non-null Promise object | ||
return PromiseCreateDto(p.title, p.mainUserId, p.meetPlace, p.endTime, inviteCode) | ||
} | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
...ow-Api/src/main/kotlin/com/depromeet/whatnow/api/promise/usecase/InviteCodeReadUseCase.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 com.depromeet.whatnow.api.promise.usecase | ||
|
||
import com.depromeet.whatnow.annotation.UseCase | ||
import com.depromeet.whatnow.domains.invitecode.adapter.InviteCodeAdapter | ||
|
||
@UseCase | ||
class InviteCodeReadUseCase( | ||
val inviteCodeAdapter: InviteCodeAdapter, | ||
) { | ||
fun findInviteCodeByPromiseId(promiseId: Long): String { | ||
return inviteCodeAdapter.findByPromiseId(promiseId).inviteCode | ||
} | ||
} |
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
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
60 changes: 60 additions & 0 deletions
60
...st/kotlin/com/depromeet/whatnow/domains/invitecode/service/InviteCodeDomainServiceTest.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,60 @@ | ||
package com.depromeet.whatnow.domains.invitecode.service | ||
|
||
import com.depromeet.whatnow.consts.INVITE_CODE_EXPIRED_TIME | ||
import com.depromeet.whatnow.domains.invitecode.adapter.InviteCodeAdapter | ||
import com.depromeet.whatnow.domains.invitecode.domain.InviteCodeRedisEntity | ||
import org.junit.jupiter.api.BeforeEach | ||
import org.junit.jupiter.api.Test | ||
import org.junit.jupiter.api.extension.ExtendWith | ||
import org.mockito.Mock | ||
import org.mockito.Mockito.`when` | ||
import org.mockito.junit.jupiter.MockitoExtension | ||
import kotlin.test.assertNotEquals | ||
|
||
@ExtendWith(MockitoExtension::class) | ||
class InviteCodeDomainServiceTest() { | ||
@Mock | ||
private lateinit var inviteCodeAdapter: InviteCodeAdapter | ||
|
||
private lateinit var inviteCodeDomainService: InviteCodeDomainService | ||
|
||
@BeforeEach | ||
fun setUp() { | ||
inviteCodeDomainService = InviteCodeDomainService(inviteCodeAdapter) | ||
} | ||
|
||
@Test | ||
fun `사전에 저장된 경우 약속 id로 초대 코드를 생성하지 않고 기존 값을 반환한다`() { | ||
// given | ||
val promiseId1 = 1L | ||
val promiseId2 = 2L | ||
|
||
`when`(inviteCodeAdapter.findByPromiseId(promiseId1)).thenReturn(InviteCodeRedisEntity(promiseId1, "code1", INVITE_CODE_EXPIRED_TIME)) | ||
`when`(inviteCodeAdapter.findByPromiseId(promiseId2)).thenReturn(InviteCodeRedisEntity(promiseId2, "code2", INVITE_CODE_EXPIRED_TIME)) | ||
|
||
// when | ||
val code1 = inviteCodeDomainService.upsertInviteCode(promiseId1) | ||
val code2 = inviteCodeDomainService.upsertInviteCode(promiseId2) | ||
|
||
// then | ||
assertNotEquals(code1, code2) | ||
} | ||
|
||
@Test | ||
fun `저장되지 않은 경우 약속 id로 매번 유니크한 초대 코드를 생성한다`() { | ||
// given | ||
val promiseId1 = 1L | ||
val promiseId2 = 2L | ||
|
||
// Mock the behavior of inviteCodeAdapter.findByPromiseId to use inviteCodeRepository | ||
`when`(inviteCodeAdapter.findByPromiseId(promiseId1)).thenCallRealMethod() | ||
`when`(inviteCodeAdapter.findByPromiseId(promiseId2)).thenCallRealMethod() | ||
|
||
// when | ||
val code1 = inviteCodeDomainService.upsertInviteCode(promiseId1) | ||
val code2 = inviteCodeDomainService.upsertInviteCode(promiseId2) | ||
|
||
// then | ||
assertNotEquals(code1, code2) | ||
} | ||
} |
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
5 changes: 5 additions & 0 deletions
5
Whatnow-Domain/src/main/kotlin/com/depromeet/whatnow/common/aop/verify/InviteCodeLength.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,5 @@ | ||
package com.depromeet.whatnow.common.aop.verify | ||
|
||
@Retention(AnnotationRetention.RUNTIME) | ||
@Target(AnnotationTarget.VALUE_PARAMETER) | ||
annotation class InviteCodeLength |
22 changes: 22 additions & 0 deletions
22
...c/main/kotlin/com/depromeet/whatnow/common/aop/verify/InviteCodeLengthValidationAspect.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,22 @@ | ||
package com.depromeet.whatnow.common.aop.verify | ||
|
||
import com.depromeet.whatnow.domains.invitecode.exception.InviteCodeFormatMismatchException | ||
import org.aspectj.lang.ProceedingJoinPoint | ||
import org.aspectj.lang.annotation.Around | ||
import org.aspectj.lang.annotation.Aspect | ||
import org.springframework.stereotype.Component | ||
|
||
@Aspect | ||
@Component | ||
class InviteCodeLengthValidationAspect { | ||
@Around("@annotation(com.depromeet.whatnow.common.aop.verify.InviteCodeLength)") | ||
fun validateInviteCodeFormat(joinPoint: ProceedingJoinPoint): Any? { | ||
val args = joinPoint.args | ||
val inviteCode = args[0] | ||
println("inviteCode: $inviteCode") | ||
if (inviteCode is String && inviteCode.length != 13) { | ||
throw InviteCodeFormatMismatchException.EXCEPTION | ||
} | ||
return joinPoint.proceed() | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
...ain/src/main/kotlin/com/depromeet/whatnow/domains/invitecode/adapter/InviteCodeAdapter.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,23 @@ | ||
package com.depromeet.whatnow.domains.invitecode.adapter | ||
|
||
import com.depromeet.whatnow.annotation.Adapter | ||
import com.depromeet.whatnow.domains.invitecode.domain.InviteCodeRedisEntity | ||
import com.depromeet.whatnow.domains.invitecode.exception.InviteCodeNotFoundException | ||
import com.depromeet.whatnow.domains.invitecode.repository.InviteCodeRepository | ||
import org.springframework.data.repository.findByIdOrNull | ||
|
||
@Adapter | ||
class InviteCodeAdapter( | ||
val inviteCodeRepository: InviteCodeRepository, | ||
) { | ||
fun save(inviteCodeRedisEntity: InviteCodeRedisEntity): InviteCodeRedisEntity { | ||
return inviteCodeRepository.save(inviteCodeRedisEntity) | ||
} | ||
fun findByPromiseId(promiseId: Long): InviteCodeRedisEntity { | ||
return inviteCodeRepository.findByIdOrNull(promiseId) ?: throw InviteCodeNotFoundException.EXCEPTION | ||
} | ||
|
||
fun findByInviteCode(inviteCode: String): InviteCodeRedisEntity { | ||
return inviteCodeRepository.findByInviteCode(inviteCode) ?: throw InviteCodeNotFoundException.EXCEPTION | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
.../src/main/kotlin/com/depromeet/whatnow/domains/invitecode/domain/InviteCodeRedisEntity.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,18 @@ | ||
package com.depromeet.whatnow.domains.invitecode.domain | ||
|
||
import org.springframework.data.annotation.Id | ||
import org.springframework.data.redis.core.RedisHash | ||
import org.springframework.data.redis.core.TimeToLive | ||
import org.springframework.data.redis.core.index.Indexed | ||
|
||
@RedisHash(value = "inviteCode") | ||
class InviteCodeRedisEntity( | ||
@Id | ||
var promiseId: Long, | ||
|
||
@Indexed | ||
var inviteCode: String, | ||
|
||
@TimeToLive // TTL | ||
var ttl: Long, | ||
) |
11 changes: 11 additions & 0 deletions
11
...com/depromeet/whatnow/domains/invitecode/exception/InviteCodeDuplicateCreatedException.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,11 @@ | ||
package com.depromeet.whatnow.domains.invitecode.exception | ||
|
||
import com.depromeet.whatnow.exception.WhatnowCodeException | ||
|
||
class InviteCodeDuplicateCreatedException : WhatnowCodeException( | ||
InviteCodeErrorCode.INVITE_CODE_DUPLICATE_CREATED, | ||
) { | ||
companion object { | ||
val EXCEPTION: WhatnowCodeException = InviteCodeDuplicateCreatedException() | ||
} | ||
} |
Oops, something went wrong.