115 lines
3.4 KiB
Java
115 lines
3.4 KiB
Java
package eu.ztsh.wymiana;
|
|
|
|
import eu.ztsh.wymiana.data.entity.CurrencyEntity;
|
|
import eu.ztsh.wymiana.data.entity.UserEntity;
|
|
import eu.ztsh.wymiana.model.Rate;
|
|
import eu.ztsh.wymiana.model.Rates;
|
|
import eu.ztsh.wymiana.web.model.CurrencyExchangeRequest;
|
|
import eu.ztsh.wymiana.web.model.UserCreateRequest;
|
|
|
|
import java.util.ArrayList;
|
|
import java.util.List;
|
|
import java.util.Optional;
|
|
|
|
public class EntityCreator {
|
|
|
|
public static class Constants {
|
|
|
|
public static String PESEL = "00281018264";
|
|
public static String NAME = "Janina";
|
|
public static String SURNAME = "Kowalska";
|
|
public static double PLN = 20.10;
|
|
public static double USD_SELL = 5.18;
|
|
public static double USD_BUY = 5.08;
|
|
public static String PLN_SYMBOL = "PLN";
|
|
public static String USD_SYMBOL = "USD";
|
|
public static double BUY_RATE = 3.8804;
|
|
public static double SELL_RATE = 3.9572;
|
|
|
|
}
|
|
|
|
public static UserEntityBuilder user() {
|
|
return new UserEntityBuilder();
|
|
}
|
|
|
|
public static UserCreateRequest.UserCreateRequestBuilder userRequest() {
|
|
return UserCreateRequest.builder().name(Constants.NAME)
|
|
.surname(Constants.SURNAME)
|
|
.pesel(Constants.PESEL)
|
|
.pln(Constants.PLN);
|
|
}
|
|
|
|
public static CurrencyExchangeRequest.CurrencyExchangeRequestBuilder exchangeRequest() {
|
|
return CurrencyExchangeRequest.builder().pesel(Constants.PESEL);
|
|
}
|
|
|
|
public static Rates rates(String date) {
|
|
var rates = new Rates();
|
|
rates.setTable("C");
|
|
rates.setCurrency("dolar amerykański");
|
|
rates.setCode("USD");
|
|
var rate = new Rate();
|
|
rate.setNo("096/C/NBP/2024");
|
|
rate.setEffectiveDate(date);
|
|
rate.setBid(Constants.BUY_RATE);
|
|
rate.setAsk(Constants.SELL_RATE);
|
|
rates.setRates(List.of(rate));
|
|
return rates;
|
|
}
|
|
|
|
public static class UserEntityBuilder {
|
|
|
|
String name;
|
|
String surname;
|
|
String pesel;
|
|
double pln;
|
|
double usd;
|
|
|
|
public UserEntityBuilder name(String name) {
|
|
this.name = name;
|
|
return this;
|
|
}
|
|
|
|
public UserEntityBuilder surname(String surname) {
|
|
this.surname = surname;
|
|
return this;
|
|
}
|
|
|
|
public UserEntityBuilder pesel(String pesel) {
|
|
this.pesel = pesel;
|
|
return this;
|
|
}
|
|
|
|
public UserEntityBuilder pln(double pln) {
|
|
this.pln = pln;
|
|
return this;
|
|
}
|
|
|
|
public UserEntityBuilder usd(double usd) {
|
|
this.usd = usd;
|
|
return this;
|
|
}
|
|
|
|
public UserEntity build() {
|
|
var nonnulPesel = Optional.ofNullable(pesel).orElse(Constants.PESEL);
|
|
List<CurrencyEntity> currencies = new ArrayList<>();
|
|
if (pln > 0) {
|
|
currencies.add(new CurrencyEntity(nonnulPesel, "PLN", pln));
|
|
}
|
|
if (usd > 0) {
|
|
currencies.add(new CurrencyEntity(nonnulPesel, "USD", usd));
|
|
}
|
|
if (currencies.isEmpty()) {
|
|
currencies.add(new CurrencyEntity(nonnulPesel, "PLN", Constants.PLN));
|
|
}
|
|
return new UserEntity(
|
|
nonnulPesel,
|
|
Optional.ofNullable(name).orElse(Constants.NAME),
|
|
Optional.ofNullable(surname).orElse(Constants.SURNAME),
|
|
currencies
|
|
);
|
|
}
|
|
|
|
}
|
|
|
|
}
|