diff --git a/src/main/java/org/yj/sejongauth/controller/Sj.java b/src/main/java/org/yj/sejongauth/controller/Sj.java index 84671da..6d91d2b 100644 --- a/src/main/java/org/yj/sejongauth/controller/Sj.java +++ b/src/main/java/org/yj/sejongauth/controller/Sj.java @@ -1,19 +1,23 @@ package org.yj.sejongauth.controller; import org.yj.sejongauth.domain.AuthService; -import org.yj.sejongauth.domain.LoginReq; -import org.yj.sejongauth.domain.ProfileRes; +import org.yj.sejongauth.domain.SjProfile; import org.yj.sejongauth.domain.ProfileService; public class Sj { - private static final AuthService authService = new AuthService(); - private static final ProfileService PROFILE_SERVICE = new ProfileService(); + private final AuthService authService; + private final ProfileService profileService; - public static ProfileRes login(LoginReq loginReq) { - if (authService.authenticate(loginReq)) { + public Sj(AuthService authService, ProfileService profileService){ + this.authService = authService; + this.profileService = profileService; + } + + public SjProfile login(String userId, String password) { + if (authService.authenticate(userId, password)) { String jsessionId = authService.getJsessionId(); - return PROFILE_SERVICE.fetchUserProfile(jsessionId); + return profileService.fetchUserProfile(jsessionId); } else { throw new RuntimeException("인증에 실패하였습니다."); } diff --git a/src/main/java/org/yj/sejongauth/domain/AuthService.java b/src/main/java/org/yj/sejongauth/domain/AuthService.java index 2c975b4..66db927 100644 --- a/src/main/java/org/yj/sejongauth/domain/AuthService.java +++ b/src/main/java/org/yj/sejongauth/domain/AuthService.java @@ -19,7 +19,8 @@ public class AuthService { private final String INVALID_URL = "URL이 유효하지 않습니다."; private final String CONTAINS_HTML = "로그인 정보가 올바르지 않습니다."; - public boolean authenticate(LoginReq loginReq) { + public boolean authenticate(String userId, String password) { + LoginReq loginReq = new LoginReq(userId, password); try { fetchJsessionId(); return attemptLogin(loginReq); diff --git a/src/main/java/org/yj/sejongauth/domain/ProfileService.java b/src/main/java/org/yj/sejongauth/domain/ProfileService.java index 67b9c8a..916377d 100644 --- a/src/main/java/org/yj/sejongauth/domain/ProfileService.java +++ b/src/main/java/org/yj/sejongauth/domain/ProfileService.java @@ -12,7 +12,7 @@ public class ProfileService { private final String PROFILE_URL = "http://classic.sejong.ac.kr/userCertStatus.do?menuInfoId=MAIN_02_05"; private final String FAIDED_PROFILE = "정보 조회에 실패하였습니다."; - public ProfileRes fetchUserProfile(String jsessionId) { + public SjProfile fetchUserProfile(String jsessionId) { try { URL url = new URL(PROFILE_URL); HttpURLConnection connection = (HttpURLConnection) url.openConnection(); @@ -37,7 +37,7 @@ private String readResponse(HttpURLConnection connection) throws IOException { } } - private ProfileRes parseProfileFromHtml(Document document) { + private SjProfile parseProfileFromHtml(Document document) { String major = document.select("div.contentWrap li dl dd").get(0).text(); String studentCode = document.select("div.contentWrap li dl dd").get(1).text(); String name = document.select("div.contentWrap li dl dd").get(2).text(); @@ -46,6 +46,6 @@ private ProfileRes parseProfileFromHtml(Document document) { int completedSemesters = Integer.parseInt(document.select("div.contentWrap li dl dd").get(5).text().split(" ")[0]); int verifiedSemesters = Integer.parseInt(document.select("div.contentWrap li dl dd").get(6).text().split(" ")[0]); - return new ProfileRes(major, studentCode, name, gradeLevel, userStatus, completedSemesters, verifiedSemesters); + return new SjProfile(major, studentCode, name, gradeLevel, userStatus, completedSemesters, verifiedSemesters); } } diff --git a/src/main/java/org/yj/sejongauth/domain/ProfileRes.java b/src/main/java/org/yj/sejongauth/domain/SjProfile.java similarity index 81% rename from src/main/java/org/yj/sejongauth/domain/ProfileRes.java rename to src/main/java/org/yj/sejongauth/domain/SjProfile.java index ef297bc..fe6d63e 100644 --- a/src/main/java/org/yj/sejongauth/domain/ProfileRes.java +++ b/src/main/java/org/yj/sejongauth/domain/SjProfile.java @@ -1,6 +1,6 @@ package org.yj.sejongauth.domain; -public class ProfileRes { +public class SjProfile { private final String major; private final String studentCode; private final String name; @@ -9,9 +9,9 @@ public class ProfileRes { private final int completedSemesters; private final int verifiedSemesters; - public ProfileRes(String major, String studentCode, String name, - int gradeLevel, String userStatus, - int completedSemesters, int verifiedSemesters) { + public SjProfile(String major, String studentCode, String name, + int gradeLevel, String userStatus, + int completedSemesters, int verifiedSemesters) { this.major = major; this.studentCode = studentCode; this.name = name; diff --git a/src/test/java/org/yj/sejongauth/domain/ProfileServiceTest.java b/src/test/java/org/yj/sejongauth/domain/ProfileServiceTest.java index da82637..762c456 100644 --- a/src/test/java/org/yj/sejongauth/domain/ProfileServiceTest.java +++ b/src/test/java/org/yj/sejongauth/domain/ProfileServiceTest.java @@ -22,7 +22,7 @@ void testFetchUserProfile_Success() { String jsessionId = "valid-session-id"; // When - ProfileRes profile = profileService.fetchUserProfile(jsessionId); + SjProfile profile = profileService.fetchUserProfile(jsessionId); // Then assertNotNull(profile);