Class UserServiceImpl
java.lang.Object
com.example.blogs.app.api.user.service.UserServiceImpl
- All Implemented Interfaces:
UserService
Orchestrates user operations by coordinating repository access, post retrieval, and entity-to-DTO mapping.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptioncreateUser(CreateUserCommand command) Creates a new user in the system.getUserByUsername(String username) Retrieves complete user profile with posts by username.getUserByUsernameOrEmail(String usernameOrEmail) Retrieves a user by username or email address.updateUserProfile(Long id, UpdateUserRequestDTO requestDTO, MultipartFile profilePicture) Updates user profile with optional field updates and profile picture replacement.
-
Constructor Details
-
UserServiceImpl
public UserServiceImpl()
-
-
Method Details
-
createUser
Description copied from interface:UserServiceCreates a new user in the system.- Specified by:
createUserin interfaceUserService- Parameters:
command- user creation details- Returns:
- the persisted user entity
-
getUserByUsernameOrEmail
Description copied from interface:UserServiceRetrieves a user by username or email address.- Specified by:
getUserByUsernameOrEmailin interfaceUserService- Parameters:
usernameOrEmail- the username or email to search for- Returns:
- the matching user entity
-
getUserByUsername
Retrieves complete user profile with posts by username. Fetches user entity, loads associated posts, and maps to DTO.- Specified by:
getUserByUsernamein interfaceUserService- Parameters:
username- the username to search for- Returns:
- user data transfer object with profile information and post summaries
- Throws:
UserNotFoundException- if no user is foundFailedToFindUserException- for database errors
-
updateUserProfile
@Transactional public UpdateUserResponseDTO updateUserProfile(Long id, UpdateUserRequestDTO requestDTO, MultipartFile profilePicture) Updates user profile with optional field updates and profile picture replacement. Supports partial updates - only non-null fields are modified. If a new profile picture is provided, the old one is deleted after successful update.- Specified by:
updateUserProfilein interfaceUserService- Parameters:
id- the user ID to updaterequestDTO- DTO containing fields to update (all fields optional)profilePicture- optional new profile picture file- Returns:
- response DTO with updated profile information
- Throws:
UserNotFoundException- if user with given ID is not foundUsernameTakenException- if new username is already takenEmailTakenException- if new email is already takenFailedToUpdateUserException- for database update failures
-