RentalEventMapperImpl.java
package com.github.jenkaby.bikerental.rental.application.mapper;
import com.github.jenkaby.bikerental.rental.domain.model.Rental;
import com.github.jenkaby.bikerental.rental.shared.mapper.RentalEquipmentMapper;
import com.github.jenkaby.bikerental.shared.domain.event.RentalCompleted;
import com.github.jenkaby.bikerental.shared.domain.event.RentalCreated;
import com.github.jenkaby.bikerental.shared.domain.event.RentalStarted;
import com.github.jenkaby.bikerental.shared.domain.event.RentalUpdated;
import com.github.jenkaby.bikerental.shared.domain.model.vo.Money;
import java.time.Instant;
import java.time.LocalDateTime;
import java.util.List;
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 RentalEventMapperImpl implements RentalEventMapper {
private final RentalEquipmentMapper rentalEquipmentMapper;
@Autowired
public RentalEventMapperImpl(RentalEquipmentMapper rentalEquipmentMapper) {
this.rentalEquipmentMapper = rentalEquipmentMapper;
}
@Override
public RentalCreated toRentalCreated(Rental rental) {
if ( rental == null ) {
return null;
}
Long rentalId = null;
String status = null;
List<Long> equipmentIds = null;
UUID customerId = null;
Instant createdAt = null;
rentalId = rental.getId();
if ( rental.getStatus() != null ) {
status = rental.getStatus().name();
}
equipmentIds = rentalEquipmentMapper.toEquipmentIds( rental.getEquipments() );
customerId = rental.getCustomerId();
createdAt = rental.getCreatedAt();
RentalCreated rentalCreated = new RentalCreated( rentalId, customerId, equipmentIds, status, createdAt );
return rentalCreated;
}
@Override
public RentalStarted toRentalStarted(Rental rental) {
if ( rental == null ) {
return null;
}
List<Long> equipmentIds = null;
Long rentalId = null;
UUID customerId = null;
LocalDateTime startedAt = null;
LocalDateTime expectedReturnAt = null;
equipmentIds = rentalEquipmentMapper.toEquipmentIds( rental.getEquipments() );
rentalId = rental.getId();
customerId = rental.getCustomerId();
startedAt = rental.getStartedAt();
expectedReturnAt = rental.getExpectedReturnAt();
RentalStarted rentalStarted = new RentalStarted( rentalId, customerId, equipmentIds, startedAt, expectedReturnAt );
return rentalStarted;
}
@Override
public RentalCompleted toRentalCompleted(Rental rental, LocalDateTime returnTime, Money totalCost) {
if ( rental == null && returnTime == null && totalCost == null ) {
return null;
}
Long rentalId = null;
List<Long> equipmentIds = null;
List<Long> returnedEquipmentIds = null;
if ( rental != null ) {
rentalId = rental.getId();
equipmentIds = rentalEquipmentMapper.toEquipmentIds( rental.getEquipments() );
returnedEquipmentIds = rentalEquipmentMapper.mapEquipmentsToIds( rental.getEquipments() );
}
LocalDateTime returnTime1 = null;
returnTime1 = returnTime;
Money totalCost1 = null;
totalCost1 = totalCost;
RentalCompleted rentalCompleted = new RentalCompleted( rentalId, equipmentIds, returnedEquipmentIds, returnTime1, totalCost1 );
return rentalCompleted;
}
@Override
public RentalUpdated toRentalUpdated(Rental rental, RentalUpdated.RentalState previous, RentalUpdated.RentalState current) {
if ( rental == null && previous == null && current == null ) {
return null;
}
Long rentalId = null;
UUID customerId = null;
if ( rental != null ) {
rentalId = rental.getId();
customerId = rental.getCustomerId();
}
RentalUpdated.RentalState previousState = null;
previousState = previous;
RentalUpdated.RentalState currentState = null;
currentState = current;
RentalUpdated rentalUpdated = new RentalUpdated( rentalId, customerId, previousState, currentState );
return rentalUpdated;
}
@Override
public RentalUpdated.RentalState toRentalState(Rental source) {
if ( source == null ) {
return null;
}
String rentalStatus = null;
List<Long> equipmentIds = null;
if ( source.getStatus() != null ) {
rentalStatus = source.getStatus().name();
}
equipmentIds = rentalEquipmentMapper.toEquipmentIds( source.getEquipments() );
RentalUpdated.RentalState rentalState = new RentalUpdated.RentalState( rentalStatus, equipmentIds );
return rentalState;
}
}