-
Notifications
You must be signed in to change notification settings - Fork 0
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
40 changed files
with
794 additions
and
59 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
54 changes: 54 additions & 0 deletions
54
src/main/kotlin/com/yedongsoon/example_project/application/couple/CoupleCommandService.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,54 @@ | ||
package com.yedongsoon.example_project.application.couple | ||
|
||
import com.yedongsoon.example_project.application.exception.CoupleExistException | ||
import com.yedongsoon.example_project.application.exception.CoupleNotFoundException | ||
import com.yedongsoon.example_project.application.exception.InvalidInviteCodeException | ||
import com.yedongsoon.example_project.domain.couple.Couple | ||
import com.yedongsoon.example_project.domain.couple.CoupleRepository | ||
import com.yedongsoon.example_project.domain.extension.encodeDtoToBase64 | ||
import com.yedongsoon.example_project.domain.member.model.CoupleCreateCommand | ||
import com.yedongsoon.example_project.domain.member.model.CoupleInfoCreateCommand | ||
import com.yedongsoon.example_project.domain.member.model.CoupleInfoModifyCommand | ||
import org.springframework.data.redis.core.ReactiveRedisTemplate | ||
import org.springframework.data.redis.core.getAndAwait | ||
import org.springframework.data.redis.core.setAndAwait | ||
import org.springframework.stereotype.Service | ||
import java.time.Duration | ||
import java.time.LocalDateTime | ||
|
||
@Service | ||
class CoupleCommandService( | ||
private val coupleRepository: CoupleRepository, | ||
private val redisTemplate: ReactiveRedisTemplate<String, String> | ||
) { | ||
fun createCoupleInfo(command: CoupleInfoCreateCommand) { | ||
coupleRepository.findByAccountNoAOrAccountNoB(command.memberNo, command.memberNo)?.let { | ||
it.createInfo(command) | ||
coupleRepository.save(it) | ||
} ?: throw CoupleNotFoundException("커플 정보가 존재하지 않습니다") | ||
} | ||
|
||
suspend fun createCouple(command: CoupleCreateCommand) { | ||
val memberNo = redisTemplate.opsForValue().getAndAwait(command.inviteCode)?.toInt() | ||
?: throw InvalidInviteCodeException("유효하지 않은 초대코드입니다.") | ||
coupleRepository.findByAccountNoAOrAccountNoB(memberNo, command.accountNoB)?.let { | ||
throw CoupleExistException("이미 커플이 존재하는 회원입니다.") | ||
} | ||
coupleRepository.save(Couple.create(memberNo, command.accountNoB)) | ||
} | ||
|
||
fun modifyCoupleInfo(memberNo: Int, command: CoupleInfoModifyCommand) { | ||
coupleRepository.findByAccountNoAOrAccountNoB(memberNo, memberNo)?.let { | ||
it.modify(command) | ||
coupleRepository.save(it) | ||
} ?: throw CoupleExistException("이미 커플이 존재하는 회원입니다.") | ||
|
||
|
||
} | ||
|
||
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() | ||
} | ||
} |
31 changes: 31 additions & 0 deletions
31
src/main/kotlin/com/yedongsoon/example_project/application/couple/CoupleQueryService.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,31 @@ | ||
package com.yedongsoon.example_project.application.couple | ||
|
||
import com.yedongsoon.example_project.application.exception.CoupleNotFoundException | ||
import com.yedongsoon.example_project.application.exception.MemberNotFoundException | ||
import com.yedongsoon.example_project.domain.couple.Couple | ||
import com.yedongsoon.example_project.domain.couple.CoupleRepository | ||
import com.yedongsoon.example_project.domain.member.Member | ||
import com.yedongsoon.example_project.domain.member.MemberRepository | ||
import org.springframework.data.crossstore.ChangeSetPersister | ||
import org.springframework.stereotype.Service | ||
|
||
|
||
@Service | ||
class CoupleQueryService( | ||
private val coupleRepository: CoupleRepository, | ||
private val memberRepository: MemberRepository, | ||
) { | ||
fun getDetail(accountNo: Int): Couple { | ||
return coupleRepository.findByAccountNoAOrAccountNoB(accountNo, accountNo) | ||
?: throw ChangeSetPersister.NotFoundException() | ||
} | ||
|
||
fun getLover(accountNo: Int): Member { | ||
val loverNo = coupleRepository.findByAccountNoAOrAccountNoB(accountNo, accountNo).let { | ||
if (it?.accountNoA == accountNo) it.accountNoB else it?.accountNoA | ||
} ?: throw CoupleNotFoundException("커플이 존재하지 않습니다.") | ||
|
||
|
||
return memberRepository.findByNo(loverNo) ?: throw MemberNotFoundException("사용자가 존재하지 않습니다.") | ||
} | ||
} |
9 changes: 0 additions & 9 deletions
9
src/main/kotlin/com/yedongsoon/example_project/application/couple/CoupleService.kt
This file was deleted.
Oops, something went wrong.
12 changes: 0 additions & 12 deletions
12
...in/kotlin/com/yedongsoon/example_project/application/couple/model/CoupleDetailResponse.kt
This file was deleted.
Oops, something went wrong.
11 changes: 0 additions & 11 deletions
11
...n/kotlin/com/yedongsoon/example_project/application/couple/model/CouplePartnerResponse.kt
This file was deleted.
Oops, something went wrong.
8 changes: 8 additions & 0 deletions
8
src/main/kotlin/com/yedongsoon/example_project/application/exception/CoupleException.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,8 @@ | ||
package com.yedongsoon.example_project.application.exception | ||
|
||
import org.springframework.http.HttpStatus | ||
|
||
class CoupleNotFoundException(message: String) : AbstractException(HttpStatus.NOT_FOUND, message) | ||
class CoupleExistException(message: String) : AbstractException(HttpStatus.BAD_REQUEST, message) | ||
class InvalidInviteCodeException(message: String) : AbstractException(HttpStatus.BAD_REQUEST, message) | ||
|
7 changes: 7 additions & 0 deletions
7
src/main/kotlin/com/yedongsoon/example_project/application/exception/MemberException.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,7 @@ | ||
package com.yedongsoon.example_project.application.exception | ||
|
||
import org.springframework.http.HttpStatus | ||
|
||
class MemberAdditionalInfoExistsException(message: String) : AbstractException(HttpStatus.BAD_REQUEST, message) | ||
class MemberNotFoundException(message: String) : AbstractException(HttpStatus.NOT_FOUND, message) | ||
|
34 changes: 34 additions & 0 deletions
34
src/main/kotlin/com/yedongsoon/example_project/application/member/MemberCommandService.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,34 @@ | ||
package com.yedongsoon.example_project.application.member | ||
|
||
|
||
import com.yedongsoon.example_project.application.exception.MemberAdditionalInfoExistsException | ||
import com.yedongsoon.example_project.application.exception.MemberNotFoundException | ||
import com.yedongsoon.example_project.domain.member.MemberRepository | ||
import com.yedongsoon.example_project.domain.member.model.MemberAdditionalInfoCommand | ||
import com.yedongsoon.example_project.domain.member.model.MemberInfoModifyCommand | ||
import jakarta.transaction.Transactional | ||
import org.springframework.data.repository.findByIdOrNull | ||
import org.springframework.stereotype.Service | ||
|
||
|
||
@Service | ||
class MemberCommandService( | ||
private val memberRepository: MemberRepository, | ||
) { | ||
@Transactional | ||
suspend fun createAdditional(command: MemberAdditionalInfoCommand) { | ||
memberRepository.findByIdOrNull(command.memberNo)?.also { | ||
if (it.birthDate != null && it.mobileNo != null) throw MemberAdditionalInfoExistsException("추가 정보를 이미 입력한 유저입니다.") | ||
it.createAdditionalInfo(command) | ||
memberRepository.save(it) //트랜잭션 수정후 제거 | ||
} ?: throw throw MemberNotFoundException("유저를 찾을 수 없습니다") | ||
} | ||
|
||
@Transactional | ||
suspend fun modifyMemberInfo(command: MemberInfoModifyCommand) { | ||
memberRepository.findByIdOrNull(command.memberNo)?.also { | ||
it.modify(command) | ||
memberRepository.save(it) //트랜잭션 수정후 제거 | ||
} ?: throw throw MemberNotFoundException("유저를 찾을 수 없습니다") | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
src/main/kotlin/com/yedongsoon/example_project/application/member/MemberQueryService.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,16 @@ | ||
package com.yedongsoon.example_project.application.member | ||
|
||
import com.yedongsoon.example_project.application.exception.MemberNotFoundException | ||
import com.yedongsoon.example_project.domain.member.Member | ||
import com.yedongsoon.example_project.domain.member.MemberRepository | ||
import org.springframework.data.repository.findByIdOrNull | ||
import org.springframework.stereotype.Service | ||
|
||
@Service | ||
class MemberQueryService( | ||
private val memberRepository: MemberRepository, | ||
) { | ||
suspend fun getMember(memberNo: Int): Member { | ||
return memberRepository.findByIdOrNull(memberNo) ?: throw throw MemberNotFoundException("유저를 찾을 수 없습니다") | ||
} | ||
} |
70 changes: 70 additions & 0 deletions
70
src/main/kotlin/com/yedongsoon/example_project/domain/couple/Couple.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,70 @@ | ||
package com.yedongsoon.example_project.domain.couple | ||
|
||
import com.yedongsoon.example_project.domain.member.model.CoupleInfoCreateCommand | ||
import com.yedongsoon.example_project.domain.member.model.CoupleInfoModifyCommand | ||
import jakarta.persistence.* | ||
import java.time.LocalDate | ||
import java.time.LocalDateTime | ||
|
||
@Entity | ||
@Table(name = "couple") | ||
class Couple( | ||
@Id | ||
@GeneratedValue(strategy = GenerationType.IDENTITY) | ||
@Column(name = "couple_no") | ||
val no: Int = 0, | ||
|
||
@Column(name = "account_no_a") | ||
val accountNoA: Int, | ||
|
||
@Column(name = "account_no_b") | ||
val accountNoB: Int, | ||
|
||
) { | ||
@Column(name = "couple_name") | ||
var name: String? = null | ||
private set | ||
|
||
@Column(name = "nick_name_a") | ||
var nickNameA: String? = null | ||
private set | ||
|
||
@Column(name = "nick_name_b") | ||
var nickNameB: String? = null | ||
private set | ||
|
||
@Column(name = "started_at") | ||
var startedAt: LocalDate? = null | ||
private set | ||
|
||
@Column(name = "couple_img") | ||
var coupleImg: String? = null | ||
private set | ||
|
||
@Column(name = "created_at") | ||
val createdAt: LocalDateTime = LocalDateTime.now() | ||
|
||
fun createInfo(command: CoupleInfoCreateCommand) { | ||
name = command.name | ||
nickNameA = command.nickNameA | ||
nickNameB = command.nickNameB | ||
startedAt = command.startedAt | ||
coupleImg = command.coupleImg | ||
} | ||
|
||
fun modify(command: CoupleInfoModifyCommand) { | ||
if (command.name != null) name = command.name | ||
if (command.nickNameA != null) nickNameA = command.nickNameA | ||
if (command.nickNameB != null) nickNameB = command.nickNameB | ||
if (command.startedAt != null) startedAt = command.startedAt | ||
if (command.coupleImg != null) coupleImg = command.coupleImg | ||
} | ||
|
||
companion object { | ||
fun create(accountNoA: Int, accountNoB: Int) = Couple( | ||
accountNoA = accountNoA, | ||
accountNoB = accountNoB | ||
) | ||
} | ||
|
||
} |
7 changes: 7 additions & 0 deletions
7
src/main/kotlin/com/yedongsoon/example_project/domain/couple/CoupleRepository.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,7 @@ | ||
package com.yedongsoon.example_project.domain.couple | ||
|
||
import org.springframework.data.jpa.repository.JpaRepository | ||
|
||
interface CoupleRepository : JpaRepository<Couple, Int> { | ||
fun findByAccountNoAOrAccountNoB(accountNoA: Int, accountNoB: Int): Couple? | ||
} |
67 changes: 67 additions & 0 deletions
67
src/main/kotlin/com/yedongsoon/example_project/domain/member/Member.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,67 @@ | ||
package com.yedongsoon.example_project.domain.member | ||
|
||
import com.yedongsoon.example_project.domain.member.model.MemberAdditionalInfoCommand | ||
import com.yedongsoon.example_project.domain.member.model.MemberInfoModifyCommand | ||
import jakarta.persistence.* | ||
import java.time.LocalDate | ||
import java.time.LocalDateTime | ||
|
||
@Entity | ||
@Table(name = "member") | ||
class Member( | ||
@Id | ||
@GeneratedValue(strategy = GenerationType.IDENTITY) | ||
@Column(name = "member_no") | ||
val no: Int = 0, | ||
|
||
@Column(name = "account_id") | ||
val accountId: String?, | ||
|
||
name: String?, | ||
|
||
email: String?, | ||
|
||
profilePhoto: String?, | ||
|
||
birthDate: LocalDate?, | ||
|
||
mobileNo: String?, | ||
) { | ||
@Column(name = "created_at") | ||
val createdAt: LocalDateTime = LocalDateTime.now() | ||
|
||
@Column(name = "name") | ||
var name: String? = name | ||
private set | ||
|
||
@Column(name = "email") | ||
var email: String? = email | ||
private set | ||
|
||
@Column(name = "profile_photo") | ||
var profilePhoto: String? = profilePhoto | ||
private set | ||
|
||
@Column(name = "birth_date") | ||
var birthDate: LocalDate? = birthDate | ||
private set | ||
|
||
@Column(name = "mobile_no") | ||
var mobileNo: String? = mobileNo | ||
private set | ||
|
||
fun createAdditionalInfo(command: MemberAdditionalInfoCommand) { | ||
name = command.name ?: name | ||
profilePhoto = command.profilePhoto | ||
birthDate = command.birthDate | ||
mobileNo = command.mobileNo | ||
} | ||
|
||
fun modify(command: MemberInfoModifyCommand) { | ||
name = command.name | ||
email = command.email | ||
profilePhoto = command.profilePhoto | ||
birthDate = command.birthDate | ||
mobileNo = command.mobileNo | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
src/main/kotlin/com/yedongsoon/example_project/domain/member/MemberRepository.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,8 @@ | ||
package com.yedongsoon.example_project.domain.member | ||
|
||
import org.springframework.data.jpa.repository.JpaRepository | ||
|
||
|
||
interface MemberRepository : JpaRepository<Member, Int> { | ||
fun findByNo(no: Int): Member? | ||
} |
6 changes: 6 additions & 0 deletions
6
src/main/kotlin/com/yedongsoon/example_project/domain/member/model/CoupleCreateCommand.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,6 @@ | ||
package com.yedongsoon.example_project.domain.member.model | ||
|
||
data class CoupleCreateCommand( | ||
val inviteCode: String, | ||
val accountNoB: Int, | ||
) |
Oops, something went wrong.