-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(api-query-jpa): memberviewer 구현
- Loading branch information
1 parent
a5cfbfb
commit 9a253de
Showing
2 changed files
with
42 additions
and
13 deletions.
There are no files selected for viewing
13 changes: 0 additions & 13 deletions
13
...ructure/api-query-jpa/src/main/java/com/whoz_in/api_query_jpa/member/MemberJpaViewer.java
This file was deleted.
Oops, something went wrong.
42 changes: 42 additions & 0 deletions
42
...ucture/api-query-jpa/src/main/java/com/whoz_in/api_query_jpa/member/MemberViewerImpl.java
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,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<MemberAuthInfo> 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); | ||
} | ||
} |