Skip to content

Commit

Permalink
fix(dvs-api): return http ok for callbacks
Browse files Browse the repository at this point in the history
  • Loading branch information
vincejv committed Aug 31, 2023
1 parent c13db7e commit dfec2f1
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
package com.abavilla.fpi.load.controller.load;

import com.abavilla.fpi.fw.controller.AbsBaseResource;
import com.abavilla.fpi.fw.dto.impl.NullDto;
import com.abavilla.fpi.fw.dto.impl.RespDto;
import com.abavilla.fpi.fw.util.MapperUtil;
import com.abavilla.fpi.load.config.ApiKeyConfig;
import com.abavilla.fpi.load.dto.load.gl.GLRewardsCallbackDto;
Expand Down Expand Up @@ -49,8 +51,8 @@ public class CallbackResource

@Path("{apiKey}")
@POST
public Uni<Void> callback(@PathParam("apiKey") String apiKey,
JsonNode body) {
public Uni<RespDto<NullDto>> callback(@PathParam("apiKey") String apiKey,
JsonNode body) {
if (StringUtils.equals(apiKey, apiKeyConfig.getGenericApiKey())) {
return service.storeCallback(MapperUtil.convert(body, GLRewardsCallbackDto.class));
} else if (StringUtils.equals(apiKey, "intlprov")) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
import java.time.ZoneOffset;
import java.util.function.Function;

import com.abavilla.fpi.fw.dto.impl.NullDto;
import com.abavilla.fpi.fw.dto.impl.RespDto;
import com.abavilla.fpi.fw.entity.mongo.AbsMongoItem;
import com.abavilla.fpi.fw.exceptions.ApiSvcEx;
import com.abavilla.fpi.fw.service.AbsSvc;
Expand All @@ -48,6 +50,7 @@
import com.dtone.dvs.dto.Transaction;
import com.google.i18n.phonenumbers.NumberParseException;
import com.google.i18n.phonenumbers.PhoneNumberUtil;
import io.netty.handler.codec.http.HttpResponseStatus;
import io.quarkus.logging.Log;
import io.smallrye.mutiny.Uni;
import jakarta.enterprise.context.ApplicationScoped;
Expand Down Expand Up @@ -91,22 +94,22 @@ public class RewardsCallbackSvc extends AbsSvc<GLRewardsCallbackDto, RewardsTran
@Inject
PhoneNumberUtil phoneNumberUtil;

public Uni<Void> storeCallback(GLRewardsCallbackDto callbackDto) {
public Uni<RespDto<NullDto>> storeCallback(GLRewardsCallbackDto callbackDto) {
return storeCallback(
glMapper.mapGLCallbackDtoToEntity(callbackDto),
ApiStatus.fromGL(callbackDto.getBody().getStatus()),
LoadConst.PROV_GL, callbackDto.getBody().getTransactionId());
}

public Uni<Void> storeCallback(Transaction dvsCallbackTransaction) {
public Uni<RespDto<NullDto>> storeCallback(Transaction dvsCallbackTransaction) {
var dvsCallbackDto = dtOneMapper.mapDTOneTransactionToCallbackDto(dvsCallbackTransaction);
return storeCallback(
dtOneMapper.mapDTOneRespToEntity(dvsCallbackDto),
ApiStatus.fromDtOne(dvsCallbackDto.getStatus().getId()),
LoadConst.PROV_DTONE, dvsCallbackDto.getDtOneId());
}

private Uni<Void> storeCallback(AbsMongoItem callbackResponse, ApiStatus status,
private Uni<RespDto<NullDto>> storeCallback(AbsMongoItem callbackResponse, ApiStatus status,
String provider, Long transactionId) {
var byTransId = advRepo.findByRespTransIdAndProvider(
String.valueOf(transactionId), provider);
Expand All @@ -122,7 +125,7 @@ private Uni<Void> storeCallback(AbsMongoItem callbackResponse, ApiStatus status,
.subscribe().with(ignored -> {
});

return Uni.createFrom().voidItem();
return Uni.createFrom().item(this::buildAckResponse);
}

/**
Expand Down Expand Up @@ -311,4 +314,11 @@ private Uni<?> sendToBotSource(RewardsTransStatus rewardsTransStatus, UserDto us
};
}

public RespDto<NullDto> buildAckResponse() {
RespDto<NullDto> ackResp = new RespDto<>();
ackResp.setTimestamp(DateUtil.nowAsStr());
ackResp.setStatus(HttpResponseStatus.OK.reasonPhrase());
return ackResp;
}

}

0 comments on commit dfec2f1

Please sign in to comment.