@@ -30,6 +30,7 @@ public class Customer extends BaseEntity<Long> { | |||||
private String brNo; | private String brNo; | ||||
@OneToOne | @OneToOne | ||||
@NotNull | |||||
@JoinColumn(name = "typeId") | @JoinColumn(name = "typeId") | ||||
private CustomerType customerType; | private CustomerType customerType; | ||||
@@ -24,12 +24,15 @@ class CustomerService(private val customerRepository: CustomerRepository, privat | |||||
fun saveCustomer(saveCustomer: SaveCustomerRequest): Customer { | fun saveCustomer(saveCustomer: SaveCustomerRequest): Customer { | ||||
val customerType = customerTypeRepository.findById(saveCustomer.typeId).orElseThrow() | |||||
val customer = | val customer = | ||||
customerRepository.saveAndFlush( | customerRepository.saveAndFlush( | ||||
Customer().apply { | Customer().apply { | ||||
id = saveCustomer.id | id = saveCustomer.id | ||||
code = saveCustomer.code | code = saveCustomer.code | ||||
name = saveCustomer.name | name = saveCustomer.name | ||||
this.customerType = customerType | |||||
address = saveCustomer.address | address = saveCustomer.address | ||||
district = saveCustomer.district | district = saveCustomer.district | ||||
brNo = saveCustomer.brNo | brNo = saveCustomer.brNo | ||||
@@ -1,12 +1,15 @@ | |||||
package com.ffii.tsms.modules.project.web.models | package com.ffii.tsms.modules.project.web.models | ||||
import jakarta.validation.constraints.NotBlank | import jakarta.validation.constraints.NotBlank | ||||
import jakarta.validation.constraints.NotNull | |||||
data class SaveCustomerRequest( | data class SaveCustomerRequest( | ||||
@field:NotBlank(message = "customer code cannot be empty") | @field:NotBlank(message = "customer code cannot be empty") | ||||
val code: String, | val code: String, | ||||
@field:NotBlank(message = "customer name cannot be empty") | @field:NotBlank(message = "customer name cannot be empty") | ||||
val name: String, | val name: String, | ||||
@field:NotNull(message = "customer name cannot be empty") | |||||
val typeId: Long, | |||||
val brNo: String?, | val brNo: String?, | ||||
val address: String?, | val address: String?, | ||||
@@ -31,21 +31,21 @@ class ProjectsService( | |||||
projectCategoryRepository.findById(request.projectCategoryId).orElseThrow() | projectCategoryRepository.findById(request.projectCategoryId).orElseThrow() | ||||
val teamLead = staffRepository.findById(request.projectLeadId).orElseThrow() | val teamLead = staffRepository.findById(request.projectLeadId).orElseThrow() | ||||
val _customer = | |||||
SaveCustomerRequest( | |||||
name = request.clientName, | |||||
code = request.clientCode, | |||||
// email = request.clientEmail, | |||||
// phone = request.clientPhone, | |||||
// contactName = request.clientContactName, | |||||
brNo = null, | |||||
address = null, | |||||
district = null, | |||||
deleteSubsidiaryIds = emptyList(), | |||||
addSubsidiaryIds = emptyList(), | |||||
id = null | |||||
) | |||||
val customer = customerService.saveCustomer(_customer) | |||||
// val _customer = | |||||
// SaveCustomerRequest( | |||||
// name = request.clientName, | |||||
// code = request.clientCode, | |||||
// // email = request.clientEmail, | |||||
// // phone = request.clientPhone, | |||||
// // contactName = request.clientContactName, | |||||
// brNo = null, | |||||
// address = null, | |||||
// district = null, | |||||
// deleteSubsidiaryIds = emptyList(), | |||||
// addSubsidiaryIds = emptyList(), | |||||
// id = null | |||||
// ) | |||||
// val customer = customerService.saveCustomer(_customer) | |||||
// TODO: Add tasks, milestones, allocated | // TODO: Add tasks, milestones, allocated | ||||
val project = | val project = | ||||
@@ -55,7 +55,7 @@ class ProjectsService( | |||||
code = request.projectCode | code = request.projectCode | ||||
this.projectCategory = projectCategory | this.projectCategory = projectCategory | ||||
this.teamLead = teamLead | this.teamLead = teamLead | ||||
this.customer = customer | |||||
// this.customer = customer | |||||
} | } | ||||
return projectRepository.save(project) | return projectRepository.save(project) | ||||