forked from ajaynegi45/LibraryMan-API
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: implement password update endpoint with DTO and exception handling
- Loading branch information
1 parent
c94ddbd
commit 3907744
Showing
5 changed files
with
201 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
50 changes: 50 additions & 0 deletions
50
src/main/java/com/libraryman_api/exception/InvalidPasswordException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package com.libraryman_api.exception; | ||
|
||
import java.io.Serial; | ||
|
||
/** | ||
* Custom exception class to handle scenarios where an invalid password is provided | ||
* in the Library Management System. This exception is thrown when a password update | ||
* operation fails due to invalid password criteria. | ||
*/ | ||
public class InvalidPasswordException extends RuntimeException { | ||
|
||
/** | ||
* The {@code serialVersionUID} is a unique identifier for each version of a serializable class. | ||
* It is used during the deserialization process to verify that the sender and receiver of a | ||
* serialized object have loaded classes for that object that are compatible with each other. | ||
* | ||
* The {@code serialVersionUID} field is important for ensuring that a serialized class | ||
* (especially when transmitted over a network or saved to disk) can be successfully deserialized, | ||
* even if the class definition changes in later versions. If the {@code serialVersionUID} does not | ||
* match during deserialization, an {@code InvalidClassException} is thrown. | ||
* | ||
* This field is optional, but it is good practice to explicitly declare it to prevent | ||
* automatic generation, which could lead to compatibility issues when the class structure changes. | ||
* | ||
* The {@code @Serial} annotation is used here to indicate that this field is related to | ||
* serialization. This annotation is available starting from Java 14 and helps improve clarity | ||
* regarding the purpose of this field. | ||
*/ | ||
@Serial | ||
private static final long serialVersionUID = 1L; | ||
|
||
/** | ||
* Constructs a new {@code InvalidPasswordException} with the specified detail message. | ||
* | ||
* @param message the detail message explaining the reason for the exception | ||
*/ | ||
public InvalidPasswordException(String message) { | ||
super(message); | ||
} | ||
|
||
/** | ||
* Constructs a new {@code InvalidPasswordException} with the specified detail message and cause. | ||
* | ||
* @param message the detail message explaining the reason for the exception | ||
* @param cause the cause of the exception (which is saved for later retrieval by the {@link #getCause()} method) | ||
*/ | ||
public InvalidPasswordException(String message, Throwable cause) { | ||
super(message, cause); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
src/main/java/com/libraryman_api/member/UpdatePasswordDto.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package com.libraryman_api.member; | ||
|
||
public class UpdatePasswordDto { | ||
|
||
private String currentPassword; | ||
|
||
private String newPassword; | ||
|
||
public UpdatePasswordDto(String currentPassword, String newPassword) { | ||
this.currentPassword = currentPassword; | ||
this.newPassword = newPassword; | ||
} | ||
|
||
public UpdatePasswordDto() { | ||
} | ||
|
||
public String getCurrentPassword() { | ||
return currentPassword; | ||
} | ||
|
||
public void setCurrentPassword(String currentPassword) { | ||
this.currentPassword = currentPassword; | ||
} | ||
|
||
public String getNewPassword() { | ||
return newPassword; | ||
} | ||
|
||
public void setNewPassword(String newPassword) { | ||
this.newPassword = newPassword; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "UpdatePasswordDto{" + | ||
"currentPassword='" + currentPassword + '\'' + | ||
", newPassword='" + newPassword + '\'' + | ||
'}'; | ||
} | ||
} |