Skip to content

Commit

Permalink
fix(m360-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 b363653 commit 3e56e51
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

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.exceptions.FPISvcEx;
import com.abavilla.fpi.sms.config.ApiKeyConfig;
import com.abavilla.fpi.sms.entity.sms.LeakAck;
Expand All @@ -42,10 +43,10 @@ public class CallbackResource

@Path("webhook/{apiKey}")
@GET
public Uni<Void> acknowledge(@QueryParam("status_code") String stsCde,
@QueryParam("transid") String msgId,
@QueryParam("timestamp") String timestamp,
@PathParam("apiKey") String apiKey) {
public Uni<RespDto<NullDto>> acknowledge(@QueryParam("status_code") String stsCde,
@QueryParam("transid") String msgId,
@QueryParam("timestamp") String timestamp,
@PathParam("apiKey") String apiKey) {
if (StringUtils.equals(apiKey, apiKeyConfig.getDlrApiKey())) {
return service.acknowledge(msgId, stsCde, timestamp);
} else {
Expand Down
21 changes: 12 additions & 9 deletions core/src/main/java/com/abavilla/fpi/sms/service/sms/MsgAckSvc.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import java.util.List;

import com.abavilla.fpi.fw.dto.impl.NullDto;
import com.abavilla.fpi.fw.dto.impl.RespDto;
import com.abavilla.fpi.fw.exceptions.ApiSvcEx;
import com.abavilla.fpi.fw.exceptions.OptimisticLockEx;
import com.abavilla.fpi.fw.service.AbsSvc;
Expand All @@ -33,26 +34,20 @@
import com.abavilla.fpi.sms.repo.sms.MsgReqRepo;
import com.abavilla.fpi.sms.util.M360Const;
import com.abavilla.fpi.telco.ext.enums.ApiStatus;
import io.netty.handler.codec.http.HttpResponseStatus;
import io.quarkus.logging.Log;
import io.smallrye.mutiny.Uni;
import jakarta.enterprise.context.ApplicationScoped;
import jakarta.inject.Inject;
import org.apache.commons.lang3.ObjectUtils;
import org.eclipse.microprofile.context.ManagedExecutor;

@ApplicationScoped
public class MsgAckSvc extends AbsSvc<NullDto, LeakAck> {

@Inject
MsgReqRepo msgReqRepo;

/**
* Runs background tasks from webhook
*/
@Inject
ManagedExecutor executor;

public Uni<Void> acknowledge(String msgId, String ackStsCde, String ackTimestamp) {
public Uni<RespDto<NullDto>> acknowledge(String msgId, String ackStsCde, String ackTimestamp) {
var apiStatus = ApiStatus.fromId(Integer.parseInt(ackStsCde));
var ackTime = DateUtil.modLdtToUtc(
DateUtil.parseStrDateToLdt(ackTimestamp, M360Const.M360_TIMESTAMP_FORMAT));
Expand Down Expand Up @@ -89,6 +84,14 @@ public Uni<Void> acknowledge(String msgId, String ackStsCde, String ackTimestamp
.subscribe().with(ignored -> {
});

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

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

}

0 comments on commit 3e56e51

Please sign in to comment.