From e1877b493b446671ab44d3daf11c67182416bb59 Mon Sep 17 00:00:00 2001 From: Paul-Christian Volkmer <paul-christian.volkmer@mni.thm.de> Date: Wed, 13 Feb 2013 12:21:58 +0100 Subject: [PATCH] Added controller to get courses of actual logged in user --- .../arsnova/controller/CourseController.java | 63 +++++++++++++++++++ .../de/thm/arsnova/dao/StubDatabaseDao.java | 12 ++++ 2 files changed, 75 insertions(+) create mode 100644 src/main/java/de/thm/arsnova/controller/CourseController.java diff --git a/src/main/java/de/thm/arsnova/controller/CourseController.java b/src/main/java/de/thm/arsnova/controller/CourseController.java new file mode 100644 index 00000000..f799488b --- /dev/null +++ b/src/main/java/de/thm/arsnova/controller/CourseController.java @@ -0,0 +1,63 @@ +/* + * Copyright (C) 2012 THM webMedia + * + * This file is part of ARSnova. + * + * ARSnova is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * ARSnova is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ +package de.thm.arsnova.controller; + +import java.util.List; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; +import org.springframework.web.bind.annotation.ResponseBody; + +import de.thm.arsnova.connector.client.ConnectorClient; +import de.thm.arsnova.connector.model.Course; +import de.thm.arsnova.exceptions.NotFoundException; +import de.thm.arsnova.exceptions.UnauthorizedException; +import de.thm.arsnova.services.IUserService; + +@Controller +public class CourseController extends AbstractController { + + public static final Logger LOGGER = LoggerFactory.getLogger(CourseController.class); + + @Autowired + private ConnectorClient connectorClient; + + @Autowired + private IUserService userService; + + @RequestMapping(value = "/mycourses", method = RequestMethod.GET) + @ResponseBody + public final List<Course> myCourses() { + String username = userService.getCurrentUser().getUsername(); + + if (username == null) { + throw new UnauthorizedException(); + } + + if (connectorClient == null) { + throw new NotFoundException(); + } + + return connectorClient.getCourses(username).getCourse(); + } +} diff --git a/src/test/java/de/thm/arsnova/dao/StubDatabaseDao.java b/src/test/java/de/thm/arsnova/dao/StubDatabaseDao.java index 6b39f275..cdb21978 100644 --- a/src/test/java/de/thm/arsnova/dao/StubDatabaseDao.java +++ b/src/test/java/de/thm/arsnova/dao/StubDatabaseDao.java @@ -376,4 +376,16 @@ public class StubDatabaseDao implements IDatabaseDao { // TODO Auto-generated method stub return null; } + + @Override + public String getCourseId(String keyword) { + // TODO Auto-generated method stub + return null; + } + + @Override + public boolean isCourseSession(String keyword) { + // TODO Auto-generated method stub + return false; + } } -- GitLab