-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
아이디 찾기 #180
The head ref may contain hidden characters: "feature/\uC544\uC774\uB514_\uCC3E\uAE30"
아이디 찾기 #180
Changes from 5 commits
207565a
5fcba0b
7b00e61
e9d2e0c
32920f3
8ea2edd
ceaeb5a
fa83198
2966944
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package com.plzgraduate.myongjigraduatebe.user.adaptor.in.web.findauthid; | ||
|
||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.PathVariable; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
|
||
import com.plzgraduate.myongjigraduatebe.core.meta.WebAdapter; | ||
import com.plzgraduate.myongjigraduatebe.user.application.port.in.find.FindUserAuthIdUseCase; | ||
import com.plzgraduate.myongjigraduatebe.user.application.port.in.find.UserAuthIdResponse; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
|
||
@WebAdapter | ||
@RequestMapping("/api/v1/users") | ||
@RequiredArgsConstructor | ||
public class FindAuthIdController { | ||
|
||
private final FindUserAuthIdUseCase findUserAuthIdUseCase; | ||
|
||
@GetMapping("/student-number/{studentNumber}") | ||
public UserAuthIdResponse findUserAuthId(@PathVariable String studentNumber) { | ||
return findUserAuthIdUseCase.findUserAuthId(studentNumber); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package com.plzgraduate.myongjigraduatebe.user.application.port.in.find; | ||
|
||
public interface FindUserAuthIdUseCase { | ||
|
||
UserAuthIdResponse findUserAuthId(String studentNumber); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package com.plzgraduate.myongjigraduatebe.user.application.port.in.find; | ||
|
||
import lombok.Builder; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
|
||
@Getter | ||
@NoArgsConstructor | ||
Check warning on line 8 in src/main/java/com/plzgraduate/myongjigraduatebe/user/application/port/in/find/UserAuthIdResponse.java Codecov / codecov/patchsrc/main/java/com/plzgraduate/myongjigraduatebe/user/application/port/in/find/UserAuthIdResponse.java#L8
|
||
public class UserAuthIdResponse { | ||
|
||
private String authId; | ||
private String studentNumber; | ||
|
||
@Builder | ||
private UserAuthIdResponse(String authId, String studentNumber) { | ||
this.authId = authId; | ||
this.studentNumber = studentNumber; | ||
} | ||
|
||
public static UserAuthIdResponse from(String encryptedAutId, String studentNumber) { | ||
return UserAuthIdResponse.builder() | ||
.authId(encryptedAutId) | ||
.studentNumber(studentNumber).build(); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package com.plzgraduate.myongjigraduatebe.user.application.service.find; | ||
|
||
import java.util.NoSuchElementException; | ||
|
||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
import com.plzgraduate.myongjigraduatebe.core.meta.UseCase; | ||
import com.plzgraduate.myongjigraduatebe.user.application.port.in.find.FindUserAuthIdUseCase; | ||
import com.plzgraduate.myongjigraduatebe.user.application.port.in.find.UserAuthIdResponse; | ||
import com.plzgraduate.myongjigraduatebe.user.application.port.out.FindUserPort; | ||
import com.plzgraduate.myongjigraduatebe.user.domain.model.User; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
|
||
@UseCase | ||
@Transactional(readOnly = true) | ||
@RequiredArgsConstructor | ||
public class FindUserAuthIdService implements FindUserAuthIdUseCase { | ||
|
||
private final FindUserPort findUserPort; | ||
|
||
@Override | ||
public UserAuthIdResponse findUserAuthId(String studentNumber) { | ||
User user = findUserPort.findUserByStudentNumber(studentNumber) | ||
.orElseThrow(() -> new NoSuchElementException("해당 학번의 사용자가 존재하지 않습니다")); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. request body로 하고 400으로 수정해버리자. 기존 api 수정할 사항 있으면 그냥 하자. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 음 저는 400번 보다는 404가 맞는거 같은게 학번으로 조회하는 요청 자체는 잘못된 요청이 아니고 찾으려는 자원이 존재하지 않는거니 404가 더 알맞은 에러코드인거 같습니다. |
||
return UserAuthIdResponse.from(user.getEncryptedAuthId(), studentNumber); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package com.plzgraduate.myongjigraduatebe.user.adaptor.in.web.findauthid; | ||
|
||
import static org.hamcrest.Matchers.is; | ||
import static org.mockito.BDDMockito.given; | ||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; | ||
import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print; | ||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath; | ||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; | ||
|
||
import org.junit.jupiter.api.DisplayName; | ||
import org.junit.jupiter.api.Test; | ||
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest; | ||
import org.springframework.boot.test.mock.mockito.MockBean; | ||
|
||
import com.plzgraduate.myongjigraduatebe.support.WebAdaptorTestSupport; | ||
import com.plzgraduate.myongjigraduatebe.user.application.port.in.find.FindUserAuthIdUseCase; | ||
import com.plzgraduate.myongjigraduatebe.user.application.port.in.find.UserAuthIdResponse; | ||
|
||
@WebMvcTest(controllers = FindAuthIdController.class) | ||
class FindAuthIdControllerTest extends WebAdaptorTestSupport { | ||
|
||
@MockBean | ||
private FindUserAuthIdUseCase findUserAuthIdUseCase; | ||
|
||
@DisplayName("학번으로 해당 학생의 아이디를 조회한다.") | ||
@Test | ||
void findUserAuthId() throws Exception { | ||
//given | ||
String studentNumber = "60191111"; | ||
String encryptedAuthId = "test***"; | ||
UserAuthIdResponse userAuthIdResponse = UserAuthIdResponse.builder() | ||
.authId(encryptedAuthId) | ||
.studentNumber(studentNumber).build(); | ||
given(findUserAuthIdUseCase.findUserAuthId(studentNumber)).willReturn(userAuthIdResponse); | ||
|
||
//when //then | ||
mockMvc.perform(get("/api/v1/users/student-number/{studentNumber}", studentNumber)) | ||
.andDo(print()) | ||
.andExpect(status().isOk()) | ||
.andExpect(jsonPath("$.authId", is(encryptedAuthId))) | ||
.andExpect(jsonPath("$.studentNumber", is(studentNumber))); | ||
} | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
package com.plzgraduate.myongjigraduatebe.user.application.service.find; | ||
|
||
import static org.assertj.core.api.Assertions.*; | ||
import static org.mockito.ArgumentMatchers.anyString; | ||
import static org.mockito.BDDMockito.given; | ||
|
||
import java.util.NoSuchElementException; | ||
import java.util.Optional; | ||
|
||
import org.junit.jupiter.api.DisplayName; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.ExtendWith; | ||
import org.mockito.InjectMocks; | ||
import org.mockito.Mock; | ||
import org.mockito.junit.jupiter.MockitoExtension; | ||
|
||
import com.plzgraduate.myongjigraduatebe.user.application.port.in.find.UserAuthIdResponse; | ||
import com.plzgraduate.myongjigraduatebe.user.application.port.out.FindUserPort; | ||
import com.plzgraduate.myongjigraduatebe.user.domain.model.User; | ||
|
||
@ExtendWith(MockitoExtension.class) | ||
class FindUserAuthIdServiceTest { | ||
|
||
@Mock | ||
private FindUserPort findUserPort; | ||
|
||
@InjectMocks | ||
private FindUserAuthIdService findUserAuthIdService; | ||
|
||
@DisplayName("학번을 통해 해당 학번 학생의 암호화된 로그인 아이디를 얻는다.") | ||
@Test | ||
void findUserAuthId() { | ||
//given | ||
String studentNumber = "60191111"; | ||
User user = User.builder() | ||
.authId("tester00") | ||
.password("tester00!") | ||
.studentNumber(studentNumber) | ||
.build(); | ||
given(findUserPort.findUserByStudentNumber(anyString())).willReturn(Optional.of(user)); | ||
|
||
//when | ||
UserAuthIdResponse userAuthIdResponse = findUserAuthIdService.findUserAuthId(studentNumber); | ||
|
||
//then | ||
assertThat(userAuthIdResponse).extracting("authId", "studentNumber") | ||
.contains("teste***", studentNumber); | ||
} | ||
|
||
@DisplayName("학번에 해당하는 유저가 존재하지 않을 경우 예외가 발생한다.") | ||
@Test | ||
void findUserAuthIdWithoutUser() { | ||
//given | ||
String studentNumber = "60191111"; | ||
given(findUserPort.findUserByStudentNumber(anyString())).willReturn(Optional.empty()); | ||
|
||
//when //then | ||
assertThatThrownBy(() -> findUserAuthIdService.findUserAuthId(studentNumber)) | ||
.isInstanceOf(NoSuchElementException.class) | ||
.hasMessage("해당 학번의 사용자가 존재하지 않습니다"); | ||
} | ||
|
||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
from -> of
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
넵