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 0000000000000000000000000000000000000000..f799488bea0b986ce1e2530e0c4c0d89ea1c3496 --- /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 6b39f27532a8c35964754274a7ee7e93b3ecb607..cdb21978fa5577aafe70af41c1c94a2586f5abc2 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; + } }