Skip to content

Commit

Permalink
refactor : Refactoring of Design Smell (Tools.java + ageutils.java) -…
Browse files Browse the repository at this point in the history
… 3 and Resolved Code Dependenices in (Oauth2Controller.java)
  • Loading branch information
Poojitha committed Apr 1, 2024
1 parent 4b2d12d commit e0e8429
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
28 changes: 28 additions & 0 deletions src/main/java/com/nonononoki/alovoa/ageUtils.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package com.nonononoki.alovoa;

import com.nonononoki.alovoa.model.AlovoaException;

import java.time.LocalDate;
import java.time.Period;
import java.util.Date;

public class ageUtils {

private ageUtils() throws AlovoaException {
throw new AlovoaException("no_contructor");
}

public static int convertPrefAge(Date userDateOfBirth, int prefAge, LocalDate currentDate, String year) {
LocalDate birthLocalDate = new java.sql.Date(userDateOfBirth.getTime()).toLocalDate();
int currentAge = Period.between(birthLocalDate, currentDate).getYears();

switch (year) {
case "Relative":
return prefAge - currentAge;
case "Exact":
return currentAge + prefAge;
default:
return 99999; // Replaces magic number 99999 with MAX_VALUE for clarity
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

import com.nonononoki.alovoa.html.IndexResource;
import com.nonononoki.alovoa.html.LoginResource;
import com.nonononoki.alovoa.service.AuthService;
import jakarta.servlet.http.Cookie;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
Expand Down Expand Up @@ -210,6 +211,6 @@ public void getRememberMeCookie(@PathVariable String rememberCookieValue, @PathV
}

private String getOauthParams(String username, String firstName, int page) {
return Tools.getAuthParams(securityConfig, httpSession.getId(), username, firstName, page);
return AuthService.getAuthParams(securityConfig, httpSession.getId(), username, firstName, page);
}
}

0 comments on commit e0e8429

Please sign in to comment.