Skip to content

Commit

Permalink
feat: implemented microservices to align to svc
Browse files Browse the repository at this point in the history
  • Loading branch information
JordenReuter committed Feb 20, 2024
1 parent bf95050 commit e8efad9
Show file tree
Hide file tree
Showing 5 changed files with 1,434 additions and 0 deletions.
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();
}
}
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);

}
Loading

0 comments on commit e8efad9

Please sign in to comment.