Skip to content

Commit

Permalink
add data to ShoppingCartDto
Browse files Browse the repository at this point in the history
  • Loading branch information
mirzaeimahdi409 committed Aug 3, 2024
1 parent c9229f4 commit ac81ebd
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,12 @@ public class ShoppingCartDto {
@JsonProperty("restaurant_owner_id")
private long restaurantOwnerId;

@JsonProperty("restaurant_owner")
private RestaurantOwnerDto restaurantOwner;

@JsonProperty("restaurant_comments")
private RestaurantCommentsDto restaurantComments;

@JsonProperty("shopping_cart_items")
private List<ShoppingCartItemDto> shoppingCartItems;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import com.dishDash.common.enums.ErrorCode;
import com.dishDash.common.exception.CustomException;
import com.dishDash.common.feign.Product.FoodApi;
import com.dishDash.common.feign.user.UserApi;
import com.dish_dash.order.domain.mapper.ShoppingCartMapper;
import com.dish_dash.order.domain.model.ShoppingCart;
import com.dish_dash.order.domain.model.ShoppingCartItem;
Expand All @@ -17,18 +18,18 @@
import java.util.concurrent.atomic.AtomicReference;
import java.util.stream.Collectors;
import lombok.RequiredArgsConstructor;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
@RequiredArgsConstructor
@Slf4j
public class CustomerShoppingCartService {

private static final Logger log = LoggerFactory.getLogger(CustomerShoppingCartService.class);
private final ShoppingCartRepository shoppingCartRepository;
private final FoodApi foodApi;
private final UserApi userApi;
private final RateService rateService;

public ShoppingCartDto createShoppingCart(long customerId, long restaurantOwnerId) {
Optional<ShoppingCart> shoppingCartOptional =
Expand All @@ -45,7 +46,12 @@ public ShoppingCartDto createShoppingCart(long customerId, long restaurantOwnerI
.totalPrice(Price.builder().build())
.build());

return ShoppingCartMapper.INSTANCE.shoppingCartToDto(shoppingCart);
ShoppingCartDto shoppingCartDto = ShoppingCartMapper.INSTANCE.shoppingCartToDto(shoppingCart);
shoppingCartDto.setRestaurantOwner(
userApi.getRestaurantOwnerProfile(shoppingCartDto.getRestaurantOwnerId()));
shoppingCartDto.setRestaurantComments(
rateService.getRestaurantComments(shoppingCartDto.getRestaurantOwnerId()));
return shoppingCartDto;
}

@Transactional
Expand Down Expand Up @@ -96,6 +102,10 @@ public ShoppingCartDto modifyShoppingCart(
item.setDescription(foodDto.getDescription());
}));
log.info("Shopping cart Add name. {}", shoppingCartDto);
shoppingCartDto.setRestaurantOwner(
userApi.getRestaurantOwnerProfile(shoppingCartDto.getRestaurantOwnerId()));
shoppingCartDto.setRestaurantComments(
rateService.getRestaurantComments(shoppingCartDto.getRestaurantOwnerId()));
return shoppingCartDto;
}
return null;
Expand All @@ -117,7 +127,10 @@ public List<ShoppingCartDto> getCustomerShoppingCarts(long customerId) {
item.setDescription(foodDto.getDescription());
})
.collect(Collectors.toList()));

shoppingCartDto.setRestaurantOwner(
userApi.getRestaurantOwnerProfile(shoppingCartDto.getRestaurantOwnerId()));
shoppingCartDto.setRestaurantComments(
rateService.getRestaurantComments(shoppingCartDto.getRestaurantOwnerId()));
return shoppingCartDto;
})
.collect(Collectors.toList());
Expand Down

0 comments on commit ac81ebd

Please sign in to comment.