-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: implemented microservices to align to svc
- Loading branch information
1 parent
bf95050
commit e8efad9
Showing
5 changed files
with
1,434 additions
and
0 deletions.
There are no files selected for viewing
108 changes: 108 additions & 0 deletions
108
...ain/java/org/tkit/onecx/product/store/bff/rs/controllers/MicroservicesRestController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
package org.tkit.onecx.product.store.bff.rs.controllers; | ||
|
||
import jakarta.enterprise.context.ApplicationScoped; | ||
import jakarta.inject.Inject; | ||
import jakarta.transaction.Transactional; | ||
import jakarta.validation.ConstraintViolationException; | ||
import jakarta.ws.rs.WebApplicationException; | ||
import jakarta.ws.rs.core.Response; | ||
|
||
import org.eclipse.microprofile.rest.client.inject.RestClient; | ||
import org.jboss.resteasy.reactive.RestResponse; | ||
import org.jboss.resteasy.reactive.server.ServerExceptionMapper; | ||
import org.tkit.onecx.product.store.bff.rs.mappers.ExceptionMapper; | ||
import org.tkit.onecx.product.store.bff.rs.mappers.MicroservicesMapper; | ||
import org.tkit.onecx.product.store.bff.rs.mappers.ProblemDetailMapper; | ||
import org.tkit.quarkus.log.cdi.LogService; | ||
|
||
import gen.org.tkit.onecx.product.store.bff.rs.internal.MicroservicesApiService; | ||
import gen.org.tkit.onecx.product.store.bff.rs.internal.model.*; | ||
import gen.org.tkit.onecx.product.store.client.api.MicroservicesInternalApi; | ||
import gen.org.tkit.onecx.product.store.client.model.Microservice; | ||
import gen.org.tkit.onecx.product.store.client.model.MicroservicePageResult; | ||
import gen.org.tkit.onecx.product.store.client.model.ProblemDetailResponse; | ||
|
||
@LogService | ||
@ApplicationScoped | ||
@Transactional(value = Transactional.TxType.NOT_SUPPORTED) | ||
public class MicroservicesRestController implements MicroservicesApiService { | ||
|
||
@RestClient | ||
@Inject | ||
MicroservicesInternalApi client; | ||
|
||
@Inject | ||
MicroservicesMapper mapper; | ||
|
||
@Inject | ||
ProblemDetailMapper problemDetailMapper; | ||
|
||
@Inject | ||
ExceptionMapper exceptionMapper; | ||
|
||
@Override | ||
public Response createMicroservice(CreateMicroserviceRequestDTO createMicroserviceRequestDTO) { | ||
|
||
try (Response response = client.createMicroservice(mapper.mapCreateMs(createMicroserviceRequestDTO))) { | ||
Microservice createdMs = response.readEntity(Microservice.class); | ||
MicroserviceDTO createdMsDTO = mapper.map(createdMs); | ||
return Response.status(response.getStatus()).entity(createdMsDTO).build(); | ||
} catch (WebApplicationException ex) { | ||
return Response.status(ex.getResponse().getStatus()) | ||
.entity(problemDetailMapper.map(ex.getResponse().readEntity(ProblemDetailResponse.class))).build(); | ||
} | ||
} | ||
|
||
@Override | ||
public Response deleteMicroservice(String id) { | ||
try (Response response = client.deleteMicroservice(id)) { | ||
return Response.fromResponse(response).build(); | ||
} | ||
} | ||
|
||
@Override | ||
public Response getMicroservice(String id) { | ||
try (Response response = client.getMicroservice(id)) { | ||
Microservice resultMs = response.readEntity(Microservice.class); | ||
MicroserviceDTO resultProductDTO = mapper.map(resultMs); | ||
return Response.status(response.getStatus()).entity(resultProductDTO).build(); | ||
} | ||
} | ||
|
||
@Override | ||
public Response getMicroserviceByAppId(String appId) { | ||
try (Response response = client.getMicroserviceByAppId(appId)) { | ||
MicroserviceDTO result = mapper.map(response.readEntity(Microservice.class)); | ||
return Response.status(response.getStatus()).entity(result).build(); | ||
} | ||
} | ||
|
||
@Override | ||
public Response searchMicroservice(MicroserviceSearchCriteriaDTO microserviceSearchCriteriaDTO) { | ||
try (Response response = client.searchMicroservice(mapper.mapMsSearchCriteria(microserviceSearchCriteriaDTO))) { | ||
MicroservicePageResult searchPageResults = response.readEntity(MicroservicePageResult.class); | ||
MicroservicePageResultDTO searchPageResultDTO = mapper.mapMsSearchPageResponse(searchPageResults); | ||
return Response.status(response.getStatus()).entity(searchPageResultDTO).build(); | ||
} | ||
} | ||
|
||
@Override | ||
public Response updateMicroservice(String id, UpdateMicroserviceRequestDTO updateMicroserviceRequestDTO) { | ||
try (Response response = client.updateMicroservice(id, mapper.mapUpdateMs(updateMicroserviceRequestDTO))) { | ||
return Response.fromResponse(response).build(); | ||
} catch (WebApplicationException ex) { | ||
return Response.status(ex.getResponse().getStatus()) | ||
.entity(problemDetailMapper.map(ex.getResponse().readEntity(ProblemDetailResponse.class))).build(); | ||
} | ||
} | ||
|
||
@ServerExceptionMapper | ||
public RestResponse<ProblemDetailResponseDTO> constraint(ConstraintViolationException ex) { | ||
return exceptionMapper.constraint(ex); | ||
} | ||
|
||
@ServerExceptionMapper | ||
public Response restException(WebApplicationException ex) { | ||
return Response.status(ex.getResponse().getStatus()).build(); | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
src/main/java/org/tkit/onecx/product/store/bff/rs/mappers/MicroservicesMapper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package org.tkit.onecx.product.store.bff.rs.mappers; | ||
|
||
import org.mapstruct.Mapper; | ||
import org.mapstruct.Mapping; | ||
import org.tkit.quarkus.rs.mappers.OffsetDateTimeMapper; | ||
|
||
import gen.org.tkit.onecx.product.store.bff.rs.internal.model.*; | ||
import gen.org.tkit.onecx.product.store.client.model.*; | ||
|
||
@Mapper(uses = { OffsetDateTimeMapper.class }) | ||
public interface MicroservicesMapper { | ||
|
||
MicroserviceDTO map(Microservice ms); | ||
|
||
CreateMicroserviceRequest mapCreateMs(CreateMicroserviceRequestDTO createMs); | ||
|
||
UpdateMicroserviceRequest mapUpdateMs(UpdateMicroserviceRequestDTO updateMs); | ||
|
||
@Mapping(target = "removeStreamItem", ignore = true) | ||
MicroservicePageResultDTO mapMsSearchPageResponse(MicroservicePageResult searchResults); | ||
|
||
MicroserviceSearchCriteria mapMsSearchCriteria(MicroserviceSearchCriteriaDTO msSearchCriteria); | ||
|
||
} |
Oops, something went wrong.