WithdrawalCommandMapperImpl.java

package com.github.jenkaby.bikerental.finance.web.command.mapper;

import com.github.jenkaby.bikerental.finance.PaymentMethod;
import com.github.jenkaby.bikerental.finance.application.usecase.RecordWithdrawalUseCase;
import com.github.jenkaby.bikerental.finance.web.command.dto.RecordWithdrawalRequest;
import com.github.jenkaby.bikerental.finance.web.command.dto.TransactionResponse;
import com.github.jenkaby.bikerental.shared.domain.IdempotencyKey;
import com.github.jenkaby.bikerental.shared.domain.model.vo.Money;
import com.github.jenkaby.bikerental.shared.mapper.IdempotencyKeyMapper;
import com.github.jenkaby.bikerental.shared.mapper.MoneyMapper;
import java.time.Instant;
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 WithdrawalCommandMapperImpl implements WithdrawalCommandMapper {

    private final MoneyMapper moneyMapper;
    private final IdempotencyKeyMapper idempotencyKeyMapper;

    @Autowired
    public WithdrawalCommandMapperImpl(MoneyMapper moneyMapper, IdempotencyKeyMapper idempotencyKeyMapper) {

        this.moneyMapper = moneyMapper;
        this.idempotencyKeyMapper = idempotencyKeyMapper;
    }

    @Override
    public RecordWithdrawalUseCase.RecordWithdrawalCommand toCommand(RecordWithdrawalRequest request) {
        if ( request == null ) {
            return null;
        }

        UUID customerId = null;
        Money amount = null;
        PaymentMethod paymentMethod = null;
        String operatorId = null;
        IdempotencyKey idempotencyKey = null;

        customerId = request.customerId();
        amount = moneyMapper.toMoney( request.amount() );
        paymentMethod = request.paymentMethod();
        operatorId = request.operatorId();
        idempotencyKey = idempotencyKeyMapper.toIdempotencyKey( request.idempotencyKey() );

        RecordWithdrawalUseCase.RecordWithdrawalCommand recordWithdrawalCommand = new RecordWithdrawalUseCase.RecordWithdrawalCommand( customerId, amount, paymentMethod, operatorId, idempotencyKey );

        return recordWithdrawalCommand;
    }

    @Override
    public TransactionResponse toResponse(RecordWithdrawalUseCase.WithdrawalResult result) {
        if ( result == null ) {
            return null;
        }

        UUID transactionId = null;
        Instant recordedAt = null;

        transactionId = result.transactionId();
        recordedAt = result.recordedAt();

        TransactionResponse transactionResponse = new TransactionResponse( transactionId, recordedAt );

        return transactionResponse;
    }
}