From 9a253de7e70bec4de1d0ccbbfe0dde9aa8da61fa Mon Sep 17 00:00:00 2001 From: westzeroright Date: Tue, 31 Dec 2024 16:05:59 +0900 Subject: [PATCH] =?UTF-8?q?feat(api-query-jpa):=20memberviewer=20=EA=B5=AC?= =?UTF-8?q?=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../api_query_jpa/member/MemberJpaViewer.java | 13 ------ .../member/MemberViewerImpl.java | 42 +++++++++++++++++++ 2 files changed, 42 insertions(+), 13 deletions(-) delete mode 100644 modules/infrastructure/api-query-jpa/src/main/java/com/whoz_in/api_query_jpa/member/MemberJpaViewer.java create mode 100644 modules/infrastructure/api-query-jpa/src/main/java/com/whoz_in/api_query_jpa/member/MemberViewerImpl.java diff --git a/modules/infrastructure/api-query-jpa/src/main/java/com/whoz_in/api_query_jpa/member/MemberJpaViewer.java b/modules/infrastructure/api-query-jpa/src/main/java/com/whoz_in/api_query_jpa/member/MemberJpaViewer.java deleted file mode 100644 index e7c202b7..00000000 --- a/modules/infrastructure/api-query-jpa/src/main/java/com/whoz_in/api_query_jpa/member/MemberJpaViewer.java +++ /dev/null @@ -1,13 +0,0 @@ -package com.whoz_in.api_query_jpa.member; - -import com.whoz_in.main_api.query.member.application.MemberAuthInfo; -import com.whoz_in.main_api.query.member.application.MemberViewer; -import java.util.Optional; - -public class MemberJpaViewer implements MemberViewer { - - @Override - public Optional findAuthInfoByLoginId(String loginId) { - return Optional.empty(); - } -} diff --git a/modules/infrastructure/api-query-jpa/src/main/java/com/whoz_in/api_query_jpa/member/MemberViewerImpl.java b/modules/infrastructure/api-query-jpa/src/main/java/com/whoz_in/api_query_jpa/member/MemberViewerImpl.java new file mode 100644 index 00000000..bbbbd032 --- /dev/null +++ b/modules/infrastructure/api-query-jpa/src/main/java/com/whoz_in/api_query_jpa/member/MemberViewerImpl.java @@ -0,0 +1,42 @@ +package com.whoz_in.api_query_jpa.member; + +import com.whoz_in.main_api.query.member.application.MemberAuthInfo; +import com.whoz_in.main_api.query.member.application.MemberViewer; +import java.nio.ByteBuffer; +import java.util.Optional; +import java.util.UUID; +import lombok.RequiredArgsConstructor; +import org.springframework.jdbc.core.simple.JdbcClient; +import org.springframework.stereotype.Repository; + +@Repository +@RequiredArgsConstructor +public class MemberViewerImpl implements MemberViewer { + + private final JdbcClient jdbcClient; + + @Override + public Optional findAuthInfoByLoginId(String loginId) { + String sql = "select id, login_id, password from member_entity where login_id = ?"; + + return jdbcClient.sql(sql) + .param(loginId) + .query((rs, rowNum) -> { + byte[] idBlob = rs.getBytes("id"); + UUID id = convertBlobToUUID(idBlob); + + return new MemberAuthInfo( + id, + rs.getString("login_id"), + rs.getString("password") + ); + }).optional(); + } + + private UUID convertBlobToUUID(byte[] blob) { + ByteBuffer buffer = ByteBuffer.wrap(blob); + long mostSigBits = buffer.getLong(); + long leastSigBits = buffer.getLong(); + return new UUID(mostSigBits, leastSigBits); + } +}