Add sources for BAEL-468 (#4171)
* Added POJO, * Added DTO, * Added Mapper
This commit is contained in:
parent
475931974b
commit
d9ddaa8e08
|
@ -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;
|
||||
}
|
||||
}
|
|
@ -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;
|
||||
}
|
||||
}
|
|
@ -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);
|
||||
}
|
Loading…
Reference in New Issue