Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,11 @@
import com.umc.yeogi_gal_lae.api.budget.dto.BudgetAssignment;
import com.umc.yeogi_gal_lae.api.budget.dto.BudgetDetailResponse;
import com.umc.yeogi_gal_lae.api.budget.dto.BudgetResponse;
import com.umc.yeogi_gal_lae.api.budget.dto.DailyBudgetAssignmentResponse;
import com.umc.yeogi_gal_lae.api.budget.repository.BudgetRepository;
import com.umc.yeogi_gal_lae.api.budget.service.BudgetService;
import com.umc.yeogi_gal_lae.global.common.response.Response;
import com.umc.yeogi_gal_lae.global.error.ErrorCode;
import com.umc.yeogi_gal_lae.global.success.SuccessCode;
import java.time.LocalDate;
import java.util.Collections;
import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -56,21 +54,7 @@ public Response<BudgetDetailResponse> getBudget(@PathVariable Long budgetId) {
}
Budget budget = budgetOpt.get();
Map<String, List<BudgetAssignment>> budgetMap = budgetService.getBudgetMapById(budgetId);
List<DailyBudgetAssignmentResponse> dailyAssignments = BudgetConverter.toDailyBudgetAssignmentResponseList(
budgetMap);

// AICourse를 통해 TripPlan 정보를 조회 (TripPlan 클래스가 startDate와 endDate를 LocalDate 타입으로 제공한다고 가정)
String imageUrl = budget.getAiCourse().getTripPlan().getImageUrl();
LocalDate startDate = budget.getAiCourse().getTripPlan().getStartDate();
LocalDate endDate = budget.getAiCourse().getTripPlan().getEndDate();

BudgetDetailResponse detailResponse = BudgetDetailResponse.builder()
.dailyAssignments(dailyAssignments)
.imageUrl(imageUrl)
.startDate(startDate)
.endDate(endDate)
.build();

BudgetDetailResponse detailResponse = BudgetConverter.toBudgetDetailResponse(budget, budgetMap);
return Response.of(SuccessCode.OK, detailResponse);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.umc.yeogi_gal_lae.api.budget.domain.Budget;
import com.umc.yeogi_gal_lae.api.budget.dto.BudgetAssignment;
import com.umc.yeogi_gal_lae.api.budget.dto.BudgetDetailResponse;
import com.umc.yeogi_gal_lae.api.budget.dto.BudgetResponse;
import com.umc.yeogi_gal_lae.api.budget.dto.DailyBudgetAssignmentResponse;
import java.util.List;
Expand Down Expand Up @@ -33,4 +34,17 @@ public static List<DailyBudgetAssignmentResponse> toDailyBudgetAssignmentRespons
.build())
.collect(Collectors.toList());
}

public static BudgetDetailResponse toBudgetDetailResponse(Budget budget,
Map<String, List<BudgetAssignment>> budgetMap) {
List<DailyBudgetAssignmentResponse> dailyAssignments = toDailyBudgetAssignmentResponseList(budgetMap);
return BudgetDetailResponse.builder()
.dailyAssignments(dailyAssignments)
.location(budget.getAiCourse().getTripPlan().getLocation())
.imageUrl(budget.getAiCourse().getTripPlan().getImageUrl())
.startDate(budget.getAiCourse().getTripPlan().getStartDate())
.endDate(budget.getAiCourse().getTripPlan().getEndDate())
.build();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
@AllArgsConstructor
@Builder
public class BudgetDetailResponse {
private String location;
private String imageUrl;
private LocalDate startDate;
private LocalDate endDate;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ private String buildBudgetPrompt(String scheduleJson) {
prompt.append("Given the following travel schedule in JSON format: ")
.append(scheduleJson)
.append(", generate budget recommendations for each day. ");
prompt.append("단, 'placeName' 필드의 값은 반드시 한국어로만 작성되어야 하며, 영어 표현은 사용하지 마세요. ");
prompt.append(
"For each place, assign exactly one budget type (one of MEAL, ACTIVITY, SHOPPING, TRANSPORT) and a recommended amount. ");
prompt.append(
Expand Down Expand Up @@ -125,7 +126,7 @@ private Map<String, List<BudgetAssignment>> parseBudgetGptResponse(String gptRes
if (jsonStart != -1) {
content = content.substring(jsonStart);
}
return objectMapper.readValue(content, new TypeReference<Map<String, List<BudgetAssignment>>>() {
return objectMapper.readValue(content, new TypeReference<>() {
});
} catch (Exception e) {
e.printStackTrace();
Expand All @@ -144,13 +145,11 @@ public Map<String, List<BudgetAssignment>> getBudgetMapById(Long id) {
}
try {
String budgetJson = budgetOpt.get().getBudgetJson();
return objectMapper.readValue(budgetJson, new TypeReference<Map<String, List<BudgetAssignment>>>() {
return objectMapper.readValue(budgetJson, new TypeReference<>() {
});
} catch (Exception e) {
e.printStackTrace();
return Collections.emptyMap();
}
}


}