Skip to content

Commit

Permalink
Merge pull request #124 from CAUSOLDOUTMEN/feature/122-fix
Browse files Browse the repository at this point in the history
Fix: ResponseFoodDto에 생성시간 누락 반영 (#122)
  • Loading branch information
synoti21 authored Nov 28, 2023
2 parents 543963f + 4617685 commit 984b343
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,13 @@ public class ResponseFoodDto {
private String name;
private BaseNutrition baseNutrition;
private boolean favoriteChecked;
private LocalTime time;

public static ResponseFoodDto of(Long foodId, Long userId, String name, BaseNutrition baseNutrition, boolean favoriteChecked) {
return new ResponseFoodDto(foodId, userId, name, baseNutrition, favoriteChecked);
public static ResponseFoodDto of(Long foodId, Long userId, String name, BaseNutrition baseNutrition, boolean favoriteChecked, LocalTime time) {
return new ResponseFoodDto(foodId, userId, name, baseNutrition, favoriteChecked, time);
}

public static ResponseFoodDto from(Food food) {
return new ResponseFoodDto(food.getId(), food.getUser().getId(), food.getName(), food.getBaseNutrition(), food.isFavorite());
return new ResponseFoodDto(food.getId(), food.getUser().getId(), food.getName(), food.getBaseNutrition(), food.isFavorite(), food.getAddedTime().toLocalTime());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public List<ResponseFoodDto> getFoodListByDate(Long userId, LocalDate date){
List<Food> foodList = foodRepository.findAllByUserIdAndDateOrderByAddedTimeAsc(userId, date);
log.info(date.toString() + "의 "+ userId + "에게 조회된 음식 개수: " + foodList.size() + "개");
return foodList.stream()
.map(food -> ResponseFoodDto.of(food.getId(), food.getUser().getId(), food.getName(), food.getBaseNutrition(), food.isFavorite())).collect(Collectors.toList());
.map(food -> ResponseFoodDto.of(food.getId(), food.getUser().getId(), food.getName(), food.getBaseNutrition(), food.isFavorite(), food.getAddedTime().toLocalTime())).collect(Collectors.toList());
}

// 음식 정보 수정
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import org.springframework.web.context.WebApplicationContext;

import java.time.LocalDate;
import java.time.LocalTime;
import java.util.List;
import java.util.Map;

Expand Down Expand Up @@ -103,7 +104,7 @@ void testGetFoodListByDate() throws Exception {
int mm = 12;
LocalDate date = LocalDate.of(yy, mm, dd);

ResponseFoodDto food1 = ResponseFoodDto.of(testFoodId, testUserId,"test",testBaseNutrition,false);
ResponseFoodDto food1 = ResponseFoodDto.of(testFoodId, testUserId,"test",testBaseNutrition,false, LocalTime.of(12,0,0));

when(foodService.getFoodListByDate(any(Long.class), any(LocalDate.class))).thenReturn(List.of(food1));
ApiResponse<List<ResponseFoodDto>> expectedResponse = ApiResponse.success(List.of(food1), ResponseCode.FOOD_READ_SUCCESS.getMessage());
Expand Down

0 comments on commit 984b343

Please sign in to comment.