Class UserServiceImpl

java.lang.Object
com.example.blogs.app.api.user.service.UserServiceImpl
All Implemented Interfaces:
UserService

@Service public class UserServiceImpl extends Object implements UserService
Orchestrates user operations by coordinating repository access, post retrieval, and entity-to-DTO mapping.
  • Constructor Details

    • UserServiceImpl

      public UserServiceImpl()
  • Method Details

    • createUser

      public UserEntity createUser(CreateUserCommand command)
      Description copied from interface: UserService
      Creates a new user in the system.
      Specified by:
      createUser in interface UserService
      Parameters:
      command - user creation details
      Returns:
      the persisted user entity
    • getUserByUsernameOrEmail

      public UserEntity getUserByUsernameOrEmail(String usernameOrEmail)
      Description copied from interface: UserService
      Retrieves a user by username or email address.
      Specified by:
      getUserByUsernameOrEmail in interface UserService
      Parameters:
      usernameOrEmail - the username or email to search for
      Returns:
      the matching user entity
    • getUserByUsername

      public UserDTO getUserByUsername(String username)
      Retrieves complete user profile with posts by username. Fetches user entity, loads associated posts, and maps to DTO.
      Specified by:
      getUserByUsername in interface UserService
      Parameters:
      username - the username to search for
      Returns:
      user data transfer object with profile information and post summaries
      Throws:
      UserNotFoundException - if no user is found
      FailedToFindUserException - 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:
      updateUserProfile in interface UserService
      Parameters:
      id - the user ID to update
      requestDTO - 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 found
      UsernameTakenException - if new username is already taken
      EmailTakenException - if new email is already taken
      FailedToUpdateUserException - for database update failures