Skip to content

Commit

Permalink
Refactor : TripItem 정렬 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
Kim-Dong-Jun99 committed Jan 18, 2024
1 parent b7a81d4 commit 733449f
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,15 @@ public record TripItemMsg(
) {
public static TripItemMsg fromTripItemList(Long tripId, String visitDate, Transportation transportation, List<TripItem> tripItems) {

return new TripItemMsg(tripId, visitDate, transportation, tripItems.stream().map(t -> new TripItemInfoMsg(t.getId(), t.getTourItem().getId(), t.getTourItem().getTitle(), t.getTourItem().getOriginalThumbnailUrl(), Category.fromCode(t.getTourItem().getContentTypeId()).getName(), t.getSeqNum(), t.getVisitDate().toString(), t.getPrice())).toList());
List<TripItemInfoMsg> tripItemInfoMsgs = new ArrayList<>(tripItems.stream().map(t -> new TripItemInfoMsg(t.getId(), t.getTourItem().getId(), t.getTourItem().getTitle(), t.getTourItem().getOriginalThumbnailUrl(), Category.fromCode(t.getTourItem().getContentTypeId()).getName(), t.getSeqNum(), t.getVisitDate().toString(), t.getPrice())).toList());
tripItemInfoMsgs.sort((a, b) -> {
if (!a.seqNum().equals(b.seqNum())) {

return Integer.parseInt(Long.toString(a.seqNum() - b.seqNum()));
}
return Integer.parseInt(Long.toString(a.tripItemId() - b.tripItemId()));
});
return new TripItemMsg(tripId, visitDate, transportation, tripItemInfoMsgs);
}

public static TripItemMsg fromTripItemList(Long tripId, String visitDate, List<TripItem> tripItems, Long tripItemId, Transportation transportation, TripItemPriceUpdateMsg updateMsg) {
Expand All @@ -28,6 +36,13 @@ public static TripItemMsg fromTripItemList(Long tripId, String visitDate, List<T
tripItemInfoMsgs.add(new TripItemInfoMsg(t.getId(), t.getTourItem().getId(), t.getTourItem().getTitle(), t.getTourItem().getOriginalThumbnailUrl(), Category.fromCode(t.getTourItem().getContentTypeId()).getName(), t.getSeqNum(), t.getVisitDate().toString(), t.getPrice()));
}
}
tripItemInfoMsgs.sort((a, b) -> {
if (!a.seqNum().equals(b.seqNum())) {

return Integer.parseInt(Long.toString(a.seqNum() - b.seqNum()));
}
return Integer.parseInt(Long.toString(a.tripItemId() - b.tripItemId()));
});
return new TripItemMsg(tripId, visitDate, transportation, tripItemInfoMsgs );
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ public void updateTripItemPrice(String tripItemId, TripItemPriceUpdateMsg priceU
TripBudgetMsg tripBudgetMsg = new TripBudgetMsg(trip.getId(), trip.getBudget(), trip.getTripItemPriceSum() + trip.getTransportationPriceSum());
TripItemMsg tripItemMsg = fromTripItemList(trip.getId(), tripItem.getVisitDate().toString(), tripItems, tripItem.getId(), fromName(transportation), priceUpdateMsg);

trip.updateTripTransportationMap(tripTransportationMap);
tripRepository.save(trip);

kafkaProducer.sendAndSaveToRedis(tripBudgetMsg, tripItemMsg);
Expand All @@ -83,7 +82,7 @@ public void updateTripItemVisitDate(String tripItemId, TripItemVisitDateUpdateMs
);
} else {
TripItem tripItem = optionalTripItem.get();
Trip trip = tripRepository.getReferenceById(tripItem.getTrip().getId());
Trip trip = tripItem.getTrip();
Map<String, String> tripTransportationMap = trip.getTripTransportationMap();
LocalDate pastDate = tripItem.getVisitDate();
String pastDateTransportation = tripTransportationMap.getOrDefault(pastDate.toString(), CAR.getName());
Expand Down Expand Up @@ -124,7 +123,6 @@ public void updateTripItemVisitDate(String tripItemId, TripItemVisitDateUpdateMs
trip.updateTransportationPriceSum(tripPathPriceMap.getOrDefault(newDate.toString(), 0), newDateTripPath.pathPriceSum());
tripPathPriceMap.put(pastDate.toString(), pastDateTripPath.pathPriceSum());
tripPathPriceMap.put(newDate.toString(), newDateTripPath.pathPriceSum());
trip.updateTripTransportationMap(tripTransportationMap);
trip.updateTripPathPriceMap(tripPathPriceMap);
tripRepository.save(trip);

Expand Down Expand Up @@ -153,7 +151,7 @@ public void deleteTripItem(String tripItemId, TripItemDeleteMsg tripItemDeleteMs
);
} else {
TripItem tripItem = optionalTripItem.get();
Trip trip = tripRepository.getReferenceById(tripItem.getTrip().getId());
Trip trip = tripItem.getTrip();
Map<String, String> tripTransportationMap = trip.getTripTransportationMap();
LocalDate visitDate = tripItem.getVisitDate();
String transportation = tripTransportationMap.getOrDefault(visitDate.toString(), CAR.getName());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,6 @@ private void updateBudgetAndItemsAndPath(Trip trip, List<TripItem> tripItems, St
trip.updateTransportationPriceSum(tripPathPriceMap.getOrDefault(visitDate, 0), tripPath.pathPriceSum());
tripPathPriceMap.put(visitDate, tripPath.pathPriceSum());
trip.updateTripPathPriceMap(tripPathPriceMap);
trip.updateTripTransportationMap(tripTransportationMap);
tripRepository.save(trip);

TripBudgetMsg tripBudgetMsg = new TripBudgetMsg(trip.getId(), trip.getBudget(), trip.getTripItemPriceSum() + trip.getTransportationPriceSum());
Expand Down

0 comments on commit 733449f

Please sign in to comment.