package com.projectning.service.web;

import java.time.Duration;
import java.time.Instant;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import com.projectning.service.domain.Moment;
import com.projectning.service.manager.MomentManager;
import com.projectning.service.manager.UserManager;
import com.projectning.util.Util;

@Controller
public class MomentController {
	
	@Autowired private UserManager userManager;
	@Autowired private MomentManager momentManager;
	
	@RequestMapping("/get_recent_moments")
    public ResponseEntity<Map<String, Object>> uploadImage(@RequestBody Map<String, Object> request) {
		Map<String, Object> respond = new HashMap<String, Object>();
		try{
			//int id = userManager.validateAccessToken(request);
			
			List<Moment> momentList = momentManager.getRecentMomentByDate(4, Instant.now().minus(Duration.ofDays(1)), 10);
			List<Map<String, Object>> processedMomentList = new ArrayList<Map<String, Object>>();
			
			for(Moment m : momentList){
				Map<String, Object> processedMoment = new HashMap<String, Object>();
				processedMoment.put("momenrId", m.getId());
				processedMoment.put("momentBody", m.getBody());
				processedMoment.put("createdAt", m.getCreatedAt().toString());
				processedMomentList.add(processedMoment);
			}
			respond.put("momentList", processedMomentList);
			respond.put("checkPoint", momentList.get(momentList.size() - 1).getCreatedAt().toString());
			respond.put("error", "");
		}catch(Exception e){
			respond = Util.createErrorRespondFromException(e);
		}
		return new ResponseEntity<Map<String, Object>>(respond, HttpStatus.OK);
		
	}

}

@@ -35,35 +35,8 @@
 b;%0A%0A
-import java.time.Duration;%0A
 impo
@@ -1035,19 +1035,8 @@
 %0A%09%09%09
-//int id = 
 user
@@ -1072,24 +1072,368 @@
 equest);%0A%09%09%09
+int userId = (int)request.get(%22userId%22);%0A%09%09%09int limit = 10;%0A%09%09%09try%7B%0A%09%09%09%09limit = (int)request.get(%22limit%22);%0A%09%09%09%7Dcatch(NullPointerException e)%7B%0A%09%09%09%09//%0A%09%09%09%7D%0A%09%09%09Instant checkPoint = Instant.now();%0A%09%09%09try%7B%0A%09%09%09%09String timeStr = (String)request.get(%22checkPoint%22);%0A%09%09%09%09checkPoint = Instant.parse(timeStr);%0A%09%09%09%7Dcatch(NullPointerException e)%7B%0A%09%09%09%09//%0A%09%09%09%7D
 %0A%09%09%09List%3CMom
@@ -1490,54 +1490,33 @@
 ate(
-4, Instant.now().minus(Duration.ofDays(1)), 10
+userId, checkPoint, limit
 );%0A%09

Tweak get recent moment method to get it work