Skip to content

MapStruct entity-DTO conversion

MapStruct is used within the codebase to handle conversions between database entities and Data Transfer Objects (DTOs) or Value Objects (VOs).^[001-todo-code.md]

Implementation

The ReportConverter interface serves as the mapper, annotated with @Mapper.^[001-todo-code.md] MapStruct automatically generates an implementation of this interface at compile time.^[001-todo-code.md] A singleton instance of the generated mapper is exposed via the INSTANCES field, retrieved using Mappers.getMapper(ReportConverter.class).^[001-todo-code.md]

Mappings

The converter defines specific methods to map internal entities to different view objects required by the application layers^[001-todo-code.md]:

  • toQryVo: Converts the persistence entity ReportDownloadRecordEntity into ReportQryVo.
  • toVo: Converts ReportDownloadRecordEntity into ReportDownloadRecordVo.

Usage

The conversion logic is utilized by services such as ReportDownloadRecordServiceImpl.^[001-todo-code.md] For example, after querying the database for a record, the service uses ReportConverter.INSTANCES.toVo(...) to transform the database entity into a value object before returning it to the domain or controller layer^[001-todo-code.md].

Sources

^[001-todo-code.md]