Skip to content

Commit

Permalink
fix returning delivery person current order while it is null and crea…
Browse files Browse the repository at this point in the history
…ting menu if not exists in category creation
  • Loading branch information
amirarab888 committed Aug 3, 2024
1 parent 918a120 commit cf2e102
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 11 deletions.
Original file line number Diff line number Diff line change
@@ -1,19 +1,31 @@
package com.dish_dash.gateway.configuration;

import com.dishDash.common.enums.ErrorCode;
import com.dishDash.common.exception.CustomException;
import com.dishDash.common.response.ErrorResponse;
import com.dish_dash.gateway.exception.CustomGatewayException;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import feign.Response;
import feign.codec.ErrorDecoder;
import lombok.RequiredArgsConstructor;

import java.io.IOException;
import java.nio.charset.StandardCharsets;

@RequiredArgsConstructor
public class FeignClientErrorDecoder implements ErrorDecoder {

private final ObjectMapper objectMapper;
@Override
public Exception decode(String methodKey, Response response) {
String body = getBodyAsString(response);

ErrorCode errorCode = mapResponseBodyToErrorCode(body);
ErrorResponse errorResponse;
try {
errorResponse = objectMapper.readValue(body, ErrorResponse.class);
} catch (JsonProcessingException e) {
return new CustomGatewayException(ErrorCode.INTERNAL_SERVER_ERROR);
}
ErrorCode errorCode = mapResponseBodyToErrorCode(errorResponse.getMessage());

if (errorCode != null) {
return new CustomGatewayException(errorCode);
Expand All @@ -35,7 +47,7 @@ private String getBodyAsString(Response response) {

private ErrorCode mapResponseBodyToErrorCode(String body) {
for (ErrorCode errorCode : ErrorCode.values()) {
if (body.contains(errorCode.name())) {
if (body.equals(errorCode.name())) {
return errorCode;
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.dish_dash.gateway.configuration;

import com.fasterxml.jackson.databind.ObjectMapper;
import feign.codec.ErrorDecoder;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
Expand All @@ -21,6 +22,6 @@ public void addCorsMappings(CorsRegistry registry) {

@Bean
public ErrorDecoder errorDecoder() {
return new FeignClientErrorDecoder();
return new FeignClientErrorDecoder(new ObjectMapper());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,6 @@ public ResponseEntity<ErrorResponse> handleCustomGatewayException(CustomGatewayE
ErrorResponse errorResponse =
new ErrorResponse(errorCode.getErrorCodeValue(), errorCode.getErrorMessageValue());

return new ResponseEntity<>(errorResponse, errorCode.getHttpStatus());
return new ResponseEntity<>(errorResponse, errorCode.getClientHttpStatus());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,6 @@ public OrderDto getDeliveryPersonCurrentOrder(long deliveryPersonID) {
userApi.getRestaurantOwnerProfile(orderDto.getRestaurantOwnerId()));
return orderDto;
}
throw new CustomException(ErrorCode.NO_CONTENT, "order not found");
throw new CustomException(ErrorCode.NOT_FOUND_No_CONTENT, "order not found");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.sql.Time;
import java.time.LocalDateTime;

import static com.fasterxml.jackson.databind.type.LogicalType.DateTime;

@Service
@RequiredArgsConstructor
@Slf4j
Expand Down Expand Up @@ -97,10 +102,7 @@ public boolean setLocation(LocationDto locationDto, long deliveryPersonId) {
.latitude(locationDto.getLatitude())
.longitude(locationDto.getLongitude())
.build());

location.setLatitude(locationDto.getLatitude());
location.setLongitude(locationDto.getLongitude());
locationRepository.save(location);
locationRepository.modify(locationDto.getLatitude(), locationDto.getLongitude(), System.currentTimeMillis(), location.getId());

deliveryPerson.setLocation(location);
deliveryPersonRepository.save(deliveryPerson);
Expand Down

0 comments on commit cf2e102

Please sign in to comment.