Skip to content

Commit

Permalink
Merge pull request #13 from HappyScrolls/feature/#11_invite_code
Browse files Browse the repository at this point in the history
Feature/#11 invite code
  • Loading branch information
chs98412 authored Oct 7, 2024
2 parents 52066f5 + d0c5869 commit 4327687
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,11 @@ class CoupleCommandService(
}

suspend fun createCouple(command: CoupleCreateCommand) {
val memberNo = redisTemplate.opsForValue().getAndAwait(command.inviteCode) ?: throw InvalidInviteCodeException("유효하지 않은 초대코드입니다.")
coupleRepository.findByAccountNoAOrAccountNoB(memberNo.toInt(), command.accountNoB)?.let {
val memberNo = redisTemplate.opsForValue().getAndAwait(command.inviteCode)?.toInt() ?: throw InvalidInviteCodeException("유효하지 않은 초대코드입니다.")
coupleRepository.findByAccountNoAOrAccountNoB(memberNo, command.accountNoB)?.let {
throw CoupleExistException("이미 커플이 존재하는 회원입니다.")
}
coupleRepository.save(Couple.create(command))
coupleRepository.save(Couple.create(memberNo,command.accountNoB))
}

fun modifyCoupleInfo(memberNo: Int, command: CoupleInfoModifyCommand) {
Expand All @@ -48,8 +48,9 @@ class CoupleCommandService(

}

suspend fun createInviteCode(memberNo: Int) {
suspend fun createInviteCode(memberNo: Int):String {
val code=memberNo.toString()+LocalDateTime.now()
redisTemplate.opsForValue().setAndAwait(code.encodeDtoToBase64(),memberNo.toString(), Duration.ofMinutes(5))
return code.encodeDtoToBase64()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,9 @@ class Couple(
}

companion object {
fun create(command: CoupleCreateCommand)=Couple(
accountNoA = command.accountNoA,
accountNoB = command.accountNoB
fun create(accountNoA:Int,accountNoB:Int)=Couple(
accountNoA = accountNoA,
accountNoB = accountNoB
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,5 @@ package com.yedongsoon.account_service.domain.member.model

data class CoupleCreateCommand(
val inviteCode:String,
val accountNoA: Int?=null,
val accountNoB: Int,
)
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package com.yedongsoon.account_service.infrastructure

import org.springframework.context.annotation.Bean
import org.springframework.context.annotation.Configuration
import org.springframework.context.annotation.Primary
import org.springframework.data.redis.connection.ReactiveRedisConnectionFactory
import org.springframework.data.redis.core.ReactiveRedisTemplate
import org.springframework.data.redis.serializer.RedisSerializationContext
Expand All @@ -11,6 +12,7 @@ import org.springframework.data.redis.serializer.StringRedisSerializer
class RedisConfig {

@Bean
@Primary
fun reactiveRedisTemplate(factory: ReactiveRedisConnectionFactory): ReactiveRedisTemplate<String, String> {
val serializationContext = RedisSerializationContext
.newSerializationContext<String, String>(StringRedisSerializer())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,8 @@ class CoupleHandler(
suspend fun createInviteCode(request: ServerRequest): ServerResponse = withContext(Dispatchers.IO) {
val memberHeader = request.extractMemberCodeHeader()

coupleCommandService.createInviteCode(memberHeader.no)
val code= coupleCommandService.createInviteCode(memberHeader.no)

ServerResponse.ok().buildAndAwait()
ServerResponse.ok().bodyValueAndAwait(code)
}
}
6 changes: 6 additions & 0 deletions src/test/http/couple.http
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,9 @@ Member-Code: eyJubyI6MSwibmFtZSI6Im5hbWUiLCJhY2NvdW50IjoiYWNjb3VudCJ9
GET {{url}}/couple/lover
Content-Type: application/json
Member-Code: eyJubyI6MSwibmFtZSI6Im5hbWUiLCJhY2NvdW50IjoiYWNjb3VudCJ9

### 초대 코드
POST {{url}}/couple/invite-code
Content-Type: application/json
Member-Code: eyJubyI6MSwibmFtZSI6Im5hbWUiLCJhY2NvdW50IjoiYWNjb3VudCJ9

0 comments on commit 4327687

Please sign in to comment.