Skip to content

Instantly share code, notes, and snippets.

View diegolirio's full-sized avatar

Diego Lírio diegolirio

View GitHub Profile
@Entity
@Table(name = "CustomerEntity")
data class CustomerSpringDataEntity(
@Id
@GeneratedValue
var id: Long? = null,
var firstname: String? = null,
var lastname: String? = null
)
@Transactional
@Path("/customers")
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
class CustomerEntrypoint {
@Inject
private lateinit var customerSpringDataRepository: CustomerSpringDataRepository
@POST
@Transactional
@Path("/customers")
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
class CustomerEntrypoint {
@POST
fun created(customer: CustomerEntity): CustomerEntity {
customer.persist()
return customer
@Entity
data class CustomerEntity(
var firstname: String? = null,
var lastname: String? = null
) : PanacheEntity() {
}
@Path("/customers")
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
class CustomerEntrypoint {
@POST
fun created(customer: CustomerEntity): CustomerEntity {
customer.persist()
return customer
}
@Service
class InvestmentService(
private val strategy: SectorTechStrategy
) {
fun save(investment: Investment): Investment {
return strategy.get(investment.sector).saveInvestment(investment)
}
}
class SectorTechStrategy(
private val strategies : List<SectorTech>
) {
fun get(sectorEnum: Investment.SectorEnum?) : SectorTech {
return strategies.stream()
.filter { it.sector() == sectorEnum }
.findFirst()
.orElseThrow { throw IllegalArgumentException("Sector not allowed to invest") }
}
}
class FinTechSave(
private val investmentRepository: InvestmentRepository
) : SectorTech {
override fun sector() = Investment.SectorEnum.FINTECH
override fun saveInvestment(investment: Investment) : Investment {
if (investment.companyValuation >= 10000000 && investment.companyValuation <= 15000000) {
if (investment.startDate!!.isBefore(LocalDate.now().minusYears(1))) {
if (investment.value >= 500000 && investment.value <= 2000000) {
@Autowired
private lateinit var restTemplate: TestRestTemplate
@Test
fun testCreateInvestmentLogTechSectorNotAllowedToInvest() {
val investment = logTechSector()
val response = restTemplate
.postForEntity("/investments", investment, ResponseData::class.java)
assertEquals(412, response.statusCodeValue)
assertEquals("Sector not allowed to invest", response.body!!.message)
@Service
class InvestmentService(
private val investmentRepository: InvestmentRepository
) {
fun save(investment: Investment): Investment {
// FINTECH
if(investment.sector == Investment.SectorEnum.FINTECH) {
if(investment.companyValuation >= 10000000 && investment.companyValuation <= 15000000) {
if(investment.startDate!!.isBefore(LocalDate.now().minusYears(1))) {