Skip to content

Commit

Permalink
Merge pull request #36 from DSM-Repo/teacher/auth
Browse files Browse the repository at this point in the history
reafactor :: 선생님 로그인 api 수정
  • Loading branch information
ori0o0p authored Jul 31, 2024
2 parents 60d7426 + c390058 commit 97385f7
Showing 1 changed file with 3 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import com.example.whopper.domain.auth.dto.request.LoginRequest;
import com.example.whopper.domain.auth.dto.response.TokenResponse;
import com.example.whopper.domain.auth.exception.PasswordMismatchException;
import com.example.whopper.domain.student.exception.StudentNotFoundException;
import com.example.whopper.domain.teacher.dao.TeacherMongoRepository;
import com.example.whopper.domain.teacher.domain.TeacherEntity;
import com.example.whopper.domain.teacher.exception.TeacherNotFoundException;
Expand Down Expand Up @@ -43,7 +42,7 @@ public TokenResponse teacherLogin(LoginRequest request) {

private TokenResponse loginExistingTeacher(LoginRequest request) {
TeacherEntity teacher = teacherMongoRepository.findFirstByAccountId(request.account_id())
.orElseThrow(() -> StudentNotFoundException.EXCEPTION);
.orElseThrow(() -> TeacherNotFoundException.EXCEPTION);

if (!passwordEncoder.matches(request.password(), teacher.getPassword())) {
throw PasswordMismatchException.EXCEPTION;
Expand All @@ -54,11 +53,11 @@ private TokenResponse loginExistingTeacher(LoginRequest request) {

private TokenResponse registerAndLoginNewTeacher(LoginRequest request) {
XquareUserResponse xquareUserResponse = xquareClient.xquareUser(request);
TeacherEntity newTeacher = createAndSaveNewStudent(xquareUserResponse);
TeacherEntity newTeacher = createAndSaveNewTeacher(xquareUserResponse);
return jwtTokenProvider.receiveToken(newTeacher.getId());
}

private TeacherEntity createAndSaveNewStudent(XquareUserResponse xquareUserResponse) {
private TeacherEntity createAndSaveNewTeacher(XquareUserResponse xquareUserResponse) {
return teacherMongoRepository.save(
TeacherEntity.builder()
.account_id(xquareUserResponse.getAccount_id())
Expand Down

0 comments on commit 97385f7

Please sign in to comment.