0% found this document useful (0 votes)
16 views15 pages

Customer Details Submission API

no

Uploaded by

shekhar.dev1998
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
16 views15 pages

Customer Details Submission API

no

Uploaded by

shekhar.dev1998
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd

package [Link].

controller;

import [Link];
import [Link];

import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];

import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
//Indicating that this class is a REST controller
@RestController
//URL mapping for this controller
@RequestMapping("/cust")
public class CustomerControl {
// Annotation for automatic dependency injection
// Dependency injection for CustomerAddressMapper
private CustomerAddressMapper customerAddressMapper;
@Autowired
private CustomerDetailsService customerDetailsService; // Dependency
injection for CustomerDetailsService
@Autowired
private CustomerDetailsMapper customerDetailsMapper;// Dependency injection
for CustomerDetailsMapper
// Endpoint for saving customer details
@Autowired
private ServiceProviderDetailsMapper serviceProviderDetailsMapper;

CustomerControl(CustomerAddressMapper customerAddressMapper) {
[Link] = customerAddressMapper;
}
// Endpoint for saving customer details
@PostMapping("/costomerdetails") // Annotation to handle HTTP POST requests
public CustomerDetailsResponse SaveCustomerDetails(@RequestBody
CustomerDetailsRequest customerDetailsRequest) {
CustomerDetailsResponse customerDetailsResponse = new
CustomerDetailsResponse(); // Initialize the response object
List<String> messages = new ArrayList();// Initialize the list to hold
validation messages
try
{
// Validate phone number
// Check if phone number is null
if([Link]()==null)
{
[Link]("Phone Number Must Not null");
}
// Check if phone number is exactly 10 digits
if ([Link]().length()<10 ||
[Link]().length()>10 )
{
[Link]("Phone Number must be 10 digits");
}

// Validate PassPort
//Passport Must Not null
if ([Link]() ==null) {
[Link](" Must Provide New service provider and
cannot be null.");

List<CustomerAddressRequest> addressRequests =
[Link]();
if (addressRequests != null) {
for (CustomerAddressRequest addressRequest :
addressRequests) {
// Check each property of addressRequest for null or
empty values and add appropriate messages
if ([Link]() == null ||
[Link]().isEmpty())
{
[Link]("Mandal must not be null or
empty");
}

if ([Link]() == null ||
[Link]().isEmpty())
{
[Link]("Mandal must not be null or
empty");
}
if ([Link]() == null ||
[Link]().isEmpty())
{
[Link]("Mandal must not be null or
empty");
}
if ([Link]() == null ||
[Link]().isEmpty())
{
[Link]("Mandal must not be null or
empty");
}
if ([Link]() == null &&
[Link]().isEmpty())
{
[Link]("Mandal must not be null or
empty");

}
}
}
// Validate ServiceProviderDetails
List<ServiceProviderDetailsRequest> serviceProviderRequests =
[Link]();
if (serviceProviderRequests != null) {
for (ServiceProviderDetailsRequest serviceProviderRequest :
serviceProviderRequests) {
// Loop through each service provider request
// Check each property of serviceProviderRequest for null or
empty values and add appropriate messages
if ([Link]() == null
|| [Link]().isEmpty()) {
[Link]("Provider Name must not be null or
empty");
}
if ([Link]() ==
null || [Link]().isEmpty()) {
[Link]("Provider Address must not be null
or empty");
}
if ([Link]() ==
null || [Link]().isEmpty()) {
[Link]("Provider Contact must not be null
or empty");
}
if ([Link]() == null
|| [Link]().isEmpty()) {
[Link]("Provider Type must not be null or
empty");
}
// Add additional validations for other properties
}
}
else {
[Link]("Service Provider Details Request list must
not be null");
}

// If no validation errors, proceed with mapping and saving the


customer details
if ([Link]())
{

CustomerDetails customerDetails =
[Link](customerDetailsRequest);// Map the request
to entity

[Link](customerDetails);// Save the


customer details using the service

}
catch(Exception e)
{
[Link]("An error occurred: " + [Link]()); // Catch
and add any exceptions to messages
}
finally
{
[Link](messages);// Set the messages
in the response object
}

return customerDetailsResponse;// Return the response object


}

ackage [Link];

public class CustomerAddressRequest {


private Long addressId;
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) {


[Link] = addressId;
}

public String getDoorNumber() {


return doorNumber;
}

public void setDoorNumber(String doorNumber) {


[Link] = doorNumber;
}

public String getStreet() {


return street;
}

public void setStreet(String street) {


[Link] = street;
}

public String getLandmarks() {


return landmarks;
}

public void setLandmarks(String landmarks) {


[Link] = landmarks;
}
public String getVillage() {
return village;
}

public void setVillage(String village) {


[Link] = village;
}

public String getMandal() {


return mandal;
}

public void setMandal(String mandal) {


[Link] = mandal;
}

public String getCity() {


return city;
}

public void setCity(String city) {


[Link] = city;
}

public String getDistrict() {


return district;
}

public void setDistrict(String district) {


[Link] = district;
}

public String getState() {


return state;
}

public void setState(String state) {


[Link] = state;
}

public String getCountry() {


return country;
}

public void setCountry(String country) {


[Link] = country;
}
}

}
package [Link];

import [Link];

public class CustomerAddressResponse {


private String village;
private String mandal;
private String city;
private String district;
private String state;
private String country;
private List<String> messages;
public List<String> getMessages() {
return messages;
}
public void setMessages(List<String> messages) {
[Link] = messages;
}
public String getVillage() {
return village;
}
public void setVillage(String village) {
[Link] = village;
}
public String getMandal() {
return mandal;
}
public void setMandal(String mandal) {
[Link] = mandal;
}
public String getCity() {
return city;
}
public void setCity(String city) {
[Link] = city;
}
public String getDistrict() {
return district;
}
public void setDistrict(String district) {
[Link] = district;
}
public String getState() {
return state;
}
public void setState(String state) {
[Link] = state;
}
public String getCountry() {
return country;
}
public void setCountry(String country) {
[Link] = country;
}

}
package [Link];

import [Link];
import [Link];

public class CustomerDetailsRequest {

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;
private List<CustomerAddressRequest> customerAddressRequest;
private List<ServiceProviderDetailsRequest> serviceProviderDetailsRequest;
public String getCustomerName() {
return customerName;
}
public void setCustomerName(String customerName) {
[Link] = customerName;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
[Link] = email;
}
public String getPhoneNumber() {
return phoneNumber;
}
public void setPhoneNumber(String phoneNumber) {
[Link] = phoneNumber;
}
public Long getTransactionId() {
return transactionId;
}
public void setTransactionId(Long transactionId) {
[Link] = transactionId;
}
public Date getDateOfBirth() {
return dateOfBirth;
}
public void setDateOfBirth(Date dateOfBirth) {
[Link] = dateOfBirth;
}
public String getGender() {
return gender;
}
public void setGender(String gender) {
[Link] = gender;
}
public String getPassport() {
return passport;
}
public void setPassport(String passport) {
[Link] = passport;
}
public Date getCustomerActiveDate() {
return customerActiveDate;
}
public void setCustomerActiveDate(Date customerActiveDate) {
[Link] = customerActiveDate;
}
public Date getCustomerDeactiveDate() {
return customerDeactiveDate;
}
public void setCustomerDeactiveDate(Date customerDeactiveDate) {
[Link] = customerDeactiveDate;
}
public List<CustomerAddressRequest> getCustomerAddressRequest() {
return customerAddressRequest;
}
public void setCustomerAddressRequest(List<CustomerAddressRequest>
customerAddressRequest) {
[Link] = customerAddressRequest;
}
public List<ServiceProviderDetailsRequest> getServiceProviderDetailsRequest()
{
return serviceProviderDetailsRequest;
}
public void
setServiceProviderDetailsRequest(List<ServiceProviderDetailsRequest>
serviceProviderDetailsRequest) {
[Link] = serviceProviderDetailsRequest;
}

package [Link];

import [Link];

public class CustomerDetailsResponse {

private String customerName;


private String email;
private String phoneNumber;
private Long transactionId;
private List<String> messages;
public String getCustomerName() {
return customerName;
}
public void setCustomerName(String customerName) {
[Link] = customerName;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
[Link] = email;
}
public String getPhoneNumber() {
return phoneNumber;
}
public void setPhoneNumber(String phoneNumber) {
[Link] = phoneNumber;
}
public Long getTransactionId() {
return transactionId;
}
public void setTransactionId(Long transactionId) {
[Link] = transactionId;
}
public List<String> getMessages() {
return messages;
}
public void setMessages(List<String> messages) {
[Link] = messages;
}

}
package [Link];

public class ServiceProvideDetailsResponse {


private Long spid;
private String providerName;
private String providerAddress;
private String providerContact;
private String providerType;
public Long getSpid() {
return spid;
}
public void setSpid(Long spid) {
[Link] = spid;
}
public String getProviderName() {
return providerName;
}
public void setProviderName(String providerName) {
[Link] = providerName;
}
public String getProviderAddress() {
return providerAddress;
}
public void setProviderAddress(String providerAddress) {
[Link] = providerAddress;
}
public String getProviderContact() {
return providerContact;
}
public void setProviderContact(String providerContact) {
[Link] = providerContact;
}
public String getProviderType() {
return providerType;
}
public void setProviderType(String providerType) {
[Link] = providerType;
}

}
package [Link];

import [Link];

public class ServiceProviderDetailsRequest {


private Long id;
private Long spid;
private String providerName;
private String providerAddress;
private String providerContact;
private String providerType;
private String website;
private String servicesOffered;
private Date establishedDate;
private double rating;

// Getters and setters


public Long getId() {
return id;
}

public void setId(Long id) {


[Link] = id;
}

public Long getSpid() {


return spid;
}

public void setSpid(Long spid) {


[Link] = spid;
}

public String getProviderName() {


return providerName;
}

public void setProviderName(String providerName) {


[Link] = providerName;
}

public String getProviderAddress() {


return providerAddress;
}

public void setProviderAddress(String providerAddress) {


[Link] = providerAddress;
}

public String getProviderContact() {


return providerContact;
}

public void setProviderContact(String providerContact) {


[Link] = providerContact;
}

public String getProviderType() {


return providerType;
}

public void setProviderType(String providerType) {


[Link] = providerType;
}

public String getWebsite() {


return website;
}

public void setWebsite(String website) {


[Link] = website;
}
public String getServicesOffered() {
return servicesOffered;
}

public void setServicesOffered(String servicesOffered) {


[Link] = servicesOffered;
}

public Date getEstablishedDate() {


return establishedDate;
}

public void setEstablishedDate(Date establishedDate) {


[Link] = establishedDate;
}

public double getRating() {


return rating;
}

public void setRating(double rating) {


[Link] = rating;
}

}
package [Link];

import [Link];
import [Link];
import [Link];

@Component // Indicates that this class is a Spring component


public class CustomerAddressMapper {
// Method to map CustomerAddressRequest to CustomerAddress entity
public CustomerAddress mapAddress(CustomerAddressRequest
customerAddressRequest) {
// Creating a new CustomerAddress object
CustomerAddress customerAddress = new CustomerAddress();
// Mapping fields from CustomerAddressRequest to CustomerAddress entity
[Link]([Link]());
[Link]([Link]());
[Link]([Link]());
[Link]([Link]());
[Link]([Link]());
[Link]([Link]());
[Link]([Link]());
[Link]([Link]());
[Link]([Link]());
[Link]([Link]());

return customerAddress; // Returning the mapped CustomerAddress entity


}
}
package [Link];

import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];

@Component // Indicates that this class is a Spring component


public class CustomerDetailsMapper {

@Autowired // Autowiring CustomerAddressMapper dependency


private CustomerAddressMapper customerAddressMapper;

@Autowired // Autowiring ServiceProviderDetailsMapper dependency


private ServiceProviderDetailsMapper serviceProviderDetailsMapper;

// Method to map CustomerDetailsRequest to CustomerDetails entity


public CustomerDetails mapCustomerDetails(CustomerDetailsRequest
customerDetailsRequest) {
// Creating a new CustomerDetails object
CustomerDetails customerDetails = new CustomerDetails();
// Mapping fields from CustomerDetailsRequest to CustomerDetails entity
[Link]([Link]());
[Link]([Link]());

[Link]([Link](
));
[Link]([Link]());
[Link]([Link]());

[Link]([Link]
ate());

[Link]([Link]());
[Link]([Link]());
[Link]([Link]());

// Map Address
if ([Link]() != null) {
// Mapping customer address if present
CustomerAddress customerAddress =
[Link]([Link]()
.get(0)); // Assuming only one address is present
[Link](customerAddress); // Setting the mapped
customer address to customer details
}

// Map ServiceProviderDetails
if ([Link]() != null && !
[Link]().isEmpty()) {
// Mapping service provider details if present
ServiceProviderDetailsRequest serviceProviderRequest =
[Link]().get(0); // Assuming only
one service provider is present
ServiceProviderDetails serviceProviderDetails =
[Link](serviceProviderRequest); //
Mapping service provider details
[Link](serviceProviderDetails); // Setting
the mapped service provider details to customer details
}

return customerDetails; // Returning the mapped customerDetails object


}
}package [Link];

import [Link];
import [Link];
import [Link];

@Component // Indicates that this class is a Spring component


public class ServiceProviderDetailsMapper {

// Method to map ServiceProviderDetailsRequest to ServiceProviderDetails


entity
public ServiceProviderDetails
mapServiceProviderDetails(ServiceProviderDetailsRequest
serviceProviderDetailsRequest) {
// Creating a new ServiceProviderDetails object
ServiceProviderDetails serviceProviderDetails = new
ServiceProviderDetails();
// Mapping fields from ServiceProviderDetailsRequest to
ServiceProviderDetails entity

[Link]([Link]());

[Link]([Link]
e());

[Link]([Link]
Address());

[Link]([Link]
Contact());

[Link]([Link]
e());

[Link]([Link]());

[Link]([Link]
Offered());

[Link]([Link]
hedDate());

[Link]([Link]());

return serviceProviderDetails; // Returning the mapped


serviceProviderDetails object
}
}

package [Link];

import [Link];
import [Link];

import [Link];

@Repository // Indicates that this interface is a Spring repository


public interface CustomerDetailsRepository extends JpaRepository<CustomerDetails,
Long> {
// Define custom query methods if needed
}
package [Link];

import [Link];

public interface CustomerDetailsService {

/** Method to save customer details


Parameters:
- customerDetails: The customer details to be saved
Returns:
- The saved customer details

*/

CustomerDetails saveCustomerDetails(CustomerDetails customerDetails);

package [Link];

import [Link];
import [Link];

import [Link];
import [Link];

@Service // Spring service annotation to indicate this class as a service component


public class CustomerDetailsServiceImpl implements CustomerDetailsService {

@Autowired // Spring annotation for automatic dependency injection


private CustomerDetailsRepository customerDetailsRepository; // Repository for
customer details

@Override
public CustomerDetails saveCustomerDetails(CustomerDetails customerDetails) {
// Method to save customer details using the repository
return [Link](customerDetails); // Saving and
returning the customer details
}
}

You might also like