Commit 8ff45e00 authored by mohantejaoleti's avatar mohantejaoleti

register and get all customers details changes

parent f61ccd02
Pipeline #2352 failed with stages
package com.altimetrik.controllers;
import com.altimetrik.service.CustomerDetailService;
import com.altimetrik.view.CustomerDetailView;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
@RestController
@RequestMapping(value = "/customer")
public class CustomerController {
@Autowired
CustomerDetailService customerDetailService;
@PostMapping(value = "/registerCustomer", produces = MediaType.APPLICATION_JSON_VALUE, consumes = MediaType.ALL_VALUE)
public ResponseEntity<Object> saveCustomer(@RequestBody CustomerDetailView customerDetailView) throws Exception {
return handleResponse(customerDetailService.saveCustomer(customerDetailView));
}
@GetMapping(value = "/getAllCustomer", produces = MediaType.APPLICATION_JSON_VALUE, consumes = MediaType.ALL_VALUE)
public ResponseEntity<Object> getAllCustomer() {
return handleResponse(customerDetailService.getAllCustomers());
}
public ResponseEntity<Object> handleResponse(Object object) {
HttpHeaders responseHeaders = new HttpHeaders();
responseHeaders.setContentType(MediaType.APPLICATION_JSON);
return new ResponseEntity(object, responseHeaders, HttpStatus.OK);
}
}
package main.java.com.altimetrik.model;
import lombok.Data;
import javax.persistence.*;
import java.sql.Date;
@Data
@Entity
@Table(name="customer")
public class Customer {
@Column (name = "customer_name")
private String name;
@Column (name = "date_of_birth")
private String dateOfBirth;
@Column (name = "customer_email")
private String email;
@Column (name = "aadhaar_number")
private String aadhaarNumber;
@Column (name = "registration_date")
private String registrationDate;
@Column (name = "assigned_mobile_number")
private Long assignedMobileNumber;
@Id
@Column(name="id")
@GeneratedValue(strategy=GenerationType.AUTO , generator="student_generator")
private Long primaryKey = null;
}
package com.altimetrik.repository;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;
@Repository
public interface ICustomerDetailRepository extends JpaRepository<main.java.com.altimetrik.model.Customer, Long> {
main.java.com.altimetrik.model.Customer save(main.java.com.altimetrik.model.Customer customer);
}
package com.altimetrik.service;
import com.altimetrik.repository.ICustomerDetailRepository;
import com.altimetrik.view.CustomerDetailView;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
@Service
public class CustomerDetailService {
@Autowired
ICustomerDetailRepository customerDetailRepository;
public List<main.java.com.altimetrik.model.Customer> getAllCustomers( ) {
return customerDetailRepository.findAll();
}
public main.java.com.altimetrik.model.Customer saveCustomer(CustomerDetailView customerDetailView) throws Exception {
if(customerDetailView.getAadhaarNumber() == null || customerDetailView.getAadhaarNumber().length() != 12){
throw new Exception("Aadhaar number is invalid");
}
main.java.com.altimetrik.model.Customer customer = new main.java.com.altimetrik.model.Customer();
customer.setName(customerDetailView.getName());
customer.setEmail(customerDetailView.getEmail());
customer.setDateOfBirth(customerDetailView.getDateOfBirth());
customer.setRegistrationDate(customerDetailView.getRegistrationDate());
customer.setAssignedMobileNumber(customerDetailView.getAssignedMobileNumber());
return customerDetailRepository.save(customer);
}
}
package com.altimetrik.view;
import lombok.Data;
import javax.persistence.Column;
@Data
public class CustomerDetailView {
private String name;
private String dateOfBirth;
private String email;
private String aadhaarNumber;
private String registrationDate;
private Long assignedMobileNumber;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment