This file contains hidden or 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
| @Entity | |
| @Table(name = "CustomerEntity") | |
| data class CustomerSpringDataEntity( | |
| @Id | |
| @GeneratedValue | |
| var id: Long? = null, | |
| var firstname: String? = null, | |
| var lastname: String? = null | |
| ) |
This file contains hidden or 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
| @Transactional | |
| @Path("/customers") | |
| @Produces(MediaType.APPLICATION_JSON) | |
| @Consumes(MediaType.APPLICATION_JSON) | |
| class CustomerEntrypoint { | |
| @Inject | |
| private lateinit var customerSpringDataRepository: CustomerSpringDataRepository | |
| @POST |
This file contains hidden or 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
| @Transactional | |
| @Path("/customers") | |
| @Produces(MediaType.APPLICATION_JSON) | |
| @Consumes(MediaType.APPLICATION_JSON) | |
| class CustomerEntrypoint { | |
| @POST | |
| fun created(customer: CustomerEntity): CustomerEntity { | |
| customer.persist() | |
| return customer |
This file contains hidden or 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
| @Entity | |
| data class CustomerEntity( | |
| var firstname: String? = null, | |
| var lastname: String? = null | |
| ) : PanacheEntity() { | |
| } |
This file contains hidden or 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
| @Path("/customers") | |
| @Produces(MediaType.APPLICATION_JSON) | |
| @Consumes(MediaType.APPLICATION_JSON) | |
| class CustomerEntrypoint { | |
| @POST | |
| fun created(customer: CustomerEntity): CustomerEntity { | |
| customer.persist() | |
| return customer | |
| } |
This file contains hidden or 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
| @Service | |
| class InvestmentService( | |
| private val strategy: SectorTechStrategy | |
| ) { | |
| fun save(investment: Investment): Investment { | |
| return strategy.get(investment.sector).saveInvestment(investment) | |
| } | |
| } |
This file contains hidden or 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
| 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") } | |
| } | |
| } |
This file contains hidden or 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
| 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) { |
This file contains hidden or 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
| @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) |
This file contains hidden or 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
| @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))) { |