Skip to content
Snippets Groups Projects
Commit cab24784 authored by Paul-Christian Volkmer's avatar Paul-Christian Volkmer
Browse files

Prepare session controller for get and post of feedback

parent 5aecf29c
Branches
Tags
No related merge requests found
......@@ -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;
}
}
......@@ -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
......@@ -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");
}
}
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment