From a2cb7e6a599da1c6bcdb0e8639ce42beeffe367c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dominik=20S=C3=A4ume?= Date: Mon, 30 Sep 2024 09:10:01 +0200 Subject: [PATCH] PMT-9: Implement an API Client Factory for setting up the API Client with its Config --- .../hmmh/pmt/employee/ApiClientFactory.java | 37 +++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 src/main/java/de/hmmh/pmt/employee/ApiClientFactory.java diff --git a/src/main/java/de/hmmh/pmt/employee/ApiClientFactory.java b/src/main/java/de/hmmh/pmt/employee/ApiClientFactory.java new file mode 100644 index 0000000..621ab58 --- /dev/null +++ b/src/main/java/de/hmmh/pmt/employee/ApiClientFactory.java @@ -0,0 +1,37 @@ +package de.hmmh.pmt.employee; + +import de.hmmh.pmt.auth.JwtToken; +import de.hmmh.pmt.employee.api.EmployeeControllerApi; +import de.hmmh.pmt.employee.api.QualificationControllerApi; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; + +@Component +public class ApiClientFactory { + + @Autowired + private ApiClient apiClient; + @Autowired + private JwtToken apiToken; + @Autowired + private EmployeeControllerApi employee; + @Autowired + private QualificationControllerApi qualification; + + public EmployeeControllerApi getEmployeeApi() { + prepareApiClient(); + employee.setApiClient(apiClient); + return employee; + } + + public QualificationControllerApi getQualificationApi() { + prepareApiClient(); + qualification.setApiClient(apiClient); + return qualification; + } + + private void prepareApiClient() { + apiClient.setAccessToken(apiToken.getToken()); + apiClient.setBasePath("https://employee.szut.dev"); + } +}