AdjustmentCommandMapperImpl.java

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

import com.github.jenkaby.bikerental.finance.application.usecase.ApplyAdjustmentUseCase;
import com.github.jenkaby.bikerental.finance.web.command.dto.AdjustmentRequest;
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.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 AdjustmentCommandMapperImpl implements AdjustmentCommandMapper {

    private final MoneyMapper moneyMapper;

    @Autowired
    public AdjustmentCommandMapperImpl(MoneyMapper moneyMapper) {

        this.moneyMapper = moneyMapper;
    }

    @Override
    public ApplyAdjustmentUseCase.ApplyAdjustmentCommand toCommand(AdjustmentRequest request) {
        if ( request == null ) {
            return null;
        }

        UUID customerId = null;
        Money amount = null;
        String reason = null;
        String operatorId = null;

        customerId = request.customerId();
        amount = moneyMapper.toMoney( request.amount() );
        reason = request.reason();
        operatorId = request.operatorId();

        IdempotencyKey idempotencyKey = IdempotencyKey.of(request.idempotencyKey());

        ApplyAdjustmentUseCase.ApplyAdjustmentCommand applyAdjustmentCommand = new ApplyAdjustmentUseCase.ApplyAdjustmentCommand( customerId, amount, reason, operatorId, idempotencyKey );

        return applyAdjustmentCommand;
    }

    @Override
    public TransactionResponse toResponse(ApplyAdjustmentUseCase.AdjustmentResult 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;
    }
}