-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #10 from diegosneves/feat/notification
refactor(Envio de email) 🎨 Remover o código da estratégia de pagamento e melhorar a lógica de negócios
- Loading branch information
Showing
23 changed files
with
337 additions
and
363 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 12 additions & 6 deletions
18
src/main/java/diegosneves/github/rachapedido/core/CashDiscountStrategy.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,26 @@ | ||
package diegosneves.github.rachapedido.core; | ||
|
||
import diegosneves.github.rachapedido.dto.InvoiceDTO; | ||
import diegosneves.github.rachapedido.enums.DiscountType; | ||
import diegosneves.github.rachapedido.mapper.BuilderMapper; | ||
import diegosneves.github.rachapedido.mapper.InvoiceFromPersonMapper; | ||
import diegosneves.github.rachapedido.model.Invoice; | ||
import diegosneves.github.rachapedido.model.Item; | ||
import diegosneves.github.rachapedido.model.Person; | ||
import diegosneves.github.rachapedido.utils.RoundUtil; | ||
|
||
public class CashDiscountStrategy extends DiscountStrategy { | ||
|
||
@Override | ||
public Invoice calculateDiscount(InvoiceDTO dto, Double discountAmount, DiscountType type, Double total, Double deliveryFee) { | ||
public Invoice calculateDiscount(Person person, Double discountAmount, DiscountType type, Double total, Double deliveryFee) { | ||
if(DiscountType.CASH.name().equals(type.name())) { | ||
dto.setPercentageConsumedTotalBill(dto.getValueConsumed() / total); | ||
dto.setTotalPayable(RoundUtil.round(((total - type.discountAmount(discountAmount) + deliveryFee) * dto.getPercentageConsumedTotalBill()))); | ||
return BuilderMapper.builderMapper(Invoice.class, dto); | ||
InvoiceFromPersonMapper mapper = new InvoiceFromPersonMapper(); | ||
Double consumption = person.getItems().stream().mapToDouble(Item::getPrice).sum(); | ||
Double percentageConsumedTotalBill = consumption / total; | ||
Invoice newInvoice = BuilderMapper.builderMapper(Invoice.class, person, mapper); | ||
newInvoice.setPercentageConsumedTotalBill(percentageConsumedTotalBill); | ||
newInvoice.setTotalPayable(RoundUtil.round(((total - type.discountAmount(discountAmount) + deliveryFee) * percentageConsumedTotalBill))); | ||
return newInvoice; | ||
} | ||
return this.checkNext(dto, discountAmount, type, total, deliveryFee); | ||
return this.checkNext(person, discountAmount, type, total, deliveryFee); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 12 additions & 6 deletions
18
src/main/java/diegosneves/github/rachapedido/core/NoDiscountStrategy.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,26 @@ | ||
package diegosneves.github.rachapedido.core; | ||
|
||
import diegosneves.github.rachapedido.dto.InvoiceDTO; | ||
import diegosneves.github.rachapedido.enums.DiscountType; | ||
import diegosneves.github.rachapedido.mapper.BuilderMapper; | ||
import diegosneves.github.rachapedido.mapper.InvoiceFromPersonMapper; | ||
import diegosneves.github.rachapedido.model.Invoice; | ||
import diegosneves.github.rachapedido.model.Item; | ||
import diegosneves.github.rachapedido.model.Person; | ||
import diegosneves.github.rachapedido.utils.RoundUtil; | ||
|
||
public class NoDiscountStrategy extends DiscountStrategy { | ||
|
||
@Override | ||
public Invoice calculateDiscount(InvoiceDTO dto, Double discountAmount, DiscountType type, Double total, Double deliveryFee) { | ||
public Invoice calculateDiscount(Person person, Double discountAmount, DiscountType type, Double total, Double deliveryFee) { | ||
if (DiscountType.NO_DISCOUNT.name().equals(type.name())) { | ||
dto.setPercentageConsumedTotalBill(dto.getValueConsumed() / total); | ||
dto.setTotalPayable(RoundUtil.round((total - type.discountAmount(discountAmount) + deliveryFee) * dto.getPercentageConsumedTotalBill())); | ||
return BuilderMapper.builderMapper(Invoice.class, dto); | ||
Double consumption = person.getItems().stream().mapToDouble(Item::getPrice).sum(); | ||
Double percentageConsumedTotalBill = consumption / total; | ||
InvoiceFromPersonMapper mapper = new InvoiceFromPersonMapper(); | ||
Invoice newInvoice = BuilderMapper.builderMapper(Invoice.class, person, mapper); | ||
newInvoice.setPercentageConsumedTotalBill(percentageConsumedTotalBill); | ||
newInvoice.setTotalPayable(RoundUtil.round((total - type.discountAmount(discountAmount) + deliveryFee) * percentageConsumedTotalBill)); | ||
return newInvoice; | ||
} | ||
return this.checkNext(dto, discountAmount, type, total, deliveryFee); | ||
return this.checkNext(person, discountAmount, type, total, deliveryFee); | ||
} | ||
} |
18 changes: 12 additions & 6 deletions
18
src/main/java/diegosneves/github/rachapedido/core/PercentageDiscountStrategy.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,27 @@ | ||
package diegosneves.github.rachapedido.core; | ||
|
||
import diegosneves.github.rachapedido.dto.InvoiceDTO; | ||
import diegosneves.github.rachapedido.enums.DiscountType; | ||
import diegosneves.github.rachapedido.mapper.BuilderMapper; | ||
import diegosneves.github.rachapedido.mapper.InvoiceFromPersonMapper; | ||
import diegosneves.github.rachapedido.model.Invoice; | ||
import diegosneves.github.rachapedido.model.Item; | ||
import diegosneves.github.rachapedido.model.Person; | ||
import diegosneves.github.rachapedido.utils.RoundUtil; | ||
|
||
public class PercentageDiscountStrategy extends DiscountStrategy { | ||
|
||
@Override | ||
public Invoice calculateDiscount(InvoiceDTO dto, Double discountAmount, DiscountType type, Double total, Double deliveryFee) { | ||
public Invoice calculateDiscount(Person person, Double discountAmount, DiscountType type, Double total, Double deliveryFee) { | ||
if (DiscountType.PERCENTAGE.name().equals(type.name())) { | ||
dto.setPercentageConsumedTotalBill(dto.getValueConsumed() / total); | ||
dto.setTotalPayable(RoundUtil.round((total - (total * type.discountAmount(discountAmount)) + deliveryFee) * dto.getPercentageConsumedTotalBill())); | ||
return BuilderMapper.builderMapper(Invoice.class, dto); | ||
Double consumption = person.getItems().stream().mapToDouble(Item::getPrice).sum(); | ||
InvoiceFromPersonMapper mapper = new InvoiceFromPersonMapper(); | ||
Double percentageConsumedTotalBill = consumption / total; | ||
Invoice newInvoice = BuilderMapper.builderMapper(Invoice.class, person, mapper); | ||
newInvoice.setPercentageConsumedTotalBill(percentageConsumedTotalBill); | ||
newInvoice.setTotalPayable(RoundUtil.round((total - (total * type.discountAmount(discountAmount)) + deliveryFee) * percentageConsumedTotalBill)); | ||
return newInvoice; | ||
} | ||
return this.checkNext(dto, discountAmount, type, total, deliveryFee); | ||
return this.checkNext(person, discountAmount, type, total, deliveryFee); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 0 additions & 33 deletions
33
src/main/java/diegosneves/github/rachapedido/exceptions/CloseOrderException.java
This file was deleted.
Oops, something went wrong.
17 changes: 17 additions & 0 deletions
17
src/main/java/diegosneves/github/rachapedido/mapper/InvoiceFromPersonMapper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package diegosneves.github.rachapedido.mapper; | ||
|
||
import diegosneves.github.rachapedido.model.Invoice; | ||
import diegosneves.github.rachapedido.model.Person; | ||
|
||
public class InvoiceFromPersonMapper implements BuildingStrategy<Invoice, Person> { | ||
|
||
@Override | ||
public Invoice run(Person origem) { | ||
return Invoice.builder() | ||
.consumerName(origem.getPersonName()) | ||
.email(origem.getEmail()) | ||
.isBuyer(origem.getIsBuyer()) | ||
.items(origem.getItems()) | ||
.build(); | ||
} | ||
} |
9 changes: 5 additions & 4 deletions
9
src/main/java/diegosneves/github/rachapedido/mapper/NotificationEmailMapper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.