Interface ChallengeMapper


public interface ChallengeMapper
Mapper interface for converting back and forth from a DTO to a Challenge entity.
Since:
18.4.2024
Version:
1.0
Author:
Yasin M.
  • Field Details

    • INSTANCE

      static final ChallengeMapper INSTANCE
      Implementation instance of the mapper
  • Method Details

    • toDTO

      ChallengeDTO toDTO(Challenge challenge)
      Converts from Challenge entity to DTO. Calculates completion value as percentage of saved amount to target amount
      Parameters:
      challenge - Challenge entity
      Returns:
      Converted DTO
    • toEntity

      Challenge toEntity(ChallengeCreateDTO challengeCreateDTO, User user)
      Converts from challenge DTO to entity. Ignore null values. Calculates completion value as percentage of saved amount to target amount. Type is capitalized only on first letter.
      Parameters:
      challengeCreateDTO - Challenge DTO
      user - User who owns the challenge
      Returns:
      Converted challenge entity
    • updateEntity

      Challenge updateEntity(Challenge challenge, ChallengeUpdateDTO challengeDTO)
      Updates a challenge entity using dto. Ignore null values. Calculates completion value as percentage of saved amount to target amount. Type is capitalized only on first letter.
      Parameters:
      challenge - Challenge entity that is updated
      challengeDTO - DTO with new changes
      Returns:
      Updated challenge entity
    • getType

      default String getType(String type)
      Formats type of challenge to capitalized first letter
      Parameters:
      type - Unformatted type
      Returns:
      Formatted type
    • updateType

      default void updateType(Challenge challenge, ChallengeUpdateDTO challengeDTO)
      Sets the type of challenge to null if DTO type is null
      Parameters:
      challenge - Challenge entity
      challengeDTO - Challenge DTO