Varizon
Varizon
java
java
Copy code
import javax.persistence.*;
import java.util.Date;
@Entity
public class CustomerDetails {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long customerId; // Primary key
@OneToOne(cascade = CascadeType.ALL)
@JoinColumn(name = "address_id", referencedColumnName = "addressId")
private CustomerAddress address; // One-to-one relationship with
CustomerAddress
@ManyToOne
@JoinColumn(name = "spid", referencedColumnName = "spid")
private ServiceProviderDetails serviceProvider; // Many-to-one relationship
with ServiceProviderDetails
java
Copy code
import javax.persistence.*;
@Entity
public class CustomerAddress {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long addressId; // Primary key
java
Copy code
import javax.persistence.*;
import java.util.Date;
import java.util.List;
@Entity
public class ServiceProviderDetails {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id; // New primary key
@Column(unique = true)
private Long spid; // Unique field for service provider ID
@OneToMany(mappedBy = "serviceProvider")
private List<CustomerDetails> customers; // One-to-many relationship with
CustomerDetails
@Repository
public interface CustomerAddressDAO extends JpaRepository<CustomerAddress, Long> {
}
@Repository
public interface ServiceProviderDetailsDAO extends
JpaRepository<ServiceProviderDetails, Long> {
}
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
@Service
public class CustomerDetailsService {
@Autowired
private CustomerDetailsDAO customerDetailsDAO;
@Transactional
public CustomerDetails saveCustomerDetails(CustomerDetails customerDetails) {
return customerDetailsDAO.save(customerDetails);
}
}
@Service
public class CustomerAddressService {
@Autowired
private CustomerAddressDAO customerAddressDAO;
@Transactional
public CustomerAddress saveCustomerAddress(CustomerAddress customerAddress) {
return customerAddressDAO.save(customerAddress);
}
}
@Service
public class ServiceProviderDetailsService {
@Autowired
private ServiceProviderDetailsDAO serviceProviderDetailsDAO;
@Transactional
public ServiceProviderDetails saveServiceProviderDetails(ServiceProviderDetails
serviceProviderDetails) {
return serviceProviderDetailsDAO.save(serviceProviderDetails);
}
}
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
@RestController
@RequestMapping("/api/customers")
public class CustomerController {
@Autowired
private CustomerDetailsService customerDetailsService;
@Autowired
private CustomerAddressService customerAddressService;
@Autowired
private ServiceProviderDetailsService serviceProviderDetailsService;
@PostMapping("/details")
public ResponseEntity<CustomerDetails> saveCustomerDetails(@RequestBody
CustomerDetails customerDetails) {
CustomerDetails savedCustomerDetails =
customerDetailsService.saveCustomerDetails(customerDetails);
return ResponseEntity.ok(savedCustomerDetails);
}
@PostMapping("/address")
public ResponseEntity<CustomerAddress> saveCustomerAddress(@RequestBody
CustomerAddress customerAddress) {
CustomerAddress savedCustomerAddress =
customerAddressService.saveCustomerAddress(customerAddress);
return ResponseEntity.ok(savedCustomerAddress);
}
@PostMapping("/service-provider")
public ResponseEntity<ServiceProviderDetails>
saveServiceProviderDetails(@RequestBody ServiceProviderDetails
serviceProviderDetails) {
ServiceProviderDetails savedServiceProviderDetails =
serviceProviderDetailsService.saveServiceProviderDetails(serviceProviderDetails);
return ResponseEntity.ok(savedServiceProviderDetails);
}
}
{
"customerName": "John Doe",
"email": "[email protected]",
"phoneNumber": "1234567890",
"transactionId": 1001,
"dateOfBirth": "1980-01-01T00:00:00.000+00:00",
"gender": "Male",
"passport": "A1234567",
"customerActiveDate": "2020-01-01T00:00:00.000+00:00",
"customerDeactiveDate": "2024-01-01T00:00:00.000+00:00",
"address": {
"doorNumber": "123",
"street": "Main St",
"landmarks": "Near Park",
"village": "Springfield",
"mandal": "Central",
"city": "Metropolis",
"district": "North",
"state": "NY",
"country": "USA"
},
"serviceProvider": {
"spid": 2001,
"providerName": "XYZ Telecom",
"providerAddress": "456 Central St",
"providerContact": "0987654321",
"providerType": "Telecom",
"website": "www.xyztelecom.com",
"servicesOffered": "Internet, TV",
"establishedDate": "2000-01-01T00:00:00.000+00:00",
"rating": 4.5
}
}