Skip to content

Commit 8cec5e3

Browse files
devondragonclaude
andcommitted
Add UserProfileUpdateDto for profile updates without password validation
Previously, the /user/updateUser endpoint used UserDto which requires email, password, and matchingPassword fields. This caused validation errors when users only wanted to update their name. Changes: - Add new UserProfileUpdateDto with only firstName and lastName fields - Update UserAPI.updateUserAccount() to use the new DTO - Profile updates no longer require password fields 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent e6a8548 commit 8cec5e3

2 files changed

Lines changed: 34 additions & 10 deletions

File tree

src/main/java/com/digitalsanctuary/spring/user/api/UserAPI.java

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import com.digitalsanctuary.spring.user.dto.PasswordResetRequestDto;
2222
import com.digitalsanctuary.spring.user.dto.SavePasswordDto;
2323
import com.digitalsanctuary.spring.user.dto.UserDto;
24+
import com.digitalsanctuary.spring.user.dto.UserProfileUpdateDto;
2425
import com.digitalsanctuary.spring.user.event.OnRegistrationCompleteEvent;
2526
import com.digitalsanctuary.spring.user.exceptions.InvalidOldPasswordException;
2627
import com.digitalsanctuary.spring.user.exceptions.UserAlreadyExistException;
@@ -131,24 +132,24 @@ public ResponseEntity<JSONResponse> resendRegistrationToken(@Valid @RequestBody
131132
}
132133

133134
/**
134-
* Updates the user's password. This is used when the user is logged in and
135-
* wants to change their password.
135+
* Updates the user's profile (first name, last name). This is used when the
136+
* user is logged in and wants to update their profile information.
136137
*
137-
* @param userDetails the authenticated user details
138-
* @param userDto the user data transfer object containing user details
139-
* @param request the HTTP servlet request
140-
* @param locale the locale
141-
* @return a ResponseEntity containing a JSONResponse with the password update
138+
* @param userDetails the authenticated user details
139+
* @param profileUpdateDto the profile update DTO containing first and last name
140+
* @param request the HTTP servlet request
141+
* @param locale the locale
142+
* @return a ResponseEntity containing a JSONResponse with the profile update
142143
* result
143144
*/
144145
@PostMapping("/updateUser")
145146
public ResponseEntity<JSONResponse> updateUserAccount(@AuthenticationPrincipal DSUserDetails userDetails,
146-
@Valid @RequestBody UserDto userDto,
147+
@Valid @RequestBody UserProfileUpdateDto profileUpdateDto,
147148
HttpServletRequest request, Locale locale) {
148149
validateAuthenticatedUser(userDetails);
149150
User user = userDetails.getUser();
150-
user.setFirstName(userDto.getFirstName());
151-
user.setLastName(userDto.getLastName());
151+
user.setFirstName(profileUpdateDto.getFirstName());
152+
user.setLastName(profileUpdateDto.getLastName());
152153
userService.saveRegisteredUser(user);
153154

154155
logAuditEvent("ProfileUpdate", "Success", "User profile updated", user, request);
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package com.digitalsanctuary.spring.user.dto;
2+
3+
import jakarta.validation.constraints.NotBlank;
4+
import jakarta.validation.constraints.Size;
5+
import lombok.Data;
6+
7+
/**
8+
* DTO for updating user profile information (first name, last name).
9+
* This is separate from UserDto to avoid requiring password fields during profile updates.
10+
*/
11+
@Data
12+
public class UserProfileUpdateDto {
13+
14+
/** The first name. */
15+
@NotBlank(message = "First name is required")
16+
@Size(max = 50, message = "First name must not exceed 50 characters")
17+
private String firstName;
18+
19+
/** The last name. */
20+
@NotBlank(message = "Last name is required")
21+
@Size(max = 50, message = "Last name must not exceed 50 characters")
22+
private String lastName;
23+
}

0 commit comments

Comments
 (0)