From 2d32625d2cbc7a972314bcbdb516145906057576 Mon Sep 17 00:00:00 2001 From: Sebastian Date: Mon, 25 Sep 2023 11:02:04 +0200 Subject: [PATCH] Taskgroup Datamodel --- README.md | 10 +++++ backend/configuration.properties | 0 .../core/entities/timemanager/Taskgroup.java | 40 +++++++++++++++++ .../timemanager/TaskgroupRepository.java | 9 ++++ .../InvalidConfigurationException.java | 2 - .../java/core/services/PropertyService.java | 44 ++++++++++++++++++- .../java/core/services/TaskgroupService.java | 15 +++++++ 7 files changed, 116 insertions(+), 4 deletions(-) delete mode 100644 backend/configuration.properties create mode 100644 backend/src/main/java/core/entities/timemanager/Taskgroup.java create mode 100644 backend/src/main/java/core/repositories/timemanager/TaskgroupRepository.java delete mode 100644 backend/src/main/java/core/services/InvalidConfigurationException.java create mode 100644 backend/src/main/java/core/services/TaskgroupService.java diff --git a/README.md b/README.md index b3b10b8..062ad25 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,12 @@ # TimeManager +Template für einen Spring-Angular-Service +## Generate Angular Client Code with OpenAPI Generator +1. Install the latest version of "openapi-generator-cli" +```bash +npm install @openapitools/openapi-generator-cli -g +``` +2. Generate Code +```bash +npx @openapitools/openapi-generator-cli generate -i openapi.yaml -g typescript-angular -o frontend/src/api/ +``` \ No newline at end of file diff --git a/backend/configuration.properties b/backend/configuration.properties deleted file mode 100644 index e69de29..0000000 diff --git a/backend/src/main/java/core/entities/timemanager/Taskgroup.java b/backend/src/main/java/core/entities/timemanager/Taskgroup.java new file mode 100644 index 0000000..1738a2c --- /dev/null +++ b/backend/src/main/java/core/entities/timemanager/Taskgroup.java @@ -0,0 +1,40 @@ +package core.entities.timemanager; + +import javax.persistence.*; +import javax.validation.constraints.NotBlank; + +@Entity +@Table(name= "taskgroups") +public class Taskgroup { + + @Id + @GeneratedValue(strategy = GenerationType.AUTO) + private long taskgroupID; + + @NotBlank + @Column(name = "name", length = 255) + private String taskgroupName; + + public Taskgroup(String taskgroupName) { + this.taskgroupName = taskgroupName; + } + + public Taskgroup() { + } + + public long getTaskgroupID() { + return taskgroupID; + } + + public void setTaskgroupID(long taskgroupID) { + this.taskgroupID = taskgroupID; + } + + public String getTaskgroupName() { + return taskgroupName; + } + + public void setTaskgroupName(String taskgroupName) { + this.taskgroupName = taskgroupName; + } +} diff --git a/backend/src/main/java/core/repositories/timemanager/TaskgroupRepository.java b/backend/src/main/java/core/repositories/timemanager/TaskgroupRepository.java new file mode 100644 index 0000000..0199806 --- /dev/null +++ b/backend/src/main/java/core/repositories/timemanager/TaskgroupRepository.java @@ -0,0 +1,9 @@ +package core.repositories.timemanager; + +import core.entities.timemanager.Taskgroup; +import org.springframework.data.repository.CrudRepository; +import org.springframework.stereotype.Repository; + +@Repository +public interface TaskgroupRepository extends CrudRepository { +} diff --git a/backend/src/main/java/core/services/InvalidConfigurationException.java b/backend/src/main/java/core/services/InvalidConfigurationException.java deleted file mode 100644 index 501c4c7..0000000 --- a/backend/src/main/java/core/services/InvalidConfigurationException.java +++ /dev/null @@ -1,2 +0,0 @@ -package core.services;public class InvalidConfigurationException { -} diff --git a/backend/src/main/java/core/services/PropertyService.java b/backend/src/main/java/core/services/PropertyService.java index 7f9dfa3..fda0d25 100644 --- a/backend/src/main/java/core/services/PropertyService.java +++ b/backend/src/main/java/core/services/PropertyService.java @@ -1,14 +1,54 @@ package core.services; import core.api.models.properties.PropertyInfo; +import core.entities.PropertiesEntity; import core.repositories.PropertyRepository; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.parsing.PropertyEntry; import org.springframework.stereotype.Service; import java.util.Optional; - +@Service public class PropertyService { - + @Autowired + private PropertyRepository propertyRepository; + + + + public void init() { + PropertiesEntity registrationEntity = new PropertiesEntity(PropertyName.REGISTRATION_PROPERTY_NAME.name(), true); + if(!propertyRepository.existsByName(registrationEntity.getName())) { + propertyRepository.save(registrationEntity); + } + } + + public Optional getProperty(PropertyName propertyName) { + Optional property = propertyRepository.findByName(propertyName.name()); + return property.map(PropertyInfo::new); + } + + public Optional getPropertyEntityByName(String name) { + return propertyRepository.findByName(name); + } + + public boolean isPropertyEnabled(PropertyName propertyName) { + Optional property = propertyRepository.findByName(propertyName.name()); + return property.map(PropertiesEntity::isStatus).orElseGet(() -> getDefaultBehaivior(propertyName)); + } + + public boolean getDefaultBehaivior(PropertyName propertyName) { + return switch (propertyName) { + case REGISTRATION_PROPERTY_NAME -> true; + }; + } + + public void savePropertyEntity(PropertiesEntity property) { + propertyRepository.save(property); + } + + public enum PropertyName { + REGISTRATION_PROPERTY_NAME + } } diff --git a/backend/src/main/java/core/services/TaskgroupService.java b/backend/src/main/java/core/services/TaskgroupService.java new file mode 100644 index 0000000..aa3f180 --- /dev/null +++ b/backend/src/main/java/core/services/TaskgroupService.java @@ -0,0 +1,15 @@ +package core.services; + +import core.repositories.timemanager.TaskgroupRepository; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +@Service +public class TaskgroupService { + + private final TaskgroupRepository taskgroupRepository; + + public TaskgroupService(@Autowired TaskgroupRepository taskgroupRepository) { + this.taskgroupRepository = taskgroupRepository; + } +}