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

Task #3788: Add POST Request handler to give feedback

parent 558cdfce
No related merge requests found
......@@ -57,7 +57,12 @@ public class SessionController {
}
@RequestMapping(value="/session/{sessionkey}/feedback", method=RequestMethod.POST)
public boolean postFeedback(@PathVariable String sessionkey, @RequestBody int value, HttpServletResponse response) {
return false;
public String postFeedback(@PathVariable String sessionkey, @RequestBody int value, HttpServletResponse response) {
if (sessionService.postFeedback(sessionkey, value)) {
response.setStatus(HttpStatus.CREATED.value());
return null;
}
response.setStatus(HttpStatus.SERVICE_UNAVAILABLE.value());
return null;
}
}
......@@ -26,6 +26,6 @@ public interface ISessionService {
public Session getSession(String keyword);
public Feedback getFeedback(String keyword);
public void postFeedback(String keyword, int value);
public boolean postFeedback(String keyword, int value);
}
\ No newline at end of file
......@@ -18,6 +18,7 @@
*/
package de.thm.arsnova.services;
import java.io.IOException;
import java.net.URLEncoder;
import java.util.ArrayList;
import java.util.List;
......@@ -32,6 +33,7 @@ import org.springframework.security.core.userdetails.User;
import org.springframework.stereotype.Service;
import com.fourspaces.couchdb.Database;
import com.fourspaces.couchdb.Document;
import com.fourspaces.couchdb.View;
import com.fourspaces.couchdb.ViewResults;
......@@ -122,8 +124,40 @@ public class SessionService implements ISessionService {
}
@Override
public void postFeedback(String keyword, int value) {
public boolean postFeedback(String keyword, int value) {
String sessionId = this.getSessionId(keyword);
if (sessionId == null) return false;
Document feedback = new Document();
feedback.put("type", "understanding");
feedback.put("user", this.actualUserName());
feedback.put("sessionId", sessionId);
feedback.put("timestamp", System.currentTimeMillis());
switch (value) {
case 0:
feedback.put("value", "Bitte schneller");
break;
case 1:
feedback.put("value", "Kann folgen");
break;
case 2:
feedback.put("value", "Zu schnell");
break;
case 3:
feedback.put("value", "Nicht mehr dabei");
break;
default:
return false;
}
try {
database.saveDocument(feedback);
} catch (IOException e) {
return false;
}
return true;
}
private String getSessionId(String keyword) {
......
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