Skip to content

Commit

Permalink
Merge pull request #425 from vinho-notas/VIN-494-Migrar-o-dominio
Browse files Browse the repository at this point in the history
VIN-494 - Migrando o dominio
  • Loading branch information
vanderleik authored Sep 21, 2024
2 parents 29a7325 + 22977e5 commit 2947354
Show file tree
Hide file tree
Showing 28 changed files with 672 additions and 84 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
package com.vinhonotas.vinho.domain.entities.wine;

import java.math.BigDecimal;
import java.time.LocalDate;

/**
* Represents the purchase information of a wine.
*/
public class PurchaseInfo {

private final BigDecimal price;
private final String purchaseLocation;
private final LocalDate purchaseDate;

public PurchaseInfo(BigDecimal price, String purchaseLocation, LocalDate purchaseDate) {
this.price = price;
this.purchaseLocation = purchaseLocation;
this.purchaseDate = purchaseDate;
}

public static PurchaseInfoBuilder builder() {
return new PurchaseInfoBuilder();
}

public BigDecimal getPrice() {
return price;
}

public String getPurchaseLocation() {
return purchaseLocation;
}

public LocalDate getPurchaseDate() {
return purchaseDate;
}

@Override
public String toString() {
return "PurchaseInfo{" +
"price=" + price +
", purchaseLocation='" + purchaseLocation + '\'' +
", purchaseDate=" + purchaseDate +
'}';
}

public static class PurchaseInfoBuilder {
private BigDecimal price;
private String purchaseLocation;
private LocalDate purchaseDate;

public PurchaseInfoBuilder price(BigDecimal price) {
this.price = price;
return this;
}

public PurchaseInfoBuilder purchaseLocation(String purchaseLocation) {
this.purchaseLocation = purchaseLocation;
return this;
}

public PurchaseInfoBuilder purchaseDate(LocalDate purchaseDate) {
this.purchaseDate = purchaseDate;
return this;
}

public PurchaseInfo build() {
return new PurchaseInfo(price, purchaseLocation, purchaseDate);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
package com.vinhonotas.vinho.domain.entities.wine;

import com.vinhonotas.vinho.v1.domain.enums.EnumWineClassification;
import com.vinhonotas.vinho.v1.domain.enums.EnumWineType;

/**
* Represents the details of a wine.
*/
public class WineDetails {

private final EnumWineType wineType;
private final EnumWineClassification wineClassification;
private final String alcoholContent;
private final int volumeMl;
private final String grape;
private final String winery;
private final String serviceTemperature;

public WineDetails(EnumWineType wineType, EnumWineClassification wineClassification, String alcoholContent,
int volumeMl, String grape, String winery, String serviceTemperature) {
this.wineType = wineType;
this.wineClassification = wineClassification;
this.alcoholContent = alcoholContent;
this.volumeMl = volumeMl;
this.grape = grape;
this.winery = winery;
this.serviceTemperature = serviceTemperature;
}

public static WineDetailsBuilder builder() {
return new WineDetailsBuilder();
}

public EnumWineType getWineType() {
return wineType;
}

public EnumWineClassification getWineClassification() {
return wineClassification;
}

public String getAlcoholContent() {
return alcoholContent;
}

public int getVolumeMl() {
return volumeMl;
}

public String getGrape() {
return grape;
}

public String getWinery() {
return winery;
}

public String getServiceTemperature() {
return serviceTemperature;
}

@Override
public String toString() {
return "WineDetails{" +
"wineType=" + wineType +
", wineClassification=" + wineClassification +
", alcoholContent='" + alcoholContent + '\'' +
", volumeMl=" + volumeMl +
", grape='" + grape + '\'' +
", winery='" + winery + '\'' +
", serviceTemperature='" + serviceTemperature + '\'' +
'}';
}

public static class WineDetailsBuilder{
private EnumWineType wineType;
private EnumWineClassification wineClassification;
private String alcoholContent;
private int volumeMl;
private String grape;
private String winery;
private String serviceTemperature;

WineDetailsBuilder() {
}

public WineDetailsBuilder wineType(EnumWineType wineType) {
this.wineType = wineType;
return this;
}

public WineDetailsBuilder wineClassification(EnumWineClassification wineClassification) {
this.wineClassification = wineClassification;
return this;
}

public WineDetailsBuilder alcoholContent(String alcoholContent) {
this.alcoholContent = alcoholContent;
return this;
}

public WineDetailsBuilder volumeMl(int volumeMl) {
this.volumeMl = volumeMl;
return this;
}

public WineDetailsBuilder grape(String grape) {
this.grape = grape;
return this;
}

public WineDetailsBuilder winery(String winery) {
this.winery = winery;
return this;
}

public WineDetailsBuilder serviceTemperature(String serviceTemperature) {
this.serviceTemperature = serviceTemperature;
return this;
}

public WineDetails build() {
return new WineDetails(wineType, wineClassification, alcoholContent, volumeMl, grape, winery, serviceTemperature);
}

}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
package com.vinhonotas.vinho.domain.entities.wine;

import com.vinhonotas.vinho.v1.domain.enums.EnumWineClassification;
import com.vinhonotas.vinho.v1.domain.enums.EnumWineType;

public class WineDomain {

private final String sku;
private final String name;
private final WineDetails wineDetails;
private final PurchaseInfo purchaseInfo;
private final WineOrigin wineOrigin;

public WineDomain(final String sku, final String name, final WineDetails wineDetails, final PurchaseInfo purchaseInfo,
final WineOrigin wineOrigin) {
this.sku = sku;
this.name = name;
this.wineDetails = wineDetails;
this.purchaseInfo = purchaseInfo;
this.wineOrigin = wineOrigin;
}

public static WineDomainBuilder builder() {
return new WineDomainBuilder();
}

public String getSku() {
return sku;
}

public String getName() {
return name;
}

public WineDetails getWineDetails() {
return wineDetails;
}

public PurchaseInfo getPurchaseInfo() {
return purchaseInfo;
}

public WineOrigin getWineOrigin() {
return wineOrigin;
}

@Override
public String toString() {
return "WineDomain{" +
"sku='" + sku + '\'' +
", name='" + name + '\'' +
", wineDetails=" + wineDetails +
", purchaseInfo=" + purchaseInfo +
", wineOrigin=" + wineOrigin +
'}';
}

public static class WineDomainBuilder {
private String sku;
private String name;
private WineDetails wineDetails;
private PurchaseInfo purchaseInfo;
private WineOrigin wineOrigin;

WineDomainBuilder() {
}

/**
* Construtor do SKU - Stock Keeping Unit, ou Unidade de Manutenção de Estoque. É um código exclusivo atribuído ao vinho
* para facilitar a sua identificação e gestão de estoque. Cada SKU é específico para um vinho e pode diferenciar produtos
* com base em:
* - 2 primeiras letras do name
* - 2 primeiras letras do EnumWineType
* - 2 primeiras letras do EnumWineClassification
* - harvest
* - 2 primeiras letras do country.
* @param name: nome do vinho
* @param wineType: tipo do vinho
* @param wineClassification: classificação do vinho
* @param harvest: safra do vinho
* @param country: país de origem do vinho
* @return String sku: código SKU gerado
*/
private String generateSku(String name, EnumWineType wineType, EnumWineClassification wineClassification, String harvest, String country) {
return name.substring(0, 2) + wineType.name().substring(0, 2) + wineClassification.name().substring(0, 2) + harvest + country.substring(0, 2);
}

public WineDomainBuilder sku(String name, EnumWineType wineType, EnumWineClassification wineClassification, String harvest, String country) {
this.sku = generateSku(name, wineType, wineClassification, harvest, country);
return this;
}

public WineDomainBuilder name(String name) {
this.name = name;
return this;
}

public WineDomainBuilder wineDetails(WineDetails wineDetails) {
this.wineDetails = wineDetails;
return this;
}

public WineDomainBuilder purchaseInfo(PurchaseInfo purchaseInfo) {
this.purchaseInfo = purchaseInfo;
return this;
}

public WineDomainBuilder wineOrigin(WineOrigin wineOrigin) {
this.wineOrigin = wineOrigin;
return this;
}

public WineDomain build() {
if (this.sku == null) {
this.sku = generateSku(this.name, this.wineDetails.getWineType(), this.wineDetails.getWineClassification(),
this.wineOrigin.getHarvest(), this.wineOrigin.getCountry());
}

return new WineDomain(this.sku, this.name, this.wineDetails, this.purchaseInfo, this.wineOrigin);
}

}

}
Loading

0 comments on commit 2947354

Please sign in to comment.