I am new to Springboot and i am now currently trying to learn how to use it with facade pattern. What is the main thing to do in facade and why should i use it. I tried to do it but i am not getting it right at this moment.this is the code i did by trying to find a adrress by a city id.im just posting the code im having trouble with
this is the repository class
@Repository
public interface EmployeeAddressRepository {
List<EmployeeAddress> findAllByAddress_City_Id(String cityid);
}
service class
@Service
public class EmployeeAddressService {
private EmployeeAddressRepository repository;
public List<EmployeeAddress> getallempbycityid(String cityid){
return this.repository.findAllByAddress_City_Id(cityid);
}
}
@Component
public class EmployeeAddressApi {
private EmployeeAddressService employeeAddressService;
private EmployeeService employeeService;
@Autowired
EmployeeAddressApi(EmployeeAddressService employeeAddress, EmployeeService employee) {
this.employeeService = employee;
this.employeeAddressService = employeeAddress;
}
public List<EmployeeAddress> getEmployeebycityId(String cityId) {
List<EmployeeAddress> EMPADDRESSLIST = employeeAddressService.getallempbycityid(cityId);
//adding names and emp id in list
List<Name> namesList = new LinkedList<>();
//sorting and getting just names
for (EmployeeAddress ea : EMPADDRESSLIST) {
namesList.add(employeeService.findById(ea.getStaffId()).getName())
}
if (namesList.isEmpty())
return null;
List<String> surnames=new ArrayList<>();
for(Name n:namesList){
surnames.add(n.getLastName)
}
//return surname
return namesList;
}
}
@RestController
@RequestMapping("/employeeaddress")
public class EmployeeAddressController {
private EmployeeAddressApi employeeAddressApi;
EmployeeAddressController(EmployeeAddressApi employeeAddressApi){
this.employeeAddressApi=employeeAddressApi;
}
@GetMapping("/getempbycityid/{cityId}")
public List<Name> read(@PathVariable String cityId){
return employeeAddressApi.getEmployeebycityId(cityId)};
}
//testController
@Test
d b_read() {
String cityid="cityid"
String url=base_url+"/read/"+cityid;
System.out.println("URL"+ url);
HttpHeaders httpHeaders=new HttpHeaders();
HttpEntity<String> entity=new HttpEntity<>(null,httpHeaders);
ResponseEntity<String> response=restTemplate.exchange(url, HttpMethod.GET,entity,String.class);
assertNotNull(response);
System.out.println("allcity"+cityid;
System.out.println("getall"+response.body();
}
I am trying to get a adress by a cityId then from that get a employee last name from the city id
Isgak Abzal is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.