Skip to content

Commit

Permalink
FE URL Updates | SIS-166 (#86)
Browse files Browse the repository at this point in the history
* Back-End URL and Front-End URL Have Been Added to application.yml File for Local and Live

* Back-End URL and Front-End URL Have Been Read from application.yml
  • Loading branch information
agitrubard authored Apr 19, 2022
1 parent 30ae7a0 commit c4f8525
Show file tree
Hide file tree
Showing 32 changed files with 77 additions and 94 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,4 @@ public class SisOperationInfoRequest implements Serializable {
@NotNull
@OperationUserID
private Long userId;

private String feUrl;
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,23 @@
import com.graduationproject.studentinformationsystem.common.util.SisUtil;
import com.graduationproject.studentinformationsystem.login.officer.password.model.dto.response.OfficerPasswordOperationResponse;
import com.graduationproject.studentinformationsystem.login.officer.password.model.entity.OfficerPasswordOperationEntity;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

import java.time.LocalDateTime;

@Component
public class OfficerPasswordOperationInfoConverter {

public OfficerPasswordOperationEntity generateEntity(final Long officerId, final String feUrl) {
@Value("${sis.fe-url}")
private String feUrl;

public OfficerPasswordOperationEntity generateEntity(final Long officerId) {

return OfficerPasswordOperationEntity.builder()
.operationId(SisUtil.generateRandomUUID())
.officerId(officerId)
.expireDate(LocalDateTime.now().plusDays(1))
.feUrl(feUrl)
.build();
}

Expand All @@ -28,7 +31,7 @@ public OfficerPasswordOperationResponse entityToResponse(final OfficerPasswordOp
.operationId(operationId)
.officerId(passwordOperationEntity.getOfficerId())
.expireDate(passwordOperationEntity.getExpireDate())
.passwordChangeUrl(passwordOperationEntity.getFeUrl() + "/login/officer/change-password/" + operationId)
.passwordChangeUrl(feUrl + "/login/officer/change-password/" + operationId)
.build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,4 @@ public class OfficerPasswordForgotRequest implements Serializable {
@NotNull
@OfficerID
private Long officerId;

@NotNull
private String feUrl;
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,4 @@ public class OfficerPasswordOperationEntity {
private String operationId;
private Long officerId;
private LocalDateTime expireDate;
private String feUrl;
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@ public enum OfficerPasswordOperationMapping {

OPERATION_ID("OPERATION_ID", "operationId"),
OFFICER_ID("OFFICER_ID", "officerId"),
EXPIRE_DATE("EXPIRE_DATE", "expireDate"),
FE_URL("FE_URL", "feUrl");
EXPIRE_DATE("EXPIRE_DATE", "expireDate");

private final String columnName;
private final String modelName;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ public void savePasswordOperation(final OfficerPasswordOperationEntity passwordO
query.addParameter(OPERATION_ID.getModelName(), passwordOperationEntity.getOperationId())
.addParameter(OFFICER_ID.getModelName(), passwordOperationEntity.getOfficerId())
.addParameter(EXPIRE_DATE.getModelName(), passwordOperationEntity.getExpireDate())
.addParameter(FE_URL.getModelName(), passwordOperationEntity.getFeUrl())
.executeUpdate();

// TODO: Specific Info Log Must be Added
Expand All @@ -57,7 +56,6 @@ public void updatePasswordOperation(final OfficerPasswordOperationEntity passwor
query.addParameter(OPERATION_ID.getModelName(), passwordOperationEntity.getOperationId())
.addParameter(OFFICER_ID.getModelName(), passwordOperationEntity.getOfficerId())
.addParameter(EXPIRE_DATE.getModelName(), passwordOperationEntity.getExpireDate())
.addParameter(FE_URL.getModelName(), passwordOperationEntity.getFeUrl())
.executeUpdate();

// TODO: Specific Info Log Must be Added
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,31 +8,31 @@ private OfficerPasswordOperationSqlScripts() {
}

/**
* SELECT OPERATION_ID, OFFICER_ID, EXPIRE_DATE, FE_URL FROM AUTH_OFFICER_PASSWORD_OPERATION
* SELECT OPERATION_ID, OFFICER_ID, EXPIRE_DATE FROM AUTH_OFFICER_PASSWORD_OPERATION
* WHERE OFFICER_ID=:officerId;
*/
public static final String GET_OFFICER_PASSWORD_OPERATION =
sqlBuilder.delete(0, sqlBuilder.length())
.append("SELECT OPERATION_ID, OFFICER_ID, EXPIRE_DATE, FE_URL " +
.append("SELECT OPERATION_ID, OFFICER_ID, EXPIRE_DATE " +
"FROM AUTH_OFFICER_PASSWORD_OPERATION WHERE OFFICER_ID=:officerId").toString();

/**
* INSERT INTO AUTH_OFFICER_PASSWORD_OPERATION SET OPERATION_ID=:operationId,
* OFFICER_ID=:officerId, EXPIRE_DATE=:expireDate, FE_URL=:feUrl;
* OFFICER_ID=:officerId, EXPIRE_DATE=:expireDate;
*/
public static final String SAVE_OFFICER_PASSWORD_OPERATION =
sqlBuilder.delete(0, sqlBuilder.length())
.append("INSERT INTO AUTH_OFFICER_PASSWORD_OPERATION SET OPERATION_ID=:operationId, " +
"OFFICER_ID=:officerId, EXPIRE_DATE=:expireDate, FE_URL=:feUrl").toString();
"OFFICER_ID=:officerId, EXPIRE_DATE=:expireDate").toString();

/**
* UPDATE AUTH_OFFICER_PASSWORD_OPERATION SET OPERATION_ID=:operationId, EXPIRE_DATE=:expireDate, FE_URL=:feUrl
* UPDATE AUTH_OFFICER_PASSWORD_OPERATION SET OPERATION_ID=:operationId, EXPIRE_DATE=:expireDate
* WHERE OFFICER_ID=:officerId;
*/
public static final String UPDATE_OFFICER_PASSWORD_OPERATION =
sqlBuilder.delete(0, sqlBuilder.length())
.append("UPDATE AUTH_OFFICER_PASSWORD_OPERATION SET OPERATION_ID=:operationId, " +
"EXPIRE_DATE=:expireDate, FE_URL=:feUrl WHERE OFFICER_ID=:officerId").toString();
"EXPIRE_DATE=:expireDate WHERE OFFICER_ID=:officerId").toString();

/**
* DELETE FROM AUTH_OFFICER_PASSWORD_OPERATION WHERE OPERATION_ID=:operationId;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@ public interface OfficerPasswordOperationOutService {

String getPasswordChangeUrl(Long officerId);

void saveOrUpdatePasswordOperation(Long officerId, String feUrl) throws SisNotExistException;
void saveOrUpdatePasswordOperation(Long officerId) throws SisNotExistException;
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,19 +23,18 @@ public class OfficerPasswordOperationOutServiceImpl implements OfficerPasswordOp
public String getPasswordChangeUrl(final Long officerId) {

final OfficerPasswordOperationResponse passwordOperationResponse = getPasswordOperation(officerId);

return passwordOperationResponse.getPasswordChangeUrl();
}

@Override
public void saveOrUpdatePasswordOperation(final Long officerId, final String feUrl) throws SisNotExistException {
public void saveOrUpdatePasswordOperation(final Long officerId) throws SisNotExistException {

boolean isOperationExist = isOperationExist(officerId);

if (!isOperationExist) {
savePasswordOperation(officerId, feUrl);
savePasswordOperation(officerId);
} else {
updatePasswordOperation(officerId, feUrl);
updatePasswordOperation(officerId);
}
}

Expand All @@ -46,24 +45,24 @@ private OfficerPasswordOperationResponse getPasswordOperation(final Long officer
return passwordOperationInfoConverter.entityToResponse(passwordOperationEntity);
}

private void savePasswordOperation(final Long officerId, final String feUrl)
private void savePasswordOperation(final Long officerId)
throws SisNotExistException {

checkBeforeSaving(officerId);

final OfficerPasswordOperationEntity passwordOperationEntity = passwordOperationInfoConverter
.generateEntity(officerId, feUrl);
.generateEntity(officerId);

passwordOperationRepository.savePasswordOperation(passwordOperationEntity);
}

private void updatePasswordOperation(final Long officerId, final String feUrl)
private void updatePasswordOperation(final Long officerId)
throws SisNotExistException {

checkBeforeUpdating(officerId);

final OfficerPasswordOperationEntity passwordOperationEntity = passwordOperationInfoConverter
.generateEntity(officerId, feUrl);
.generateEntity(officerId);

passwordOperationRepository.updatePasswordOperation(passwordOperationEntity);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public OfficerPasswordForgotResponse forgotPassword(OfficerPasswordForgotRequest

final OfficerInfoDetailResponse infoDetailResponse = officerOutService.getOfficerInfoDetailResponse(officerId);

passwordOperationOutService.saveOrUpdatePasswordOperation(officerId, passwordForgotRequest.getFeUrl());
passwordOperationOutService.saveOrUpdatePasswordOperation(officerId);
officerMailService.sendForgotPasswordEmail(infoDetailResponse);

return OfficerPasswordForgotResponse.builder()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,23 @@
import com.graduationproject.studentinformationsystem.common.util.SisUtil;
import com.graduationproject.studentinformationsystem.login.student.password.model.dto.response.StudentPasswordOperationResponse;
import com.graduationproject.studentinformationsystem.login.student.password.model.entity.StudentPasswordOperationEntity;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

import java.time.LocalDateTime;

@Component
public class StudentPasswordOperationInfoConverter {

public StudentPasswordOperationEntity generateEntity(final Long studentId, final String feUrl) {
@Value("${sis.fe-url}")
private String feUrl;

public StudentPasswordOperationEntity generateEntity(final Long studentId) {

return StudentPasswordOperationEntity.builder()
.operationId(SisUtil.generateRandomUUID())
.studentId(studentId)
.expireDate(LocalDateTime.now().plusDays(1))
.feUrl(feUrl)
.build();
}

Expand All @@ -28,7 +31,7 @@ public StudentPasswordOperationResponse entityToResponse(final StudentPasswordOp
.operationId(operationId)
.studentId(passwordOperationEntity.getStudentId())
.expireDate(passwordOperationEntity.getExpireDate())
.passwordChangeUrl(passwordOperationEntity.getFeUrl() + "/login/student/change-password/" + operationId)
.passwordChangeUrl(feUrl + "/login/student/change-password/" + operationId)
.build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,4 @@ public class StudentPasswordForgotRequest implements Serializable {
@NotNull
@StudentID
private Long studentId;

@NotNull
private String feUrl;
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,4 @@ public class StudentPasswordOperationEntity {
private String operationId;
private Long studentId;
private LocalDateTime expireDate;
private String feUrl;
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@ public enum StudentPasswordOperationMapping {

OPERATION_ID("OPERATION_ID", "operationId"),
STUDENT_ID("STUDENT_ID", "studentId"),
EXPIRE_DATE("EXPIRE_DATE", "expireDate"),
FE_URL("FE_URL", "feUrl");
EXPIRE_DATE("EXPIRE_DATE", "expireDate");

private final String columnName;
private final String modelName;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ public void savePasswordOperation(final StudentPasswordOperationEntity passwordO
query.addParameter(OPERATION_ID.getModelName(), passwordOperationEntity.getOperationId())
.addParameter(STUDENT_ID.getModelName(), passwordOperationEntity.getStudentId())
.addParameter(EXPIRE_DATE.getModelName(), passwordOperationEntity.getExpireDate())
.addParameter(FE_URL.getModelName(), passwordOperationEntity.getFeUrl())
.executeUpdate();

// TODO: Specific Info Log Must be Added
Expand All @@ -57,7 +56,6 @@ public void updatePasswordOperation(final StudentPasswordOperationEntity passwor
query.addParameter(OPERATION_ID.getModelName(), passwordOperationEntity.getOperationId())
.addParameter(STUDENT_ID.getModelName(), passwordOperationEntity.getStudentId())
.addParameter(EXPIRE_DATE.getModelName(), passwordOperationEntity.getExpireDate())
.addParameter(FE_URL.getModelName(), passwordOperationEntity.getFeUrl())
.executeUpdate();

// TODO: Specific Info Log Must be Added
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,31 +8,31 @@ private StudentPasswordOperationSqlScripts() {
}

/**
* SELECT OPERATION_ID, STUDENT_ID, EXPIRE_DATE, FE_URL FROM AUTH_STUDENT_PASSWORD_OPERATION
* SELECT OPERATION_ID, STUDENT_ID, EXPIRE_DATE FROM AUTH_STUDENT_PASSWORD_OPERATION
* WHERE STUDENT_ID=:studentId;
*/
public static final String GET_STUDENT_PASSWORD_OPERATION =
sqlBuilder.delete(0, sqlBuilder.length())
.append("SELECT OPERATION_ID, STUDENT_ID, EXPIRE_DATE, FE_URL " +
.append("SELECT OPERATION_ID, STUDENT_ID, EXPIRE_DATE " +
"FROM AUTH_STUDENT_PASSWORD_OPERATION WHERE STUDENT_ID=:studentId").toString();

/**
* INSERT INTO AUTH_STUDENT_PASSWORD_OPERATION SET OPERATION_ID=:operationId,
* STUDENT_ID=:studentId, EXPIRE_DATE=:expireDate, FE_URL=:feUrl;
* STUDENT_ID=:studentId, EXPIRE_DATE=:expireDate;
*/
public static final String SAVE_STUDENT_PASSWORD_OPERATION =
sqlBuilder.delete(0, sqlBuilder.length())
.append("INSERT INTO AUTH_STUDENT_PASSWORD_OPERATION SET OPERATION_ID=:operationId, " +
"STUDENT_ID=:studentId, EXPIRE_DATE=:expireDate, FE_URL=:feUrl").toString();
"STUDENT_ID=:studentId, EXPIRE_DATE=:expireDate").toString();

/**
* UPDATE AUTH_STUDENT_PASSWORD_OPERATION SET OPERATION_ID=:operationId, EXPIRE_DATE=:expireDate, FE_URL=:feUrl
* UPDATE AUTH_STUDENT_PASSWORD_OPERATION SET OPERATION_ID=:operationId, EXPIRE_DATE=:expireDate
* WHERE STUDENT_ID=:studentId;
*/
public static final String UPDATE_STUDENT_PASSWORD_OPERATION =
sqlBuilder.delete(0, sqlBuilder.length())
.append("UPDATE AUTH_STUDENT_PASSWORD_OPERATION SET OPERATION_ID=:operationId, " +
"EXPIRE_DATE=:expireDate, FE_URL=:feUrl WHERE STUDENT_ID=:studentId").toString();
"EXPIRE_DATE=:expireDate WHERE STUDENT_ID=:studentId").toString();

/**
* DELETE FROM AUTH_STUDENT_PASSWORD_OPERATION WHERE OPERATION_ID=:operationId;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@ public interface StudentPasswordOperationOutService {

String getPasswordChangeUrl(Long studentId);

void saveOrUpdatePasswordOperation(Long studentId, String feUrl) throws SisNotExistException;
void saveOrUpdatePasswordOperation(Long studentId) throws SisNotExistException;
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,14 @@ public String getPasswordChangeUrl(final Long studentId) {
}

@Override
public void saveOrUpdatePasswordOperation(final Long studentId, final String feUrl) throws SisNotExistException {
public void saveOrUpdatePasswordOperation(final Long studentId) throws SisNotExistException {

boolean isOperationExist = isOperationExist(studentId);

if (!isOperationExist) {
savePasswordOperation(studentId, feUrl);
savePasswordOperation(studentId);
} else {
updatePasswordOperation(studentId, feUrl);
updatePasswordOperation(studentId);
}
}

Expand All @@ -46,25 +46,21 @@ private StudentPasswordOperationResponse getPasswordOperation(final Long student
return passwordOperationInfoConverter.entityToResponse(passwordOperationEntity);
}

private void savePasswordOperation(final Long studentId, final String feUrl)
private void savePasswordOperation(final Long studentId)
throws SisNotExistException {

checkBeforeSaving(studentId);

final StudentPasswordOperationEntity passwordOperationEntity = passwordOperationInfoConverter
.generateEntity(studentId, feUrl);

final StudentPasswordOperationEntity passwordOperationEntity = passwordOperationInfoConverter.generateEntity(studentId);
passwordOperationRepository.savePasswordOperation(passwordOperationEntity);
}

private void updatePasswordOperation(final Long studentId, final String feUrl)
private void updatePasswordOperation(final Long studentId)
throws SisNotExistException {

checkBeforeUpdating(studentId);

final StudentPasswordOperationEntity passwordOperationEntity = passwordOperationInfoConverter
.generateEntity(studentId, feUrl);

final StudentPasswordOperationEntity passwordOperationEntity = passwordOperationInfoConverter.generateEntity(studentId);
passwordOperationRepository.updatePasswordOperation(passwordOperationEntity);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public StudentPasswordForgotResponse forgotPassword(StudentPasswordForgotRequest

final StudentInfoDetailResponse infoDetailResponse = studentOutService.getStudentInfoDetailResponse(studentId);

passwordOperationOutService.saveOrUpdatePasswordOperation(studentId, passwordForgotRequest.getFeUrl());
passwordOperationOutService.saveOrUpdatePasswordOperation(studentId);
studentMailService.sendForgotPasswordEmail(infoDetailResponse);

return StudentPasswordForgotResponse.builder()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,23 @@
import com.graduationproject.studentinformationsystem.common.util.SisUtil;
import com.graduationproject.studentinformationsystem.login.teacher.password.model.dto.response.TeacherPasswordOperationResponse;
import com.graduationproject.studentinformationsystem.login.teacher.password.model.entity.TeacherPasswordOperationEntity;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

import java.time.LocalDateTime;

@Component
public class TeacherPasswordOperationInfoConverter {

public TeacherPasswordOperationEntity generateEntity(final Long teacherId, final String feUrl) {
@Value("${sis.fe-url}")
private String feUrl;

public TeacherPasswordOperationEntity generateEntity(final Long teacherId) {

return TeacherPasswordOperationEntity.builder()
.operationId(SisUtil.generateRandomUUID())
.teacherId(teacherId)
.expireDate(LocalDateTime.now().plusDays(1))
.feUrl(feUrl)
.build();
}

Expand All @@ -28,7 +31,7 @@ public TeacherPasswordOperationResponse entityToResponse(final TeacherPasswordOp
.operationId(operationId)
.teacherId(passwordOperationEntity.getTeacherId())
.expireDate(passwordOperationEntity.getExpireDate())
.passwordChangeUrl(passwordOperationEntity.getFeUrl() + "/login/teacher/change-password/" + operationId)
.passwordChangeUrl(feUrl + "/login/teacher/change-password/" + operationId)
.build();
}
}
Loading

0 comments on commit c4f8525

Please sign in to comment.