@Test
 public void testDelete() throws Exception {
   mockMvc
       .perform(
           delete(REST_URL + MEAL1_ID)
               .contentType(MediaType.APPLICATION_JSON)
               .with(userHttpBasic(USER)))
       .andExpect(status().isOk());
   MATCHER.assertCollectionEquals(
       Arrays.asList(MEAL6, MEAL5, MEAL4, MEAL3, MEAL2), service.getAll(START_SEQ));
 }
  @Test
  public void testUpdate() throws Exception {
    UserMeal updated = getUpdated();

    mockMvc
        .perform(
            put(REST_URL + MEAL1_ID)
                .contentType(MediaType.APPLICATION_JSON)
                .content(JsonUtil.writeValue(updated))
                .with(userHttpBasic(USER)))
        .andExpect(status().isOk());

    assertEquals(updated, service.get(MEAL1_ID, START_SEQ));
  }
 public List<UserMealWithExceed> getBetween(
     LocalDate startDate, LocalTime startTime, LocalDate endDate, LocalTime endTime) {
   int userId = LoggedUser.id();
   LOG.info(
       "getBetween dates {} - {} for time {} - {} for User {}",
       startDate,
       endDate,
       startTime,
       endTime,
       userId);
   return UserMealsUtil.getFilteredWithExceeded(
       service.getBetweenDates(startDate, endDate, userId),
       startTime,
       endTime,
       LoggedUser.getCaloriesPerDay());
 }
  @Test
  public void testCreate() throws Exception {
    UserMeal created = getCreated();
    ResultActions action =
        mockMvc.perform(
            post(REST_URL)
                .contentType(MediaType.APPLICATION_JSON)
                .content(JsonUtil.writeValue(created))
                .with(userHttpBasic(ADMIN)));

    UserMeal returned = MATCHER.fromJsonAction(action);
    created.setId(returned.getId());

    MATCHER.assertEquals(created, returned);
    MATCHER.assertCollectionEquals(
        Arrays.asList(ADMIN_MEAL2, created, ADMIN_MEAL), service.getAll(ADMIN_ID));
  }
 public UserMeal create(UserMeal meal) {
   meal.setId(null);
   int userId = LoggedUser.id();
   LOG.info("create {} for User {}", meal, userId);
   return service.save(meal, userId);
 }
 public void update(UserMeal meal, int id) {
   meal.setId(id);
   int userId = LoggedUser.id();
   LOG.info("update {} for User {}", meal, userId);
   service.update(meal, userId);
 }
 public List<UserMealWithExceed> getAll() {
   int userId = LoggedUser.id();
   LOG.info("getAll for User {}", userId);
   return UserMealsUtil.getWithExceeded(service.getAll(userId), LoggedUser.getCaloriesPerDay());
 }
 public void delete(int id) {
   int userId = LoggedUser.id();
   LOG.info("delete meal {} for User {}", id, userId);
   service.delete(id, userId);
 }
 public UserMeal get(int id) {
   int userId = LoggedUser.id();
   LOG.info("get meal {} for User {}", id, userId);
   return service.get(id, userId);
 }