TransactionRecordMapperImpl.java
package com.github.jenkaby.bikerental.finance.infrastructure.persistence.mapper;
import com.github.jenkaby.bikerental.finance.domain.model.SubLedgerRef;
import com.github.jenkaby.bikerental.finance.domain.model.TransactionRecord;
import com.github.jenkaby.bikerental.finance.infrastructure.persistence.entity.TransactionRecordJpaEntity;
import com.github.jenkaby.bikerental.shared.mapper.MoneyMapper;
import java.util.UUID;
import javax.annotation.processing.Generated;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
@Generated(
value = "org.mapstruct.ap.MappingProcessor",
comments = "version: 1.6.3, compiler: IncrementalProcessingEnvironment from gradle-language-java-9.4.1.jar, environment: Java 21.0.10 (Amazon.com Inc.)"
)
@Component
public class TransactionRecordMapperImpl implements TransactionRecordMapper {
private final MoneyMapper moneyMapper;
@Autowired
public TransactionRecordMapperImpl(MoneyMapper moneyMapper) {
this.moneyMapper = moneyMapper;
}
@Override
public TransactionRecord toDomain(TransactionRecordJpaEntity entity) {
if ( entity == null ) {
return null;
}
TransactionRecord.TransactionRecordBuilder transactionRecord = TransactionRecord.builder();
transactionRecord.subLedgerRef( toRef( entity.getSubLedgerId() ) );
transactionRecord.id( entity.getId() );
transactionRecord.ledgerType( entity.getLedgerType() );
transactionRecord.direction( entity.getDirection() );
transactionRecord.amount( moneyMapper.toMoney( entity.getAmount() ) );
return transactionRecord.build();
}
@Override
public TransactionRecordJpaEntity toEntity(TransactionRecord domain) {
if ( domain == null ) {
return null;
}
TransactionRecordJpaEntity.TransactionRecordJpaEntityBuilder transactionRecordJpaEntity = TransactionRecordJpaEntity.builder();
transactionRecordJpaEntity.subLedgerId( domainSubLedgerRefId( domain ) );
transactionRecordJpaEntity.id( domain.getId() );
transactionRecordJpaEntity.ledgerType( domain.getLedgerType() );
transactionRecordJpaEntity.direction( domain.getDirection() );
transactionRecordJpaEntity.amount( moneyMapper.toBigDecimal( domain.getAmount() ) );
return transactionRecordJpaEntity.build();
}
private UUID domainSubLedgerRefId(TransactionRecord transactionRecord) {
SubLedgerRef subLedgerRef = transactionRecord.getSubLedgerRef();
if ( subLedgerRef == null ) {
return null;
}
return subLedgerRef.id();
}
}