CustomerDetails.
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
private String customerName;
private String email;
private String phoneNumber;
private Long transactionId;
private Date dateOfBirth;
private String gender;
private String passport;
private Date customerActiveDate;
private Date customerDeactiveDate;
@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
// Getters and setters
public Long getCustomerId() {
return customerId;
}
public void setCustomerId(Long customerId) {
this.customerId = customerId;
}
public String getCustomerName() {
return customerName;
}
public void setCustomerName(String customerName) {
this.customerName = customerName;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
public String getPhoneNumber() {
return phoneNumber;
}
public void setPhoneNumber(String phoneNumber) {
this.phoneNumber = phoneNumber;
}
public Long getTransactionId() {
return transactionId;
}
public void setTransactionId(Long transactionId) {
this.transactionId = transactionId;
}
public Date getDateOfBirth() {
return dateOfBirth;
}
public void setDateOfBirth(Date dateOfBirth) {
this.dateOfBirth = dateOfBirth;
}
public String getGender() {
return gender;
}
public void setGender(String gender) {
this.gender = gender;
}
public String getPassport() {
return passport;
}
public void setPassport(String passport) {
this.passport = passport;
}
public Date getCustomerActiveDate() {
return customerActiveDate;
}
public void setCustomerActiveDate(Date customerActiveDate) {
this.customerActiveDate = customerActiveDate;
}
public Date getCustomerDeactiveDate() {
return customerDeactiveDate;
}
public void setCustomerDeactiveDate(Date customerDeactiveDate) {
this.customerDeactiveDate = customerDeactiveDate;
}
public CustomerAddress getAddress() {
return address;
}
public void setAddress(CustomerAddress address) {
this.address = address;
}
public ServiceProviderDetails getServiceProvider() {
return serviceProvider;
}
public void setServiceProvider(ServiceProviderDetails serviceProvider) {
this.serviceProvider = serviceProvider;
}
}
CustomerAddress.java
java
Copy code
import javax.persistence.*;
@Entity
public class CustomerAddress {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long addressId; // Primary key
private String doorNumber;
private String street;
private String landmarks;
private String village;
private String mandal;
private String city;
private String district;
private String state;
private String country;
// Getters and setters
public Long getAddressId() {
return addressId;
}
public void setAddressId(Long addressId) {
this.addressId = addressId;
}
public String getDoorNumber() {
return doorNumber;
}
public void setDoorNumber(String doorNumber) {
this.doorNumber = doorNumber;
}
public String getStreet() {
return street;
}
public void setStreet(String street) {
this.street = street;
}
public String getLandmarks() {
return landmarks;
}
public void setLandmarks(String landmarks) {
this.landmarks = landmarks;
}
public String getVillage() {
return village;
}
public void setVillage(String village) {
this.village = village;
}
public String getMandal() {
return mandal;
}
public void setMandal(String mandal) {
this.mandal = mandal;
}
public String getCity() {
return city;
}
public void setCity(String city) {
this.city = city;
}
public String getDistrict() {
return district;
}
public void setDistrict(String district) {
this.district = district;
}
public String getState() {
return state;
}
public void setState(String state) {
this.state = state;
}
public String getCountry() {
return country;
}
public void setCountry(String country) {
this.country = country;
}
}
ServiceProviderDetails.java
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
private String providerName;
private String providerAddress;
private String providerContact;
private String providerType;
private String website;
private String servicesOffered;
private Date establishedDate;
private double rating;
@OneToMany(mappedBy = "serviceProvider")
private List<CustomerDetails> customers; // One-to-many relationship with
CustomerDetails
// Getters and setters
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public Long getSpid() {
return spid;
}
public void setSpid(Long spid) {
this.spid = spid;
}
public String getProviderName() {
return providerName;
}
public void setProviderName(String providerName) {
this.providerName = providerName;
}
public String getProviderAddress() {
return providerAddress;
}
public void setProviderAddress(String providerAddress) {
this.providerAddress = providerAddress;
}
public String getProviderContact() {
return providerContact;
}
public void setProviderContact(String providerContact) {
this.providerContact = providerContact;
}
public String getProviderType() {
return providerType;
}
public void setProviderType(String providerType) {
this.providerType = providerType;
}
public String getWebsite() {
return website;
}
public void setWebsite(String website) {
this.website = website;
}
public String getServicesOffered() {
return servicesOffered;
}
public void setServicesOffered(String servicesOffered) {
this.servicesOffered = servicesOffered;
}
public Date getEstablishedDate() {
return establishedDate;
}
public void setEstablishedDate(Date establishedDate) {
this.establishedDate = establishedDate;
}
public double getRating() {
return rating;
}
public void setRating(double rating) {
this.rating = rating;
}
public List<CustomerDetails> getCustomers() {
return customers;
}
public void setCustomers(List<CustomerDetails> customers) {
this.customers = customers;
}
}
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;
@Repository
public interface CustomerDetailsDAO extends JpaRepository<CustomerDetails, Long> {
}
@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": "johndoe@example.com",
"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
}
}