Skip to content

Commit

Permalink
Merge pull request #2 from urinaner/develop
Browse files Browse the repository at this point in the history
v0.3.0
  • Loading branch information
urinaner authored Nov 6, 2024
2 parents 5894430 + a863d4f commit 4b2e9d9
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 16 deletions.
18 changes: 11 additions & 7 deletions src/main/java/org/yj/sejongauth/controller/Sj.java
Original file line number Diff line number Diff line change
@@ -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("인증에 실패하였습니다.");
}
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/org/yj/sejongauth/domain/AuthService.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/org/yj/sejongauth/domain/ProfileService.java
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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();
Expand All @@ -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);
}
}
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 4b2e9d9

Please sign in to comment.