diff --git a/src/main/java/de/thm/arsnova/SessionController.java b/src/main/java/de/thm/arsnova/SessionController.java index 5cc061b9a0158ad27a468ff553717d841fe46888..57c07d402b25f7f2882b0395be75c315dc93e177 100644 --- a/src/main/java/de/thm/arsnova/SessionController.java +++ b/src/main/java/de/thm/arsnova/SessionController.java @@ -18,13 +18,17 @@ */ package de.thm.arsnova; +import java.util.List; + import javax.servlet.http.HttpServletResponse; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.HttpStatus; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; import de.thm.arsnova.entities.Session; import de.thm.arsnova.services.ISessionService; @@ -43,4 +47,22 @@ public class SessionController { response.setStatus(HttpStatus.NOT_FOUND.value()); return null; } + + @RequestMapping(value="/session/{sessionkey}/feedback", method=RequestMethod.GET) + public List<Integer> getFeedback(@PathVariable String sessionkey, HttpServletResponse response) { + List<Integer> feedback = sessionService.getFeedback(sessionkey); + if (feedback != null) return feedback; + + response.setStatus(HttpStatus.NOT_FOUND.value()); + return null; + } + + @RequestMapping(value="/session/{sessionkey}/feedback", method=RequestMethod.POST) + public List<Integer> postFeedback(@PathVariable String sessionkey, @RequestBody int value, HttpServletResponse response) { + List<Integer> feedback = sessionService.getFeedback(sessionkey); + if (feedback != null) return feedback; + + response.setStatus(HttpStatus.NOT_FOUND.value()); + return null; + } } diff --git a/src/main/java/de/thm/arsnova/services/ISessionService.java b/src/main/java/de/thm/arsnova/services/ISessionService.java index 97f6ed6035a07f37b19f1c5770cf776264d4a8d6..949ebee34a2354671619568ee2d919d0950844af 100644 --- a/src/main/java/de/thm/arsnova/services/ISessionService.java +++ b/src/main/java/de/thm/arsnova/services/ISessionService.java @@ -18,11 +18,15 @@ */ package de.thm.arsnova.services; +import java.util.List; + import de.thm.arsnova.entities.Session; public interface ISessionService { public Session getSession(String keyword); + public List<Integer> getFeedback(String keyword); + public void postFeedback(String keyword, int value); } \ No newline at end of file diff --git a/src/main/java/de/thm/arsnova/services/SessionService.java b/src/main/java/de/thm/arsnova/services/SessionService.java index f10b9522c104130637fde710ad58bf76d8ac1ed0..962a923e39230e5240b9580b2eb59a674fd6a599 100644 --- a/src/main/java/de/thm/arsnova/services/SessionService.java +++ b/src/main/java/de/thm/arsnova/services/SessionService.java @@ -19,6 +19,8 @@ package de.thm.arsnova.services; import java.net.URLEncoder; +import java.util.ArrayList; +import java.util.List; import net.sf.json.JSONObject; @@ -36,15 +38,15 @@ import de.thm.arsnova.entities.Session; public class SessionService implements ISessionService { private final com.fourspaces.couchdb.Session session = new com.fourspaces.couchdb.Session("localhost", 5984); - public static final Logger logger = LoggerFactory - .getLogger(SessionService.class); - + private final Database database = session.getDatabase("arsnova"); + + public static final Logger logger = LoggerFactory.getLogger(SessionService.class); + @Override public Session getSession(String keyword) { - Database db = session.getDatabase("arsnova"); View view = new View("session/by_keyword"); view.setKey(URLEncoder.encode("\""+keyword+"\"")); - ViewResults results = db.view(view); + ViewResults results = database.view(view); if (results.getJSONArray("rows").optJSONObject(0) == null) return null; @@ -55,4 +57,37 @@ public class SessionService implements ISessionService { return null; } + @Override + public List<Integer> getFeedback(String keyword) { + String sessionId = this.getSessionId(keyword); + if (sessionId == null) return null; + + View view = new View("understanding/by_session"); + view.setGroup(true); + view.setStartKey(URLEncoder.encode("[\""+sessionId+"\"]")); + view.setEndKey(URLEncoder.encode("[\""+sessionId+"\"],{}")); + ViewResults results = database.view(view); + + //if (results.getJSONArray("rows").optJSONObject(0) == null) return null; + + logger.info("Feedback: {}", results.getJSONObject("rows")); + + return null; + } + + @Override + public void postFeedback(String keyword, int value) { + + } + + private String getSessionId(String keyword) { + View view = new View("session/by_keyword"); + view.setKey(URLEncoder.encode("\""+keyword+"\"")); + ViewResults results = database.view(view); + + if (results.getJSONArray("rows").optJSONObject(0) == null) return null; + + return results.getJSONArray("rows").optJSONObject(0).optJSONObject("value").getString("_id"); + } + }