From e5685891817bf048623f0c0b848816a2a4e01a13 Mon Sep 17 00:00:00 2001 From: Jottyfan Date: Sat, 13 Jan 2024 15:59:57 +0100 Subject: [PATCH] added download option, see #1 --- build.gradle | 2 +- .../modules/download/DownloadController.java | 29 +++++++++++++++++ .../modules/download/DownloadRepository.java | 31 +++++++++++++++++++ .../modules/download/DownloadService.java | 20 ++++++++++++ src/main/resources/templates/template.html | 1 + 5 files changed, 82 insertions(+), 1 deletion(-) create mode 100644 src/main/java/de/jottyfan/bico/modules/download/DownloadController.java create mode 100644 src/main/java/de/jottyfan/bico/modules/download/DownloadRepository.java create mode 100644 src/main/java/de/jottyfan/bico/modules/download/DownloadService.java diff --git a/build.gradle b/build.gradle index b24f81d..c217ceb 100644 --- a/build.gradle +++ b/build.gradle @@ -8,7 +8,7 @@ plugins { } group = 'de.jottyfan.bico' -version = '0.0.8' +version = '0.0.9' description = """BibleClassOrganizer""" diff --git a/src/main/java/de/jottyfan/bico/modules/download/DownloadController.java b/src/main/java/de/jottyfan/bico/modules/download/DownloadController.java new file mode 100644 index 0000000..726c140 --- /dev/null +++ b/src/main/java/de/jottyfan/bico/modules/download/DownloadController.java @@ -0,0 +1,29 @@ +package de.jottyfan.bico.modules.download; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.HttpStatus; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.ResponseBody; +import org.springframework.web.bind.annotation.ResponseStatus; + +import de.jottyfan.bico.modules.CommonController; + +/** + * + * @author jotty + * + */ +@Controller +public class DownloadController extends CommonController { + + @Autowired + private DownloadService service; + + @GetMapping(value = "/download", produces = "text/csv") + @ResponseBody + @ResponseStatus(HttpStatus.OK) + public String download() { + return service.getCsv(); + } +} diff --git a/src/main/java/de/jottyfan/bico/modules/download/DownloadRepository.java b/src/main/java/de/jottyfan/bico/modules/download/DownloadRepository.java new file mode 100644 index 0000000..7d019a9 --- /dev/null +++ b/src/main/java/de/jottyfan/bico/modules/download/DownloadRepository.java @@ -0,0 +1,31 @@ +package de.jottyfan.bico.modules.download; + +import static de.jottyfan.bico.db.Tables.V_CALENDAR; + +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; +import org.jooq.DSLContext; +import org.jooq.SelectWhereStep; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Repository; + +import de.jottyfan.bico.db.tables.records.VCalendarRecord; + +/** + * + * @author jotty + * + */ +@Repository +public class DownloadRepository { + private static final Logger LOGGER = LogManager.getLogger(DownloadRepository.class); + + @Autowired + private DSLContext jooq; + + public String getCsv() { + SelectWhereStep sql = jooq.selectFrom(V_CALENDAR); + LOGGER.trace(sql); + return sql.fetch().formatCSV(); + } +} diff --git a/src/main/java/de/jottyfan/bico/modules/download/DownloadService.java b/src/main/java/de/jottyfan/bico/modules/download/DownloadService.java new file mode 100644 index 0000000..f83bf23 --- /dev/null +++ b/src/main/java/de/jottyfan/bico/modules/download/DownloadService.java @@ -0,0 +1,20 @@ +package de.jottyfan.bico.modules.download; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +/** + * + * @author jotty + * + */ +@Service +public class DownloadService { + + @Autowired + private DownloadRepository repository; + + public String getCsv() { + return repository.getCsv(); + } +} diff --git a/src/main/resources/templates/template.html b/src/main/resources/templates/template.html index 2fcc1bb..8513a92 100644 --- a/src/main/resources/templates/template.html +++ b/src/main/resources/templates/template.html @@ -24,6 +24,7 @@