Add sources for BAEL-468 (#4171)

* Added POJO,
* Added DTO,
* Added Mapper
This commit is contained in:
xenteros 2018-05-10 17:32:20 +03:00 committed by Grzegorz Piwowarek
parent 475931974b
commit d9ddaa8e08
3 changed files with 69 additions and 0 deletions

View File

@ -0,0 +1,23 @@
package com.baeldung.dto;
public class TransactionDTO {
private String uuid;
private Long totalInCents;
public String getUuid() {
return uuid;
}
public void setUuid(String uuid) {
this.uuid = uuid;
}
public Long getTotalInCents() {
return totalInCents;
}
public void setTotalInCents(Long totalInCents) {
this.totalInCents = totalInCents;
}
}

View File

@ -0,0 +1,23 @@
package com.baeldung.entity;
import java.math.BigDecimal;
import java.util.UUID;
public class Transaction {
private Long id;
private String uuid = UUID.randomUUID().toString();
private BigDecimal total;
public Long getId() {
return id;
}
public String getUuid() {
return uuid;
}
public BigDecimal getTotal() {
return total;
}
}

View File

@ -0,0 +1,23 @@
package com.baeldung.mapper;
import java.math.BigDecimal;
import java.util.Collection;
import java.util.List;
import org.mapstruct.Mapper;
import com.baeldung.dto.TransactionDTO;
import com.baeldung.entity.Transaction;
@Mapper
abstract class TransactionMapper {
public TransactionDTO toTransactionDTO(Transaction transaction) {
TransactionDTO transactionDTO = new TransactionDTO();
transactionDTO.setUuid(transaction.getUuid());
transactionDTO.setTotalInCents(transaction.getTotal().multiply(new BigDecimal("100")).longValue());
return transactionDTO;
}
public abstract List<TransactionDTO> toTransactionDTO(Collection<Transaction> transactions);
}