Skip to content

Commit

Permalink
Add sport controller
Browse files Browse the repository at this point in the history
  • Loading branch information
BilledTrain380 committed Aug 31, 2018
1 parent f48641d commit f89f6fd
Show file tree
Hide file tree
Showing 4 changed files with 121 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/*
* Copyright (c) 2018 by Nicolas Märchy
*
* This file is part of Sporttag PSA.
*
* Sporttag PSA 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.
*
* Sporttag PSA 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 Sporttag PSA. If not, see <http://www.gnu.org/licenses/>.
*
* Diese Datei ist Teil von Sporttag PSA.
*
* Sporttag PSA ist Freie Software: Sie können es unter den Bedingungen
* der GNU General Public License, wie von der Free Software Foundation,
* Version 3 der Lizenz oder (nach Ihrer Wahl) jeder späteren
* veröffentlichten Version, weiterverbreiten und/oder modifizieren.
*
* Sporttag PSA wird in der Hoffnung, dass es nützlich sein wird, aber
* OHNE JEDE GEWÄHRLEISTUNG, bereitgestellt; sogar ohne die implizite
* Gewährleistung der MARKTFÄHIGKEIT oder EIGNUNG FÜR EINEN BESTIMMTEN ZWECK.
* Siehe die GNU General Public License für weitere Details.
*
* Sie sollten eine Kopie der GNU General Public License zusammen mit diesem
* Programm erhalten haben. Wenn nicht, siehe <http://www.gnu.org/licenses/>.
*
*
*/

package ch.schulealtendorf.sporttagpsa.business.participation

import ch.schulealtendorf.sporttagpsa.model.Sport

/**
* Describes a manager for {@link Sport} related data.
*
* @author nmaerchy <billedtrain380@gmail.com>
* @since 2.0.0
*/
interface SportManager {

/**
* @return all sport types
*/
fun getSports(): List<Sport>
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/*
* Copyright (c) 2018 by Nicolas Märchy
*
* This file is part of Sporttag PSA.
*
* Sporttag PSA 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.
*
* Sporttag PSA 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 Sporttag PSA. If not, see <http://www.gnu.org/licenses/>.
*
* Diese Datei ist Teil von Sporttag PSA.
*
* Sporttag PSA ist Freie Software: Sie können es unter den Bedingungen
* der GNU General Public License, wie von der Free Software Foundation,
* Version 3 der Lizenz oder (nach Ihrer Wahl) jeder späteren
* veröffentlichten Version, weiterverbreiten und/oder modifizieren.
*
* Sporttag PSA wird in der Hoffnung, dass es nützlich sein wird, aber
* OHNE JEDE GEWÄHRLEISTUNG, bereitgestellt; sogar ohne die implizite
* Gewährleistung der MARKTFÄHIGKEIT oder EIGNUNG FÜR EINEN BESTIMMTEN ZWECK.
* Siehe die GNU General Public License für weitere Details.
*
* Sie sollten eine Kopie der GNU General Public License zusammen mit diesem
* Programm erhalten haben. Wenn nicht, siehe <http://www.gnu.org/licenses/>.
*
*
*/

package ch.schulealtendorf.sporttagpsa.business.participation

import ch.schulealtendorf.sporttagpsa.model.Sport
import ch.schulealtendorf.sporttagpsa.repository.SportRepository
import org.springframework.stereotype.Component

/**
* {@link SportRepository} implementation with repositories.
*
* @author nmaerchy <billedtrain380@gmail.com>
* @since 2.0.0
*/
@Component
class SportManagerImpl(
private val sportRepository: SportRepository
): SportManager {

override fun getSports(): List<Sport> {
return sportRepository.findAll().map { Sport(it.name) }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ class WebConfig: WebMvcConfigurer {
*/
override fun addCorsMappings(registry: CorsRegistry) {
registry.addMapping("/**")
.allowedMethods("GET", "POST", "PUT", "DELETE")
.allowedMethods("GET", "POST", "PATCH", "PUT", "DELETE")
.allowedOrigins("*")
.allowedHeaders("*");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,23 @@

package ch.schulealtendorf.sporttagpsa.controller.rest.sport

import ch.schulealtendorf.sporttagpsa.business.participation.SportManager
import ch.schulealtendorf.sporttagpsa.model.Sport
import org.springframework.http.MediaType
import org.springframework.web.bind.annotation.GetMapping
import org.springframework.web.bind.annotation.RestController

/**
* @author nmaerchy <billedtrain380@gmail.com>
* @since 2.0.0
*/
class SportController() {
@RestController
class SportController(
private val sportManager: SportManager
) {

@GetMapping("/sports", produces = [MediaType.APPLICATION_JSON_VALUE])
fun getSports(): List<Sport> {
return listOf()
return sportManager.getSports()
}
}

0 comments on commit f89f6fd

Please sign in to comment.