Created
July 8, 2022 20:33
-
-
Save bijay-shrestha/8aeedab9f33d866b9ddb93e0e21b200c to your computer and use it in GitHub Desktop.
Native Query Parse Example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package edu.miu.annapurnabe; | |
import edu.miu.annapurnabe.dto.response.MealResponseDetailDTO; | |
import java.time.LocalDate; | |
import java.time.format.DateTimeFormatter; | |
import java.util.ArrayList; | |
import java.util.List; | |
import java.util.function.Function; | |
/** | |
* @author bijayshrestha on 7/7/22 | |
* @project annapurna-be | |
*/ | |
public class DailyMealUtils { | |
public static Function<List<Object[]>, List<MealResponseDetailDTO>> | |
convertObjectListToResponse = (objects) -> { | |
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd"); | |
final Integer DAILY_MEAL_ID = 0; | |
final Integer DINE_TYPE_NAME = 1; | |
final Integer DAILY_MEAL_DATE = 2; | |
final Integer DAILY_MEAL_NAME = 3; | |
final Integer DAILY_MEAL_DESCRIPTION = 4; | |
final Integer CONTAINS_DAIRY = 5; | |
final Integer CONTAINS_GLUTEN = 6; | |
final Integer CONTAINS_SUGAR = 7; | |
List<MealResponseDetailDTO> responseDTOList = new ArrayList<>(); | |
objects.forEach(o -> { | |
MealResponseDetailDTO responseDTO = new MealResponseDetailDTO(); | |
responseDTO.setDailyMealId(Long.parseLong(o[DAILY_MEAL_ID].toString())); | |
responseDTO.setDineTypeName(o[DINE_TYPE_NAME].toString()); | |
responseDTO.setDailyMealDate(LocalDate.parse(o[DAILY_MEAL_DATE].toString(),formatter)); | |
responseDTO.setName(o[DAILY_MEAL_NAME].toString()); | |
responseDTO.setDescription(o[DAILY_MEAL_DESCRIPTION].toString()); | |
responseDTO.setContainsDairy(Boolean.parseBoolean(o[CONTAINS_DAIRY].toString())); | |
responseDTO.setContainsGluten(Boolean.parseBoolean(o[CONTAINS_GLUTEN].toString())); | |
responseDTO.setContainsSugar(Boolean.parseBoolean(o[CONTAINS_SUGAR].toString())); | |
responseDTOList.add(responseDTO); | |
}); | |
return responseDTOList; | |
}; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment