Skip to content

Commit

Permalink
[#75] refactor: auth query kotlin으로 migration
Browse files Browse the repository at this point in the history
  • Loading branch information
shin-mallang committed Nov 17, 2023
1 parent 787e47a commit 2844d78
Show file tree
Hide file tree
Showing 20 changed files with 146 additions and 179 deletions.
19 changes: 0 additions & 19 deletions src/main/java/com/mallang/auth/query/MemberQueryService.java

This file was deleted.

19 changes: 0 additions & 19 deletions src/main/java/com/mallang/auth/query/dao/MemberProfileDataDao.java

This file was deleted.

This file was deleted.

17 changes: 0 additions & 17 deletions src/main/java/com/mallang/auth/query/data/MemberProfileData.java

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,14 +1,9 @@
package com.mallang.auth.exception;
package com.mallang.auth.exception

import static org.springframework.http.HttpStatus.INTERNAL_SERVER_ERROR;

import com.mallang.common.execption.ErrorCode;
import com.mallang.common.execption.MallangLogException;

public class IncorrectUseAuthAtException extends MallangLogException {

public IncorrectUseAuthAtException() {
super(new ErrorCode(INTERNAL_SERVER_ERROR, "@Auth 어노테이션을 잘못 사용했습니다."));
}
}
import com.mallang.common.execption.ErrorCode
import com.mallang.common.execption.MallangLogException
import org.springframework.http.HttpStatus.INTERNAL_SERVER_ERROR

class IncorrectUseAuthAtException : MallangLogException(
ErrorCode(INTERNAL_SERVER_ERROR, "@Auth 어노테이션을 잘못 사용했습니다.")
)
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
package com.mallang.auth.exception;
package com.mallang.auth.exception

import static org.springframework.http.HttpStatus.UNAUTHORIZED;
import com.mallang.common.execption.ErrorCode
import com.mallang.common.execption.MallangLogException
import org.springframework.http.HttpStatus.UNAUTHORIZED

import com.mallang.common.execption.ErrorCode;
import com.mallang.common.execption.MallangLogException;

public class NoAuthenticationSessionException extends MallangLogException {

public NoAuthenticationSessionException() {
super(new ErrorCode(UNAUTHORIZED, "인증 정보가 없거나 만료되었습니다."));
}
}
class NoAuthenticationSessionException : MallangLogException(
ErrorCode(UNAUTHORIZED, "인증 정보가 없거나 만료되었습니다.")
)
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
package com.mallang.auth.exception;
package com.mallang.auth.exception

import static org.springframework.http.HttpStatus.NOT_FOUND;
import com.mallang.common.execption.ErrorCode
import com.mallang.common.execption.MallangLogException
import org.springframework.http.HttpStatus.NOT_FOUND

import com.mallang.common.execption.ErrorCode;
import com.mallang.common.execption.MallangLogException;

public class NotFoundMemberException extends MallangLogException {

public NotFoundMemberException() {
super(new ErrorCode(NOT_FOUND, "존재하지 않는 회원입니다."));
}
}
class NotFoundMemberException : MallangLogException(
ErrorCode(NOT_FOUND, "존재하지 않는 회원입니다.")
)
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
package com.mallang.auth.exception;
package com.mallang.auth.exception

import static org.springframework.http.HttpStatus.INTERNAL_SERVER_ERROR;
import com.mallang.common.execption.ErrorCode
import com.mallang.common.execption.MallangLogException
import org.springframework.http.HttpStatus.INTERNAL_SERVER_ERROR

import com.mallang.common.execption.ErrorCode;
import com.mallang.common.execption.MallangLogException;

public class UnsupportedOauthTypeException extends MallangLogException {

public UnsupportedOauthTypeException() {
super(new ErrorCode(INTERNAL_SERVER_ERROR, "Oauth 에 문제가 있습니다."));
}
}
class UnsupportedOauthTypeException : MallangLogException(
ErrorCode(INTERNAL_SERVER_ERROR, "Oauth 에 문제가 있습니다.")
)
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package com.mallang.auth.presentation

import com.mallang.auth.presentation.support.Auth
import com.mallang.auth.query.MemberQueryService
import com.mallang.auth.query.data.MemberProfileData
import com.mallang.auth.query.dao.model.MemberProfileQueryModel
import lombok.RequiredArgsConstructor
import org.springframework.http.ResponseEntity
import org.springframework.web.bind.annotation.GetMapping
Expand All @@ -19,15 +19,15 @@ class MemberController(

@GetMapping("/{id}")
fun findProfile(
@PathVariable("id") memberId: Long
): ResponseEntity<MemberProfileData> {
return ResponseEntity.ok(memberQueryService.findProfile(memberId))
@PathVariable("id") memberId: Long? // TODO non null
): ResponseEntity<MemberProfileQueryModel> {
return ResponseEntity.ok(memberQueryService.findProfile(memberId!!))
}

@GetMapping("/my")
fun findMyProfile(
@Auth memberId: Long?
): ResponseEntity<MemberProfileData> {
return ResponseEntity.ok(memberQueryService.findProfile(memberId))
): ResponseEntity<MemberProfileQueryModel> {
return ResponseEntity.ok(memberQueryService.findProfile(memberId!!))
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class AuthArgumentResolver(
@Nullable mavContainer: ModelAndViewContainer?,
webRequest: NativeWebRequest,
@Nullable binderFactory: WebDataBinderFactory?
): Any {
): Long {
return authContext.getMemberId()
}
}
18 changes: 18 additions & 0 deletions src/main/kotlin/com/mallang/auth/query/MemberQueryService.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package com.mallang.auth.query

import com.mallang.auth.query.dao.MemberProfileDataDao
import com.mallang.auth.query.dao.model.MemberProfileQueryModel
import org.springframework.stereotype.Service
import org.springframework.transaction.annotation.Transactional


@Transactional(readOnly = true)
@Service
class MemberQueryService(
private val memberProfileDataDao: MemberProfileDataDao
) {

fun findProfile(memberId: Long): MemberProfileQueryModel {
return memberProfileDataDao.find(memberId)
}
}
17 changes: 17 additions & 0 deletions src/main/kotlin/com/mallang/auth/query/dao/MemberProfileDataDao.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.mallang.auth.query.dao

import com.mallang.auth.query.dao.model.MemberProfileQueryModel
import com.mallang.auth.query.dao.support.MemberQuerySupport
import org.springframework.stereotype.Component
import org.springframework.transaction.annotation.Transactional

@Transactional(readOnly = true)
@Component
class MemberProfileDataDao(
private val memberQuerySupport: MemberQuerySupport
) {

fun find(memberId: Long): MemberProfileQueryModel {
return MemberProfileQueryModel.from(memberQuerySupport.getById(memberId))
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package com.mallang.auth.query.dao.model

import com.mallang.auth.domain.Member

data class MemberProfileQueryModel(
val id: Long,
val nickname: String,
val profileImageUrl: String
) {
companion object {
fun from(member: Member): MemberProfileQueryModel =
MemberProfileQueryModel(
member.id,
member.nickname,
member.profileImageUrl
)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.mallang.auth.query.dao.support

import com.mallang.auth.domain.Member
import org.springframework.data.jpa.repository.JpaRepository
import org.springframework.data.repository.findByIdOrNull


interface MemberQuerySupport : JpaRepository<Member, Long?> {
fun getById(id: Long) = findByIdOrNull(id)
?: throw NoSuchElementException("id가 ${id}인 회원을 찾을 수 없습니다.")
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import static com.mallang.acceptance.AcceptanceSteps.given;
import static org.assertj.core.api.Assertions.assertThat;

import com.mallang.auth.query.data.MemberProfileData;
import com.mallang.auth.query.dao.model.MemberProfileQueryModel;
import io.restassured.response.ExtractableResponse;
import io.restassured.response.Response;

Expand All @@ -28,17 +28,17 @@ public class MemberAcceptanceSteps {
.extract();
}

public static MemberProfileData 회원_정보_조회_결과_데이터(
public static MemberProfileQueryModel 회원_정보_조회_결과_데이터(
ExtractableResponse<Response> 응답
) {
return 응답.response().as(MemberProfileData.class);
return 응답.response().as(MemberProfileQueryModel.class);
}

public static void 회원_정보_조회_결과를_검증한다(
ExtractableResponse<Response> 응답,
MemberProfileData 예상
MemberProfileQueryModel 예상
) {
MemberProfileData 회원_정보 = 응답.response().as(MemberProfileData.class);
MemberProfileQueryModel 회원_정보 = 응답.response().as(MemberProfileQueryModel.class);
assertThat(회원_정보)
.usingRecursiveComparison()
.ignoringFields("id")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import static com.mallang.acceptance.auth.MemberAcceptanceSteps.회원_정보_조회_요청;

import com.mallang.acceptance.AcceptanceTest;
import com.mallang.auth.query.data.MemberProfileData;
import com.mallang.auth.query.dao.model.MemberProfileQueryModel;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.DisplayNameGeneration;
import org.junit.jupiter.api.DisplayNameGenerator.ReplaceUnderscores;
Expand All @@ -31,7 +31,7 @@ class 내_정보_조회_시 {
var 응답 = 내_정보_조회_요청(말랑_세션_ID);

// then
회원_정보_조회_결과를_검증한다(응답, new MemberProfileData(null, "mallang", "mallang"));
회원_정보_조회_결과를_검증한다(응답, new MemberProfileQueryModel(1L, "mallang", "mallang"));
}

@Nested
Expand All @@ -44,7 +44,7 @@ class 회원_정보_조회_시 {
var 정보 = 회원_정보_조회_결과_데이터(내_정보_조회_요청(말랑_세션_ID));

// when
var 응답 = 회원_정보_조회_요청(정보.id());
var 응답 = 회원_정보_조회_요청(정보.getId());

// then
회원_정보_조회_결과를_검증한다(응답, 정보);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ class 특정_회원이_구독중인_블로그_조회_시 {
var 블로그1주인_세션_ID = 회원가입과_로그인_후_세션_ID_반환("블로그1주인");
var 블로그2주인_세션_ID = 회원가입과_로그인_후_세션_ID_반환("블로그2주인");
var 구독자_세션_ID = 회원가입과_로그인_후_세션_ID_반환("구독자");
var 구독자_ID = 회원_정보_조회_결과_데이터(내_정보_조회_요청(구독자_세션_ID)).id();
var 구독자_ID = 회원_정보_조회_결과_데이터(내_정보_조회_요청(구독자_세션_ID)).getId();
var 블로그1_ID = 블로그_개설(블로그1주인_세션_ID, "blog1");
var 블로그2_ID = 블로그_개설(블로그2주인_세션_ID, "blog2");
블로그_구독_요청(구독자_세션_ID, 블로그1_ID);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ class OauthServiceTest {
@Test
void 로그인_시_가입되지_않았다면_회원가입시킨다() {
// given
Member 동훈 = 동훈();
Member 동훈 = 동훈(1L);
given(oauthMemberClientComposite.fetch(GITHUB, "code"))
.willReturn(동훈);
given(memberRepository.findByOauthId(동훈.getOauthId()))
Expand All @@ -64,7 +64,7 @@ class OauthServiceTest {
@Test
void 로그인_시_이미_가입되었다면_로그인만_시킨다() {
// given
Member 동훈 = 동훈();
Member 동훈 = 동훈(1L);
given(oauthMemberClientComposite.fetch(GITHUB, "code"))
.willReturn(동훈);
given(memberRepository.findByOauthId(동훈.getOauthId()))
Expand Down

This file was deleted.

Loading

0 comments on commit 2844d78

Please sign in to comment.