Skip to content

Commit 5ccccfd

Browse files
authored
AYS-787 | User List Queries Have Been Optimized (#475)
1 parent 9ae94a9 commit 5ccccfd

File tree

2 files changed

+54
-1
lines changed

2 files changed

+54
-1
lines changed
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
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+
}

src/main/java/org/ays/auth/port/adapter/AysUserAdapter.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import org.ays.auth.model.AysUserFilter;
66
import org.ays.auth.model.entity.AysUserEntity;
77
import org.ays.auth.model.mapper.AysUserEntityToDomainMapper;
8+
import org.ays.auth.model.mapper.AysUserEntityToDomainWithoutRelationsMapper;
89
import org.ays.auth.model.mapper.AysUserToEntityMapper;
910
import org.ays.auth.port.AysUserReadPort;
1011
import org.ays.auth.port.AysUserSavePort;
@@ -36,6 +37,7 @@ class AysUserAdapter implements AysUserReadPort, AysUserSavePort {
3637

3738
private final AysUserToEntityMapper userToEntityMapper = AysUserToEntityMapper.initialize();
3839
private final AysUserEntityToDomainMapper userEntityToDomainMapper = AysUserEntityToDomainMapper.initialize();
40+
private final AysUserEntityToDomainWithoutRelationsMapper userEntityToDomainWithoutRelationsMapper = AysUserEntityToDomainWithoutRelationsMapper.initialize();
3941

4042

4143
/**
@@ -58,7 +60,7 @@ public AysPage<AysUser> findAll(AysPageable aysPageable, AysUserFilter filter) {
5860

5961
final Page<AysUserEntity> userEntitysPage = userRepository.findAll(specification, pageable);
6062

61-
final List<AysUser> users = userEntityToDomainMapper.map(userEntitysPage.getContent());
63+
final List<AysUser> users = userEntityToDomainWithoutRelationsMapper.map(userEntitysPage.getContent());
6264

6365
return AysPage.of(filter, userEntitysPage, users);
6466
}

0 commit comments

Comments
 (0)