Taskgroup Datamodel

This commit is contained in:
Sebastian 2023-09-25 11:02:04 +02:00
parent 2517e8ab31
commit 2d32625d2c
7 changed files with 116 additions and 4 deletions

View File

@ -1,2 +1,12 @@
# TimeManager # 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/
```

View File

@ -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;
}
}

View File

@ -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<Taskgroup, Long> {
}

View File

@ -1,2 +0,0 @@
package core.services;public class InvalidConfigurationException {
}

View File

@ -1,14 +1,54 @@
package core.services; package core.services;
import core.api.models.properties.PropertyInfo; import core.api.models.properties.PropertyInfo;
import core.entities.PropertiesEntity;
import core.repositories.PropertyRepository; import core.repositories.PropertyRepository;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.parsing.PropertyEntry;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import java.util.Optional; import java.util.Optional;
@Service
public class PropertyService { 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<PropertyInfo> getProperty(PropertyName propertyName) {
Optional<PropertiesEntity> property = propertyRepository.findByName(propertyName.name());
return property.map(PropertyInfo::new);
}
public Optional<PropertiesEntity> getPropertyEntityByName(String name) {
return propertyRepository.findByName(name);
}
public boolean isPropertyEnabled(PropertyName propertyName) {
Optional<PropertiesEntity> 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
}
} }

View File

@ -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;
}
}