Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package hs.kr.entrydsm.user.infrastructure.grpc.server

import hs.kr.entrydsm.casper.user.proto.UserServiceGrpcKt
import hs.kr.entrydsm.casper.user.proto.UserServiceProto
import hs.kr.entrydsm.user.domain.user.application.port.`in`.QueryUserByUUIDUseCase
import hs.kr.entrydsm.user.infrastructure.grpc.server.mapper.UserGrpcMapper
import io.grpc.Status
import io.grpc.StatusException
import net.devh.boot.grpc.server.service.GrpcService
import java.util.UUID

/**
* 사용자 관련 gRPC 서비스 구현 클래스입니다.
* 다른 마이크로서비스와의 gRPC 통신을 통해 사용자 정보를 제공합니다.
*
* @property queryUserByUUIDUseCase UUID로 사용자 조회 유스케이스
* @property userGrpcMapper gRPC 메시지 변환 매퍼
*/
@GrpcService
class UserGrpcService(
private val queryUserByUUIDUseCase: QueryUserByUUIDUseCase,
private val userGrpcMapper: UserGrpcMapper,
) : UserServiceGrpcKt.UserServiceCoroutineImplBase() {

/**
* 사용자 ID로 사용자 정보를 조회합니다.
*
* @param request 사용자 ID가 포함된 gRPC 요청
* @return 사용자 정보 gRPC 응답
* @throws StatusException UUID 형식이 잘못되었거나 서버 오류가 발생한 경우
*/
override suspend fun getUserInfoByUserId(request: UserServiceProto.GetUserInfoRequest): UserServiceProto.GetUserInfoResponse {
val userId = UUID.fromString(request.userId)
val userInfo = queryUserByUUIDUseCase.getUserById(userId)
return userGrpcMapper.toGetUserInfoResponse(userInfo)
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

왜 에러가 한국어였다가 영어였다가 계속 바뀌나요 @qkrwndnjs1075

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

에러 처리는 비즈니스 로직 상에서 처리 되어지고 있기 때문에 제거 하였습니다.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍👍

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package hs.kr.entrydsm.user.infrastructure.grpc.server.dto

import hs.kr.entrydsm.user.domain.user.adapter.out.domain.UserRole
import java.util.UUID

/**
* 내부 gRPC 통신용 사용자 응답 DTO 클래스입니다.
* 다른 마이크로서비스와의 통신에서 사용자 정보를 전달하는 데 사용됩니다.
*
* @property id 사용자 고유 식별자
* @property phoneNumber 사용자 전화번호
* @property name 사용자 이름
* @property isParent 학부모 여부
* @property receiptCode 지원서 접수번호
* @property role 사용자 역할
*/
data class InternalUserResponse(
val id: UUID,
val phoneNumber: String,
val name: String,
val isParent: Boolean,
val receiptCode: Long?,
val role: UserRole,
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package hs.kr.entrydsm.user.infrastructure.grpc.server.mapper

import hs.kr.entrydsm.casper.user.proto.UserServiceProto
import hs.kr.entrydsm.user.infrastructure.grpc.server.dto.InternalUserResponse
import hs.kr.entrydsm.user.domain.user.adapter.out.domain.UserRole
import org.springframework.stereotype.Component

/**
* 사용자 정보를 gRPC 프로토콜 버퍼와 매핑하는 매퍼 클래스입니다.
* 내부 DTO와 gRPC 메시지 간의 변환을 담당합니다.
*/
@Component
class UserGrpcMapper {

/**
* InternalUserResponse 객체를 gRPC 사용자 정보 응답으로 변환합니다.
*
* @param userResponse 변환할 사용자 응답 DTO
* @return gRPC 사용자 정보 응답
*/
fun toGetUserInfoResponse(userResponse: InternalUserResponse): UserServiceProto.GetUserInfoResponse {
return UserServiceProto.GetUserInfoResponse.newBuilder()
Copy link
Contributor

@devizi0 devizi0 Jul 29, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

.setReceiptCode() 이것도 추가해야 하는거 아닌가요 @qkrwndnjs1075

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

근데 ?: 0L이 맞나 수험번호를 부여 받는 건데?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

서버팀에서 판단 하시죠

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

아 생각해보니까 어짜피 receiptCode는 안 보내서 필요없음

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

.setId(userResponse.id.toString())
.setPhoneNumber(userResponse.phoneNumber)
.setName(userResponse.name)
.setIsParent(userResponse.isParent)
.setRole(toProtoUserRole(userResponse.role))
.build()
}

/**
* 도메인 사용자 역할을 gRPC 프로토콜 사용자 역할로 변환합니다.
*
* @param userRole 변환할 도메인 사용자 역할
* @return gRPC 프로토콜 사용자 역할
*/
private fun toProtoUserRole(userRole: UserRole): UserServiceProto.UserRole{
return when(userRole){
UserRole.ROOT -> UserServiceProto.UserRole.ROOT
UserRole.USER -> UserServiceProto.UserRole.USER
UserRole.ADMIN -> UserServiceProto.UserRole.ADMIN
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package hs.kr.entrydsm.user.infrastructure.kafka.producer

/**
* 모든 테이블 삭제 이벤트를 Kafka로 발행하는 Producer 인터페이스입니다.
* 관리자가 전체 데이터를 초기화할 때 다른 마이크로서비스에 알림을 전송하는 역할을 합니다.
*/
interface DeleteAllTableProducer {
/**
* 모든 테이블 삭제 이벤트를 전송합니다.
* 전체 데이터 초기화 이벤트를 Kafka 토픽으로 발행합니다.
*/
fun send()
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package hs.kr.entrydsm.user.infrastructure.kafka.producer

/**
* 사용자 삭제 이벤트를 Kafka로 발행하는 Producer 인터페이스입니다.
* 사용자 탈퇴 시 다른 마이크로서비스에 알림을 전송하는 역할을 합니다.
*/
interface DeleteUserProducer {
/**
* 사용자 삭제 이벤트를 전송합니다.
* 사용자의 접수번호를 포함한 삭제 이벤트를 Kafka 토픽으로 발행합니다.
*
* @param receiptCode 삭제된 사용자의 접수번호
*/
fun send(receiptCode: Long)
}