Skip to content

Commit

Permalink
✨ Create basic event closes #669
Browse files Browse the repository at this point in the history
  • Loading branch information
McPringle committed Oct 16, 2024
1 parent 76fb3cc commit ea7effd
Show file tree
Hide file tree
Showing 5 changed files with 111 additions and 1 deletion.
31 changes: 31 additions & 0 deletions src/main/java/org/komunumo/data/entity/Event.java
Original file line number Diff line number Diff line change
@@ -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 <http://www.gnu.org/licenses/>.
*/
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) { }
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
22 changes: 22 additions & 0 deletions src/main/java/org/komunumo/data/service/EventService.java
Original file line number Diff line number Diff line change
@@ -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 <http://www.gnu.org/licenses/>.
*/
package org.komunumo.data.service;

import org.komunumo.data.service.getter.DSLContextGetter;

interface EventService extends DSLContextGetter { }
15 changes: 15 additions & 0 deletions src/main/resources/db/migration/V1_0_0__initialization.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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`);
42 changes: 42 additions & 0 deletions src/test/java/org/komunumo/data/entity/EventTest.java
Original file line number Diff line number Diff line change
@@ -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 <http://www.gnu.org/licenses/>.
*/
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());
}

}

0 comments on commit ea7effd

Please sign in to comment.