From ea7effdc42b1f2d4862179d6fefbd68a1aca1b65 Mon Sep 17 00:00:00 2001 From: Marcus Fihlon Date: Wed, 16 Oct 2024 16:49:32 +0200 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20Create=20basic=20event=20closes=20#?= =?UTF-8?q?669?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/org/komunumo/data/entity/Event.java | 31 ++++++++++++++ .../data/service/DatabaseService.java | 2 +- .../komunumo/data/service/EventService.java | 22 ++++++++++ .../db/migration/V1_0_0__initialization.sql | 15 +++++++ .../org/komunumo/data/entity/EventTest.java | 42 +++++++++++++++++++ 5 files changed, 111 insertions(+), 1 deletion(-) create mode 100644 src/main/java/org/komunumo/data/entity/Event.java create mode 100644 src/main/java/org/komunumo/data/service/EventService.java create mode 100644 src/test/java/org/komunumo/data/entity/EventTest.java diff --git a/src/main/java/org/komunumo/data/entity/Event.java b/src/main/java/org/komunumo/data/entity/Event.java new file mode 100644 index 00000000..df487db3 --- /dev/null +++ b/src/main/java/org/komunumo/data/entity/Event.java @@ -0,0 +1,31 @@ +/* + * Komunumo - Open Source Community Manager + * Copyright (C) Marcus Fihlon and the individual contributors to Komunumo. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published + * by the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program 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 Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ +package org.komunumo.data.entity; + +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +import java.time.Duration; +import java.time.LocalDateTime; + +public record Event(@Nullable Long id, + @NotNull String title, + @NotNull String subtitle, + @NotNull String description, + @Nullable LocalDateTime date, + @Nullable Duration duration) { } diff --git a/src/main/java/org/komunumo/data/service/DatabaseService.java b/src/main/java/org/komunumo/data/service/DatabaseService.java index b8885d2d..56b8d301 100644 --- a/src/main/java/org/komunumo/data/service/DatabaseService.java +++ b/src/main/java/org/komunumo/data/service/DatabaseService.java @@ -25,7 +25,7 @@ import org.springframework.stereotype.Service; @Service -public class DatabaseService implements DSLContextGetter, ConfigurationGetter, ConfigurationService { +public class DatabaseService implements DSLContextGetter, ConfigurationGetter, ConfigurationService, EventService { private final DSLContext dsl; diff --git a/src/main/java/org/komunumo/data/service/EventService.java b/src/main/java/org/komunumo/data/service/EventService.java new file mode 100644 index 00000000..4e78b3a0 --- /dev/null +++ b/src/main/java/org/komunumo/data/service/EventService.java @@ -0,0 +1,22 @@ +/* + * Komunumo - Open Source Community Manager + * Copyright (C) Marcus Fihlon and the individual contributors to Komunumo. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published + * by the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program 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 Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ +package org.komunumo.data.service; + +import org.komunumo.data.service.getter.DSLContextGetter; + +interface EventService extends DSLContextGetter { } diff --git a/src/main/resources/db/migration/V1_0_0__initialization.sql b/src/main/resources/db/migration/V1_0_0__initialization.sql index 134434fc..21a8f369 100644 --- a/src/main/resources/db/migration/V1_0_0__initialization.sql +++ b/src/main/resources/db/migration/V1_0_0__initialization.sql @@ -4,3 +4,18 @@ CREATE TABLE `configuration` ( PRIMARY KEY (`conf_key`) ); + +CREATE TABLE `event` ( + `id` BIGINT NOT NULL AUTO_INCREMENT, + + `title` VARCHAR(255) NOT NULL, + `subtitle` VARCHAR(255) NOT NULL DEFAULT '', + `description` MEDIUMTEXT NOT NULL DEFAULT '', + + `date` DATETIME NULL, + `duration` TIME NULL, + + PRIMARY KEY (`id`) +); + +CREATE INDEX `event_date` ON `event` (`date`); diff --git a/src/test/java/org/komunumo/data/entity/EventTest.java b/src/test/java/org/komunumo/data/entity/EventTest.java new file mode 100644 index 00000000..5b3ced42 --- /dev/null +++ b/src/test/java/org/komunumo/data/entity/EventTest.java @@ -0,0 +1,42 @@ +/* + * Komunumo - Open Source Community Manager + * Copyright (C) Marcus Fihlon and the individual contributors to Komunumo. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published + * by the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program 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 Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ +package org.komunumo.data.entity; + +import org.junit.jupiter.api.Test; + +import java.time.Duration; +import java.time.LocalDateTime; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +class EventTest { + + @Test + void testEvent() { + final var testEvent = new Event(1L, "Foobar", "This is a test", "I am a description.", + LocalDateTime.of(2024, 10, 16, 18, 15), Duration.ofHours(1)); + + assertEquals(1L, testEvent.id()); + assertEquals("Foobar", testEvent.title()); + assertEquals("This is a test", testEvent.subtitle()); + assertEquals("I am a description.", testEvent.description()); + assertEquals(LocalDateTime.of(2024, 10, 16, 18, 15), testEvent.date()); + assertEquals(Duration.ofHours(1), testEvent.duration()); + } + +}