|
| 1 | +package org.ays.auth.model.mapper; |
| 2 | + |
| 3 | +import org.ays.auth.model.AysUser; |
| 4 | +import org.ays.auth.model.entity.AysUserEntity; |
| 5 | +import org.ays.common.model.mapper.BaseMapper; |
| 6 | +import org.mapstruct.Mapper; |
| 7 | +import org.mapstruct.Mapping; |
| 8 | +import org.mapstruct.factory.Mappers; |
| 9 | + |
| 10 | +/** |
| 11 | + * Mapper interface for converting {@link AysUserEntity} to {@link AysUser} domain objects without including |
| 12 | + * related entities such as roles, institution, and login attempt. |
| 13 | + * <p> |
| 14 | + * This interface uses MapStruct to generate the implementation at compile time. It defines a custom mapping |
| 15 | + * configuration that excludes sensitive or unnecessary fields for certain use cases. |
| 16 | + * </p> |
| 17 | + * <ul> |
| 18 | + * <li>Maps {@code countryCode} and {@code lineNumber} to {@code phoneNumber}.</li> |
| 19 | + * <li>Ignores {@code roles}, {@code institution}, {@code password}, and {@code loginAttempt} fields.</li> |
| 20 | + * </ul> |
| 21 | + * |
| 22 | + * <p>Implements the {@link BaseMapper} interface which defines the generic map method signature.</p> |
| 23 | + */ |
| 24 | +@Mapper |
| 25 | +public interface AysUserEntityToDomainWithoutRelationsMapper extends BaseMapper<AysUserEntity, AysUser> { |
| 26 | + |
| 27 | + /** |
| 28 | + * Maps an {@link AysUserEntity} to an {@link AysUser} excluding related entities and sensitive fields. |
| 29 | + * |
| 30 | + * @param userEntity the user entity to be mapped |
| 31 | + * @return a mapped {@link AysUser} object without roles, institution, password, or login attempt |
| 32 | + */ |
| 33 | + @Override |
| 34 | + @Mapping(target = "phoneNumber.countryCode", source = "countryCode") |
| 35 | + @Mapping(target = "phoneNumber.lineNumber", source = "lineNumber") |
| 36 | + @Mapping(target = "roles", source = "roles", ignore = true) |
| 37 | + @Mapping(target = "institution", source = "institution", ignore = true) |
| 38 | + @Mapping(target = "password", ignore = true) |
| 39 | + @Mapping(target = "loginAttempt", ignore = true) |
| 40 | + AysUser map(AysUserEntity userEntity); |
| 41 | + |
| 42 | + /** |
| 43 | + * Initializes and returns the MapStruct-generated implementation of this mapper. |
| 44 | + * |
| 45 | + * @return the mapper implementation instance |
| 46 | + */ |
| 47 | + static AysUserEntityToDomainWithoutRelationsMapper initialize() { |
| 48 | + return Mappers.getMapper(AysUserEntityToDomainWithoutRelationsMapper.class); |
| 49 | + } |
| 50 | + |
| 51 | +} |
0 commit comments