Skip to content

Commit

Permalink
AYS-427 | AdminRegistrationApplicationNotExistException Has Been In…
Browse files Browse the repository at this point in the history
…tegrated to Summary and Complete Admin Registration Flows (#372)
  • Loading branch information
agitrubard authored Sep 10, 2024
1 parent 7b2d2c8 commit 3eb7bfc
Show file tree
Hide file tree
Showing 10 changed files with 220 additions and 144 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,11 @@
import org.ays.auth.port.AdminRegistrationApplicationSavePort;
import org.ays.auth.port.AysUserSavePort;
import org.ays.auth.service.AdminRegistrationApplicationService;
import org.ays.auth.util.exception.AdminRegistrationApplicationNotExistByIdException;
import org.ays.auth.util.exception.AdminRegistrationApplicationNotExistException;
import org.ays.auth.util.exception.AysAdminRegistrationApplicationAlreadyApprovedException;
import org.ays.auth.util.exception.AysAdminRegistrationApplicationAlreadyRejectedException;
import org.ays.auth.util.exception.AysAdminRegistrationApplicationInCompleteException;
import org.ays.auth.util.exception.AysAdminRegistrationApplicationNotExistByIdException;
import org.ays.common.model.AysPage;
import org.ays.common.model.AysPageable;
import org.ays.institution.port.InstitutionReadPort;
Expand Down Expand Up @@ -67,7 +68,7 @@ public AysPage<AdminRegistrationApplication> findAll(final AdminRegistrationAppl
@Override
public AdminRegistrationApplication findById(String id) {
return adminRegistrationApplicationReadPort.findById(id)
.orElseThrow(() -> new AysAdminRegistrationApplicationNotExistByIdException(id));
.orElseThrow(() -> new AdminRegistrationApplicationNotExistByIdException(id));
}

/**
Expand All @@ -82,7 +83,7 @@ public AdminRegistrationApplication findSummaryById(String id) {

return adminRegistrationApplicationReadPort.findById(id)
.filter(AdminRegistrationApplication::isWaiting)
.orElseThrow(() -> new AysAdminRegistrationApplicationNotExistByIdException(id));
.orElseThrow(() -> new AdminRegistrationApplicationNotExistException(id));
}

/**
Expand Down Expand Up @@ -118,7 +119,7 @@ public AdminRegistrationApplication create(AdminRegistrationApplicationCreateReq
public void approve(String id) {
final AdminRegistrationApplication registrationApplication = adminRegistrationApplicationReadPort
.findById(id)
.orElseThrow(() -> new AysAdminRegistrationApplicationNotExistByIdException(id));
.orElseThrow(() -> new AdminRegistrationApplicationNotExistByIdException(id));

this.checkApplicationStatus(registrationApplication);

Expand All @@ -141,7 +142,7 @@ public void approve(String id) {
public void reject(final String id, final AdminRegistrationApplicationRejectRequest rejectRequest) {
final AdminRegistrationApplication registrationApplication = adminRegistrationApplicationReadPort
.findById(id)
.orElseThrow(() -> new AysAdminRegistrationApplicationNotExistByIdException(id));
.orElseThrow(() -> new AdminRegistrationApplicationNotExistByIdException(id));

this.checkApplicationStatus(registrationApplication);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
import org.ays.auth.port.AysUserReadPort;
import org.ays.auth.port.AysUserSavePort;
import org.ays.auth.service.AdminRegistrationCompleteService;
import org.ays.auth.util.exception.AysAdminRegistrationApplicationNotExistByIdException;
import org.ays.auth.util.exception.AdminRegistrationApplicationNotExistException;
import org.ays.auth.util.exception.AysUserAlreadyExistsByEmailAddressException;
import org.ays.auth.util.exception.AysUserAlreadyExistsByPhoneNumberException;
import org.ays.institution.model.Institution;
Expand Down Expand Up @@ -58,19 +58,14 @@ class AdminRegistrationCompleteServiceImpl implements AdminRegistrationCompleteS
* @param id The unique identifier of the admin registration application.
* @param completeRequest The request containing necessary information to complete the registration.
* This includes user details such as email, phone number, and password.
* @throws AysAdminRegistrationApplicationNotExistByIdException if the registration application does not exist or is not in a waiting state.
* @throws AysUserAlreadyExistsByEmailAddressException if a user with the given email already exists.
* @throws AysUserAlreadyExistsByPhoneNumberException if a user with the given phone number already exists.
* @throws AdminRegistrationApplicationNotExistException if the registration application does not exist or is not in a waiting state.
* @throws AysUserAlreadyExistsByEmailAddressException if a user with the given email already exists.
* @throws AysUserAlreadyExistsByPhoneNumberException if a user with the given phone number already exists.
*/
@Override
public void complete(final String id, final AdminRegistrationApplicationCompleteRequest completeRequest) {
log.trace("Admin Register Flow call starting for email of {}", completeRequest.getEmailAddress());

final AdminRegistrationApplication application = adminRegistrationApplicationReadPort
.findById(id)
.filter(AdminRegistrationApplication::isWaiting)
.orElseThrow(() -> new AysAdminRegistrationApplicationNotExistByIdException(id));

log.trace("Admin Register Flow call starting for email of {}", completeRequest.getEmailAddress());

final AysUser user = adminRegistrationApplicationCompleteRequestToUserMapper.map(completeRequest);

Expand All @@ -85,6 +80,11 @@ public void complete(final String id, final AdminRegistrationApplicationComplete
log.trace("Admin Registration Request checked successfully!");


final AdminRegistrationApplication application = adminRegistrationApplicationReadPort
.findById(id)
.filter(AdminRegistrationApplication::isWaiting)
.orElseThrow(() -> new AdminRegistrationApplicationNotExistException(id));

user.setInstitution(application.getInstitution());
user.notVerify();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
* Typically, this exception is thrown when an operation or query is performed on an admin register application
* entity using an ID that does not correspond to an existing admin register application.
*/
public final class AysAdminRegistrationApplicationNotExistByIdException extends AysNotExistException {
public final class AdminRegistrationApplicationNotExistByIdException extends AysNotExistException {

/**
* Unique identifier for serialization.
Expand All @@ -20,11 +20,11 @@ public final class AysAdminRegistrationApplicationNotExistByIdException extends
private static final long serialVersionUID = 8416712253227498925L;

/**
* Constructs a new {@link AysAdminRegistrationApplicationNotExistByIdException} with the specified ID.
* Constructs a new {@link AdminRegistrationApplicationNotExistByIdException} with the specified ID.
*
* @param id The ID of the admin registration application that does not exist.
*/
public AysAdminRegistrationApplicationNotExistByIdException(String id) {
public AdminRegistrationApplicationNotExistByIdException(String id) {
super("admin registration application not exist! id:" + id);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package org.ays.auth.util.exception;

import org.ays.common.util.exception.AysAuthException;

import java.io.Serial;

/**
* Exception indicating that an admin registration application does not exist with the specified ID.
* It extends {@link AysAuthException}, which provides the base exception for all authentication-related issues in the application.
* Typically, this exception is thrown when an operation or query is performed on an admin register application
* entity using an ID that does not correspond to an existing admin register application.
*/
public final class AdminRegistrationApplicationNotExistException extends AysAuthException {

/**
* Unique identifier for serialization.
*/
@Serial
private static final long serialVersionUID = 8875043711494901525L;

/**
* Constructs a new {@link AdminRegistrationApplicationNotExistException} with the specified ID.
*
* @param id The ID of the admin registration application that does not exist.
*/
public AdminRegistrationApplicationNotExistException(String id) {
super("admin registration application does not exist! id:" + id);
}

}
26 changes: 0 additions & 26 deletions src/main/java/org/ays/common/util/AysUUID.java

This file was deleted.

2 changes: 1 addition & 1 deletion src/test/java/org/ays/AysMockMvc.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public ResultActions perform(final MockHttpServletRequestBuilder mockHttpServlet
.andExpect(AysMockResultMatchersBuilders.header()
.value(mockErrorResponse.getHeader()))
.andExpect(AysMockResultMatchersBuilders.response()
.doesNotExist());
.doesNotHaveJsonPath());
}

}
Loading

0 comments on commit 3eb7bfc

Please sign in to comment.