-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7ef3ab9
commit ab23ee4
Showing
11 changed files
with
465 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
84 changes: 84 additions & 0 deletions
84
.../kotlin/ch/schulealtendorf/sporttagpsa/controller/web/eventsheets/EventSheetController.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
/* | ||
* 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.controller.web.eventsheets | ||
|
||
import ch.schulealtendorf.sporttagpsa.business.athletics.DisciplineManager | ||
import ch.schulealtendorf.sporttagpsa.business.export.EventSheetDisciplineExport | ||
import ch.schulealtendorf.sporttagpsa.business.export.EventSheetExport | ||
import ch.schulealtendorf.sporttagpsa.business.export.ExportManager | ||
import ch.schulealtendorf.sporttagpsa.business.group.GroupManager | ||
import ch.schulealtendorf.sporttagpsa.controller.rest.BadRequestException | ||
import ch.schulealtendorf.sporttagpsa.controller.web.files.FileQualifier | ||
import ch.schulealtendorf.sporttagpsa.filesystem.FileSystem | ||
import org.springframework.http.MediaType | ||
import org.springframework.stereotype.Controller | ||
import org.springframework.web.bind.annotation.PostMapping | ||
import org.springframework.web.bind.annotation.RequestBody | ||
import org.springframework.web.bind.annotation.RequestMapping | ||
import org.springframework.web.bind.annotation.ResponseBody | ||
|
||
@Controller | ||
@RequestMapping("/api/web") | ||
class EventSheetController( | ||
private val exportManager: ExportManager, | ||
private val disciplineManager: DisciplineManager, | ||
private val groupManager: GroupManager, | ||
private val fileSystem: FileSystem | ||
) { | ||
|
||
@PostMapping("/event-sheets", consumes = [MediaType.APPLICATION_JSON_VALUE], produces = [MediaType.APPLICATION_JSON_VALUE]) | ||
@ResponseBody | ||
fun createEventSheets(@RequestBody data: List<EventSheetData>): FileQualifier { | ||
|
||
val exportData = EventSheetExport(data.map { | ||
|
||
val discipline = disciplineManager.getDiscipline(it.discipline) | ||
.orElseThrow { BadRequestException("The discipline does not exist: name=${it.discipline}") } | ||
|
||
val group = groupManager.getGroup(it.group) | ||
.orElseThrow { BadRequestException("The group does not exist: name=${it.group}") } | ||
|
||
EventSheetDisciplineExport(discipline, group, it.gender) | ||
}) | ||
|
||
val zip = exportManager.generateArchive(exportData) | ||
|
||
return FileQualifier( | ||
zip.absolutePath.removePrefix(fileSystem.getApplicationDir().absolutePath) | ||
) | ||
} | ||
} |
45 changes: 45 additions & 0 deletions
45
src/main/kotlin/ch/schulealtendorf/sporttagpsa/controller/web/eventsheets/Models.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
/* | ||
* 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.controller.web.eventsheets | ||
|
||
import ch.schulealtendorf.sporttagpsa.model.Gender | ||
|
||
data class EventSheetData( | ||
val discipline: String, | ||
val group: String, | ||
val gender: Gender | ||
) |
83 changes: 83 additions & 0 deletions
83
src/main/kotlin/ch/schulealtendorf/sporttagpsa/controller/web/files/FileController.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
/* | ||
* 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.controller.web.files | ||
|
||
import ch.schulealtendorf.sporttagpsa.controller.rest.NotFoundException | ||
import ch.schulealtendorf.sporttagpsa.filesystem.FileSystem | ||
import org.springframework.core.io.InputStreamResource | ||
import org.springframework.http.HttpHeaders | ||
import org.springframework.http.HttpStatus | ||
import org.springframework.http.MediaType | ||
import org.springframework.http.ResponseEntity | ||
import org.springframework.stereotype.Controller | ||
import org.springframework.web.bind.annotation.GetMapping | ||
import org.springframework.web.bind.annotation.PathVariable | ||
import org.springframework.web.bind.annotation.RequestMapping | ||
import java.io.File | ||
import java.io.FileInputStream | ||
|
||
/** | ||
* Controller to resolve files from the application dir. | ||
* | ||
* @author nmaerchy <billedtrain380@gmail.com> | ||
* @since 2.0.0 | ||
*/ | ||
@Controller | ||
@RequestMapping("/web/file") | ||
class FileController( | ||
private val fileSystem: FileSystem | ||
) { | ||
|
||
@GetMapping("/{file_qualifier}") | ||
fun getFile(@PathVariable("file_qualifier") fileQualifier: String): ResponseEntity<InputStreamResource> { | ||
|
||
val file: File = fileSystem.getApplicationDir().resolve(fileQualifier) | ||
|
||
if (file.exists().not()) | ||
throw NotFoundException("The file could not be found: qualifier=$fileQualifier") | ||
|
||
val headers = HttpHeaders().apply { | ||
contentType = MediaType.APPLICATION_OCTET_STREAM | ||
contentLength = file.length() | ||
setContentDispositionFormData("attachment", file.name) | ||
} | ||
|
||
val inputStreamResource = InputStreamResource(FileInputStream(file)) | ||
|
||
return ResponseEntity(inputStreamResource, headers, HttpStatus.OK) | ||
} | ||
} |
41 changes: 41 additions & 0 deletions
41
src/main/kotlin/ch/schulealtendorf/sporttagpsa/controller/web/files/Models.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
/* | ||
* 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.controller.web.files | ||
|
||
data class FileQualifier( | ||
val value: String | ||
) |
70 changes: 70 additions & 0 deletions
70
...h/schulealtendorf/sporttagpsa/controller/web/participantlist/ParticipantListController.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
/* | ||
* 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.controller.web.participantlist | ||
|
||
import ch.schulealtendorf.sporttagpsa.business.export.ExportManager | ||
import ch.schulealtendorf.sporttagpsa.business.export.ParticipantExport | ||
import ch.schulealtendorf.sporttagpsa.controller.web.files.FileQualifier | ||
import ch.schulealtendorf.sporttagpsa.filesystem.FileSystem | ||
import ch.schulealtendorf.sporttagpsa.model.Sport | ||
import org.springframework.http.MediaType | ||
import org.springframework.stereotype.Controller | ||
import org.springframework.web.bind.annotation.PostMapping | ||
import org.springframework.web.bind.annotation.RequestBody | ||
import org.springframework.web.bind.annotation.RequestMapping | ||
import org.springframework.web.bind.annotation.ResponseBody | ||
|
||
@Controller | ||
@RequestMapping("/api/web") | ||
class ParticipantListController( | ||
private val exportManager: ExportManager, | ||
private val fileSystem: FileSystem | ||
) { | ||
|
||
@PostMapping("/participant-list", consumes = [MediaType.APPLICATION_JSON_VALUE], produces = [MediaType.APPLICATION_JSON_VALUE]) | ||
@ResponseBody | ||
fun createParticipantList(@RequestBody data: List<Sport>): FileQualifier { | ||
|
||
val exportData = ParticipantExport(data) | ||
|
||
val zip = exportManager.generateArchive(exportData) | ||
|
||
return FileQualifier( | ||
zip.absolutePath.removePrefix(fileSystem.getApplicationDir().absolutePath) | ||
) | ||
} | ||
} |
Oops, something went wrong.