Skip to content

Commit 5e9831b

Browse files
authored
Merge pull request #18 from EntryDSM/feature/13-gRPC
Feature/13 gRPC
2 parents 591c6a7 + 073e26d commit 5e9831b

File tree

3 files changed

+103
-0
lines changed

3 files changed

+103
-0
lines changed
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
package hs.kr.entrydsm.schedule.infrastructure.grpc.server
2+
3+
import hs.kr.entrydsm.casper.schedule.proto.ScheduleServiceGrpcKt
4+
import hs.kr.entrydsm.casper.schedule.proto.ScheduleServiceProto
5+
import hs.kr.entrydsm.schedule.domain.schedule.application.port.`in`.QueryScheduleByTypeUseCase
6+
import hs.kr.entrydsm.schedule.infrastructure.grpc.dto.response.InternalScheduleResponse
7+
import hs.kr.entrydsm.schedule.infrastructure.grpc.server.mapper.ScheduleGrpcMapper
8+
import net.devh.boot.grpc.server.service.GrpcService
9+
10+
/**
11+
* gRPC 서버 구현체로, 스케줄 관련 gRPC 요청을 처리합니다.
12+
* ScheduleService gRPC 서비스 정의를 구현하며, 클라이언트로부터의 스케줄 조회 요청을 처리합니다.
13+
*
14+
* @property scheduleGrpcMapper 도메인 모델과 gRPC 메시지 간의 변환을 담당하는 매퍼
15+
* @property queryScheduleByTypeUseCase 특정 유형의 스케줄을 조회하기 위한 유스케이스
16+
*/
17+
@GrpcService
18+
class ScheduleGrpcService(
19+
private val scheduleGrpcMapper: ScheduleGrpcMapper,
20+
private val queryScheduleByTypeUseCase: QueryScheduleByTypeUseCase
21+
) : ScheduleServiceGrpcKt.ScheduleServiceCoroutineImplBase() {
22+
23+
/**
24+
* 주어진 타입에 해당하는 스케줄을 조회합니다.
25+
*
26+
* @param request 조회할 스케줄의 타입이 포함된 요청 메시지
27+
* @return 조회된 스케줄 정보가 포함된 응답 메시지
28+
* @throws hs.kr.entrydsm.common.exception.BusinessException 해당 타입의 스케줄이 존재하지 않는 경우 발생
29+
*/
30+
override suspend fun getScheduleByType(request: ScheduleServiceProto.TypeRequest): ScheduleServiceProto.GetScheduleResponse {
31+
val schedule = queryScheduleByTypeUseCase.execute(request.type.toString())
32+
val internalScheduleResponse = InternalScheduleResponse(
33+
type = schedule.type,
34+
date = schedule.date.toString()
35+
)
36+
return scheduleGrpcMapper.toGetScheduleByTypeResponse(internalScheduleResponse)
37+
}
38+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package hs.kr.entrydsm.schedule.infrastructure.grpc.dto.response
2+
3+
import hs.kr.entrydsm.schedule.domain.schedule.model.type.Type
4+
5+
/**
6+
* 내부적으로 사용되는 스케줄 응답 데이터 클래스입니다.
7+
* 이 클래스는 도메인 계층과 인프라스트럭처 계층 간의 데이터 전달에 사용됩니다.
8+
*
9+
* @property type 스케줄의 유형 (시작일, 1차 발표일 등)
10+
* @property date 스케줄 날짜 (문자열 형식)
11+
*/
12+
data class InternalScheduleResponse(
13+
val type: Type,
14+
val date: String
15+
)
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
package hs.kr.entrydsm.schedule.infrastructure.grpc.server.mapper
2+
3+
import hs.kr.entrydsm.casper.schedule.proto.ScheduleServiceProto
4+
import hs.kr.entrydsm.schedule.domain.schedule.model.type.Type
5+
import hs.kr.entrydsm.schedule.infrastructure.grpc.dto.response.InternalScheduleResponse
6+
import org.springframework.stereotype.Component
7+
8+
/**
9+
* 도메인 모델과 gRPC 메시지 간의 변환을 담당하는 매퍼 클래스입니다.
10+
* 이 클래스는 내부 도메인 모델과 gRPC 프로토콜 버퍼 메시지 간의 변환 로직을 캡슐화합니다.
11+
*/
12+
@Component
13+
class ScheduleGrpcMapper {
14+
companion object {
15+
/**
16+
* 도메인 타입과 gRPC 프로토 타입 간의 매핑을 정의한 맵입니다.
17+
* 이 맵은 도메인 모델의 Type과 프로토콜 버퍼의 Type 간의 변환을 위해 사용됩니다.
18+
*/
19+
private val DOMAIN_TO_PROTO_MAP = mapOf(
20+
Type.START_DATE to ScheduleServiceProto.Type.START_DATE,
21+
Type.FIRST_ANNOUNCEMENT to ScheduleServiceProto.Type.FIRST_ANNOUNCEMENT,
22+
Type.INTERVIEW to ScheduleServiceProto.Type.INTERVIEW,
23+
Type.SECOND_ANNOUNCEMENT to ScheduleServiceProto.Type.SECOND_ANNOUNCEMENT,
24+
Type.END_DATE to ScheduleServiceProto.Type.END_DATE
25+
)
26+
}
27+
28+
/**
29+
* 내부 스케줄 응답을 gRPC 응답 메시지로 변환합니다.
30+
*
31+
* @param response 변환할 내부 스케줄 응답 객체
32+
* @return gRPC 프로토콜 버퍼 형식의 응답 메시지
33+
* @throws NoSuchElementException 매핑된 프로토 타입을 찾을 수 없는 경우 발생
34+
*/
35+
fun toGetScheduleByTypeResponse(response: InternalScheduleResponse): ScheduleServiceProto.GetScheduleResponse {
36+
return ScheduleServiceProto.GetScheduleResponse.newBuilder()
37+
.setType(toProtoType(response.type))
38+
.setDate(response.date)
39+
.build()
40+
}
41+
42+
/**
43+
* 도메인 타입을 gRPC 프로토 타입으로 변환합니다.
44+
*
45+
* @param type 변환할 도메인 타입
46+
* @return 변환된 gRPC 프로토 타입
47+
* @throws NoSuchElementException 매핑된 프로토 타입을 찾을 수 없는 경우 발생
48+
*/
49+
private fun toProtoType(type: Type): ScheduleServiceProto.Type = DOMAIN_TO_PROTO_MAP[type]!!
50+
}

0 commit comments

Comments
 (0)