Compare commits
3
Commits
1f7dfee78f
...
97d86cd11a
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
97d86cd11a | ||
|
|
6985e0ea87 | ||
|
|
a0cf2d1854 |
No files matched your search
@@ -22,6 +22,7 @@
|
|||||||
</properties>
|
</properties>
|
||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
|
<!-- Spring libs -->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.springframework.boot</groupId>
|
<groupId>org.springframework.boot</groupId>
|
||||||
<artifactId>spring-boot-starter-web</artifactId>
|
<artifactId>spring-boot-starter-web</artifactId>
|
||||||
@@ -30,18 +31,12 @@
|
|||||||
<groupId>org.springframework.boot</groupId>
|
<groupId>org.springframework.boot</groupId>
|
||||||
<artifactId>spring-boot-starter-data-jdbc</artifactId>
|
<artifactId>spring-boot-starter-data-jdbc</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<!-- CSV handling -->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.h2database</groupId>
|
<groupId>com.fasterxml.jackson.dataformat</groupId>
|
||||||
<artifactId>h2</artifactId>
|
<artifactId>jackson-dataformat-csv</artifactId>
|
||||||
<scope>runtime</scope>
|
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<!-- OpenAPI generation -->
|
||||||
<groupId>org.projectlombok</groupId>
|
|
||||||
<artifactId>lombok</artifactId>
|
|
||||||
<optional>true</optional>
|
|
||||||
</dependency>
|
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.springdoc</groupId>
|
<groupId>org.springdoc</groupId>
|
||||||
<artifactId>springdoc-openapi-ui</artifactId>
|
<artifactId>springdoc-openapi-ui</artifactId>
|
||||||
@@ -52,7 +47,18 @@
|
|||||||
<artifactId>jackson-databind-nullable</artifactId>
|
<artifactId>jackson-databind-nullable</artifactId>
|
||||||
<version>0.2.6</version>
|
<version>0.2.6</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<!-- DB driver - change to other driver on DB change -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.h2database</groupId>
|
||||||
|
<artifactId>h2</artifactId>
|
||||||
|
<scope>runtime</scope>
|
||||||
|
</dependency>
|
||||||
|
<!-- confinience -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.projectlombok</groupId>
|
||||||
|
<artifactId>lombok</artifactId>
|
||||||
|
<optional>true</optional>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
<!-- testing -->
|
<!-- testing -->
|
||||||
<dependency>
|
<dependency>
|
||||||
@@ -60,6 +66,11 @@
|
|||||||
<artifactId>spring-boot-starter-test</artifactId>
|
<artifactId>spring-boot-starter-test</artifactId>
|
||||||
<scope>test</scope>
|
<scope>test</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.mockito</groupId>
|
||||||
|
<artifactId>mockito-core</artifactId>
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
<build>
|
<build>
|
||||||
@@ -79,7 +90,7 @@
|
|||||||
</inputSpec>
|
</inputSpec>
|
||||||
<generatorName>spring</generatorName>
|
<generatorName>spring</generatorName>
|
||||||
<apiPackage>de.etecture.ga.api</apiPackage>
|
<apiPackage>de.etecture.ga.api</apiPackage>
|
||||||
<modelPackage>de.etecture.ga.model</modelPackage>
|
<modelPackage>de.etecture.ga.dto</modelPackage>
|
||||||
<supportingFilesToGenerate>
|
<supportingFilesToGenerate>
|
||||||
ApiUtil.java
|
ApiUtil.java
|
||||||
</supportingFilesToGenerate>
|
</supportingFilesToGenerate>
|
||||||
|
|||||||
@@ -0,0 +1,46 @@
|
|||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
package de.etecture.ga.api;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.springframework.http.ResponseEntity;
|
||||||
|
|
||||||
|
import de.etecture.ga.dto.Termin;
|
||||||
|
import de.etecture.ga.dto.TerminRequest;
|
||||||
|
import jakarta.validation.Valid;
|
||||||
|
import jakarta.validation.constraints.NotNull;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public class GarageApiController implements WerkstattApi {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ResponseEntity<Termin> getTermin(String werkstattId, String terminId) {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
return WerkstattApi.super.getTermin(werkstattId, terminId);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ResponseEntity<List<Termin>> getTermine(String werkstattId, @Valid String von, @Valid String bis,
|
||||||
|
@Valid String leistungsId) {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
return WerkstattApi.super.getTermine(werkstattId, von, bis, leistungsId);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ResponseEntity<List<Termin>> getTerminvorschlaege(String werkstattId, @NotNull @Valid String leistungsId,
|
||||||
|
@Valid String von, @Valid String bis) {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
return WerkstattApi.super.getTerminvorschlaege(werkstattId, leistungsId, von, bis);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ResponseEntity<Termin> postTermin(String werkstattId, @Valid TerminRequest termin) {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
return WerkstattApi.super.postTermin(werkstattId, termin);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,40 @@
|
|||||||
|
package de.etecture.ga.config;
|
||||||
|
|
||||||
|
import java.time.Duration;
|
||||||
|
import java.time.temporal.ChronoUnit;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.springframework.core.convert.converter.Converter;
|
||||||
|
import org.springframework.data.convert.ReadingConverter;
|
||||||
|
import org.springframework.data.convert.WritingConverter;
|
||||||
|
import org.springframework.data.jdbc.repository.config.AbstractJdbcConfiguration;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
@Component
|
||||||
|
public class DataBaseConfiguration extends AbstractJdbcConfiguration {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected List<?> userConverters() {
|
||||||
|
return Arrays.asList(new DurationToLongConverter(), new LongToDurationConverter());
|
||||||
|
}
|
||||||
|
|
||||||
|
@WritingConverter
|
||||||
|
public class DurationToLongConverter implements Converter<Duration, Long> {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Long convert(Duration duration) {
|
||||||
|
return duration.toSeconds();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@ReadingConverter
|
||||||
|
public class LongToDurationConverter implements Converter<Long, Duration> {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Duration convert(Long duration) {
|
||||||
|
return Duration.of(duration, ChronoUnit.SECONDS);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,22 @@
|
|||||||
|
package de.etecture.ga.config;
|
||||||
|
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
import de.etecture.ga.service.GarageImportService;
|
||||||
|
import jakarta.annotation.PostConstruct;
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
|
||||||
|
@Slf4j
|
||||||
|
@Component
|
||||||
|
@AllArgsConstructor
|
||||||
|
public class Setup {
|
||||||
|
|
||||||
|
private final GarageImportService importService;
|
||||||
|
|
||||||
|
@PostConstruct
|
||||||
|
private void importData() {
|
||||||
|
|
||||||
|
importService.importGarageData();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,32 @@
|
|||||||
|
package de.etecture.ga.model;
|
||||||
|
|
||||||
|
import java.time.Duration;
|
||||||
|
import java.util.Date;
|
||||||
|
|
||||||
|
import org.springframework.data.annotation.Id;
|
||||||
|
import org.springframework.data.jdbc.core.mapping.AggregateReference;
|
||||||
|
import org.springframework.data.relational.core.mapping.Column;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.experimental.Accessors;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
@Accessors(fluent = true, chain = true)
|
||||||
|
public class Appointment {
|
||||||
|
|
||||||
|
@Id
|
||||||
|
private Long id;
|
||||||
|
|
||||||
|
@Column("GARAGE_ID")
|
||||||
|
private AggregateReference<Garage, Long> garageId;
|
||||||
|
|
||||||
|
private String serviceCode;
|
||||||
|
|
||||||
|
private String serviceName;
|
||||||
|
|
||||||
|
private Date appointmentTime;
|
||||||
|
|
||||||
|
private Integer slot = 1;
|
||||||
|
|
||||||
|
private Duration duration = Duration.ZERO;
|
||||||
|
}
|
||||||
@@ -0,0 +1,63 @@
|
|||||||
|
package de.etecture.ga.model;
|
||||||
|
|
||||||
|
import java.time.Duration;
|
||||||
|
import java.util.HashSet;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
import org.springframework.data.annotation.Id;
|
||||||
|
import org.springframework.data.jdbc.core.mapping.AggregateReference;
|
||||||
|
import org.springframework.data.relational.core.mapping.MappedCollection;
|
||||||
|
import org.springframework.util.Assert;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.experimental.Accessors;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
@Accessors(fluent = true, chain = true)
|
||||||
|
public class Garage {
|
||||||
|
|
||||||
|
@Id
|
||||||
|
private Long id;
|
||||||
|
|
||||||
|
private String code;
|
||||||
|
|
||||||
|
private String name;
|
||||||
|
|
||||||
|
private Integer maxAppointments = 1;
|
||||||
|
|
||||||
|
@MappedCollection(idColumn = "GARAGE_ID")
|
||||||
|
private Set<Appointment> appointments = new HashSet<>();
|
||||||
|
|
||||||
|
@MappedCollection(idColumn = "GARAGE_ID")
|
||||||
|
private Set<GarageServices> garageServices = new HashSet<>();
|
||||||
|
|
||||||
|
public Garage addAppointment(Appointment appointment) {
|
||||||
|
|
||||||
|
boolean added = this.appointments.add(appointment);
|
||||||
|
if(!added) {
|
||||||
|
appointment.slot(appointment.slot() + 1);
|
||||||
|
this.addAppointment(appointment);
|
||||||
|
}
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Garage addService(MDService service) {
|
||||||
|
garageServices.add(createGarageService(service, null));
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addService(MDService service, Duration duration) {
|
||||||
|
garageServices.add(createGarageService(service, duration));
|
||||||
|
}
|
||||||
|
|
||||||
|
private GarageServices createGarageService(MDService service, Duration duration) {
|
||||||
|
|
||||||
|
Assert.notNull(service, "Service must not be null");
|
||||||
|
Assert.notNull(service.id(), "Service id, must not be null");
|
||||||
|
|
||||||
|
duration = duration == null ? service.duration() : duration;
|
||||||
|
|
||||||
|
return new GarageServices().garageId(AggregateReference.to(this.id()))
|
||||||
|
.serviceId(AggregateReference.to(service.id())).duration(duration);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,23 @@
|
|||||||
|
package de.etecture.ga.model;
|
||||||
|
|
||||||
|
import java.time.Duration;
|
||||||
|
|
||||||
|
import org.springframework.data.jdbc.core.mapping.AggregateReference;
|
||||||
|
import org.springframework.data.relational.core.mapping.Column;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.experimental.Accessors;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
@Accessors(fluent = true, chain = true)
|
||||||
|
public class GarageServices {
|
||||||
|
|
||||||
|
@Column("GARAGE_ID")
|
||||||
|
private AggregateReference<Garage, Long> garageId;
|
||||||
|
|
||||||
|
@Column("SERVICE_ID")
|
||||||
|
private AggregateReference<MDService, Long> serviceId;
|
||||||
|
|
||||||
|
private Duration duration;
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,23 @@
|
|||||||
|
package de.etecture.ga.model;
|
||||||
|
|
||||||
|
import java.time.Duration;
|
||||||
|
|
||||||
|
import org.springframework.data.annotation.Id;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.experimental.Accessors;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
@Accessors(fluent = true, chain = true)
|
||||||
|
public class MDService {
|
||||||
|
|
||||||
|
@Id
|
||||||
|
private Long id;
|
||||||
|
|
||||||
|
private String code;
|
||||||
|
|
||||||
|
private String name;
|
||||||
|
|
||||||
|
private Duration duration = Duration.ZERO;
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
package de.etecture.ga.repository;
|
||||||
|
|
||||||
|
import org.springframework.data.repository.CrudRepository;
|
||||||
|
|
||||||
|
import de.etecture.ga.model.Appointment;
|
||||||
|
|
||||||
|
public interface AppointmentRepository extends CrudRepository<Appointment, Long> {
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
package de.etecture.ga.repository;
|
||||||
|
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
|
import org.springframework.data.repository.CrudRepository;
|
||||||
|
|
||||||
|
import de.etecture.ga.model.Garage;
|
||||||
|
|
||||||
|
public interface GarageRepository extends CrudRepository<Garage, Long> {
|
||||||
|
|
||||||
|
public Optional<Garage> findByCode(String code);
|
||||||
|
}
|
||||||
@@ -0,0 +1,20 @@
|
|||||||
|
package de.etecture.ga.repository;
|
||||||
|
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
|
import org.springframework.data.jdbc.repository.query.Query;
|
||||||
|
import org.springframework.data.repository.CrudRepository;
|
||||||
|
|
||||||
|
import de.etecture.ga.model.GarageServices;
|
||||||
|
import de.etecture.ga.model.MDService;
|
||||||
|
|
||||||
|
public interface GarageServiceRepository extends CrudRepository<GarageServices, Long> {
|
||||||
|
|
||||||
|
|
||||||
|
@Query("select s.ID, s.CODE, s.NAME, ifNull(gs.DURATION, s.DURATION) as DURATION "
|
||||||
|
+ "from GARAGE_SERVICES gs "
|
||||||
|
+ "join MD_SERVICE s on s.ID = gs.SERVICE_ID "
|
||||||
|
+ "join GARAGE g on g.ID = gs.GARAGE_ID "
|
||||||
|
+ "where s.CODE = :serviceCode and g.CODE = :garageCode")
|
||||||
|
public Optional<MDService> findByServiceCodeAndGarage(String serviceCode, String garageCode);
|
||||||
|
}
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
package de.etecture.ga.repository;
|
||||||
|
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
|
import org.springframework.data.repository.CrudRepository;
|
||||||
|
|
||||||
|
import de.etecture.ga.model.MDService;
|
||||||
|
|
||||||
|
public interface MDServiceRepository extends CrudRepository<MDService, Long> {
|
||||||
|
|
||||||
|
public Optional<MDService> findByCode(String code);
|
||||||
|
}
|
||||||
@@ -0,0 +1,118 @@
|
|||||||
|
package de.etecture.ga.service;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.net.URISyntaxException;
|
||||||
|
import java.nio.file.Files;
|
||||||
|
import java.nio.file.Path;
|
||||||
|
import java.nio.file.Paths;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.Date;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Objects;
|
||||||
|
import java.util.Optional;
|
||||||
|
import java.util.stream.Stream;
|
||||||
|
|
||||||
|
import org.springframework.data.jdbc.core.mapping.AggregateReference;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.databind.MappingIterator;
|
||||||
|
import com.fasterxml.jackson.dataformat.csv.CsvMapper;
|
||||||
|
import com.fasterxml.jackson.dataformat.csv.CsvSchema;
|
||||||
|
|
||||||
|
import de.etecture.ga.model.Appointment;
|
||||||
|
import de.etecture.ga.model.Garage;
|
||||||
|
import de.etecture.ga.model.MDService;
|
||||||
|
import de.etecture.ga.repository.AppointmentRepository;
|
||||||
|
import de.etecture.ga.repository.GarageRepository;
|
||||||
|
import de.etecture.ga.repository.GarageServiceRepository;
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
|
||||||
|
@Slf4j
|
||||||
|
@Service
|
||||||
|
@AllArgsConstructor
|
||||||
|
public class GarageImportService {
|
||||||
|
|
||||||
|
private static final String IMPORT_FOLDER = "import";
|
||||||
|
|
||||||
|
private final GarageRepository garageRepository;
|
||||||
|
|
||||||
|
private final GarageServiceRepository garageServiceRepository;
|
||||||
|
|
||||||
|
private final AppointmentRepository appointmentRepository;
|
||||||
|
|
||||||
|
public void importGarageData() {
|
||||||
|
|
||||||
|
try (Stream<Path> files = Files
|
||||||
|
.list(Paths.get(getClass().getClassLoader().getResource(IMPORT_FOLDER).toURI()))) {
|
||||||
|
|
||||||
|
files.filter(Files::isRegularFile).filter(path -> path.toString().endsWith(".csv"))
|
||||||
|
.forEach(this::loadGarageData);
|
||||||
|
|
||||||
|
} catch (IOException | URISyntaxException e) {
|
||||||
|
log.error("Can't read file", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public Optional<Garage> loadGarageData(final Path file) {
|
||||||
|
|
||||||
|
Optional<Garage> garage = garageRepository.findByCode(getGarageNameFromFile(file));
|
||||||
|
|
||||||
|
if (garage.isPresent()) {
|
||||||
|
List<CSVData> appointmentData = loadObjectsFromFile(file);
|
||||||
|
|
||||||
|
appointmentData.stream().filter(Objects::nonNull)
|
||||||
|
.forEach(data -> addAppointmentToGarage(data, garage.get()));
|
||||||
|
|
||||||
|
// bestehende Termine speichern
|
||||||
|
garage.get().appointments().forEach(appointmentRepository::save);
|
||||||
|
}
|
||||||
|
|
||||||
|
return garage;
|
||||||
|
}
|
||||||
|
|
||||||
|
private String getGarageNameFromFile(final Path fileName) {
|
||||||
|
|
||||||
|
String name = fileName.getFileName().toString();
|
||||||
|
|
||||||
|
int pos = name.lastIndexOf(".");
|
||||||
|
if (pos > 0 && pos < (name.length() - 1)) {
|
||||||
|
name = name.substring(0, pos);
|
||||||
|
}
|
||||||
|
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
|
private List<CSVData> loadObjectsFromFile(final Path file) {
|
||||||
|
|
||||||
|
try {
|
||||||
|
CsvSchema bootstrapSchema = CsvSchema.emptySchema().withHeader();
|
||||||
|
CsvMapper mapper = new CsvMapper();
|
||||||
|
MappingIterator<CSVData> readValues = mapper.readerFor(CSVData.class).with(bootstrapSchema)
|
||||||
|
.readValues(file.toFile());
|
||||||
|
|
||||||
|
return readValues.readAll();
|
||||||
|
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error("Error occurred while loading object list from file {}", file, e);
|
||||||
|
return Collections.emptyList();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void addAppointmentToGarage(CSVData data, Garage garage) {
|
||||||
|
|
||||||
|
Optional<MDService> garageService = garageServiceRepository.findByServiceCodeAndGarage(data.SERVICE,
|
||||||
|
garage.code());
|
||||||
|
|
||||||
|
garageService.map(service -> getAppointmentForService(service, data.APP_DATE, garage.id()))
|
||||||
|
.ifPresent(garage::addAppointment);
|
||||||
|
}
|
||||||
|
|
||||||
|
private Appointment getAppointmentForService(MDService service, Date date, Long garageId) {
|
||||||
|
return new Appointment().appointmentTime(date).serviceCode(service.code()).serviceName(service.name())
|
||||||
|
.duration(service.duration()).garageId(AggregateReference.to(garageId));
|
||||||
|
}
|
||||||
|
|
||||||
|
private record CSVData(Date APP_DATE, String SERVICE) {
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,39 @@
|
|||||||
|
package de.etecture.ga.service;
|
||||||
|
|
||||||
|
import java.security.InvalidParameterException;
|
||||||
|
|
||||||
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
import org.springframework.util.Assert;
|
||||||
|
|
||||||
|
import de.etecture.ga.model.MDService;
|
||||||
|
import de.etecture.ga.repository.MDServiceRepository;
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
|
||||||
|
@Service
|
||||||
|
@AllArgsConstructor
|
||||||
|
public class MDServiceService {
|
||||||
|
|
||||||
|
private final MDServiceRepository serviceRepository;
|
||||||
|
|
||||||
|
public MDService storeMDService(String serviceCode) {
|
||||||
|
|
||||||
|
if (StringUtils.isBlank(serviceCode))
|
||||||
|
throw new InvalidParameterException("serviceCode should not been empty");
|
||||||
|
|
||||||
|
MDService service = serviceRepository.findByCode(serviceCode).orElse(new MDService().code(serviceCode));
|
||||||
|
|
||||||
|
return serviceRepository.save(service);
|
||||||
|
}
|
||||||
|
|
||||||
|
public MDService storeMDService(MDService serviceToSafe) {
|
||||||
|
|
||||||
|
Assert.notNull(serviceToSafe, "Service must not be null");
|
||||||
|
Assert.notNull(serviceToSafe.code(), "Service code must not be null");
|
||||||
|
Assert.isTrue(serviceToSafe.duration().isPositive(), "Service duration must must be bigger then 0");
|
||||||
|
|
||||||
|
MDService service = serviceRepository.findByCode(serviceToSafe.code()).orElse(serviceToSafe);
|
||||||
|
|
||||||
|
return serviceRepository.save(service);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1 +1,11 @@
|
|||||||
spring.application.name=Garage appointment management
|
spring.application.name=Garage appointment management
|
||||||
|
|
||||||
|
# Datasource settings
|
||||||
|
spring.datasource.url=jdbc:h2:mem:etecture
|
||||||
|
spring.datasource.driverClassName=org.h2.Driver
|
||||||
|
spring.datasource.username=sa
|
||||||
|
spring.datasource.password=password
|
||||||
|
spring.datasource.platform=h2
|
||||||
|
|
||||||
|
# init DB by script
|
||||||
|
spring.sql.init.mode=always
|
||||||
@@ -0,0 +1,25 @@
|
|||||||
|
-- initial data
|
||||||
|
INSERT INTO MD_SERVICE (CODE, NAME, DURATION)
|
||||||
|
VALUES
|
||||||
|
('MOT', 'Motorinstandsetzung', 14400),
|
||||||
|
('OIL', 'Ölwechsel', 900),
|
||||||
|
('WHE', 'Radwechsel', 1800),
|
||||||
|
('FIX', 'Blechreparatur', 10800),
|
||||||
|
('INS', 'Hauptuntersuchung', 3600);
|
||||||
|
|
||||||
|
|
||||||
|
INSERT INTO GARAGE (CODE, NAME, MAX_APPOINTMENTS)
|
||||||
|
VALUES
|
||||||
|
('autohaus-schmidt', 'Autohaus Schmidt', 2),
|
||||||
|
('meisterbetrieb-bachstraße', 'Meisterbetrieb Bachstraße', 3);
|
||||||
|
|
||||||
|
|
||||||
|
INSERT INTO GARAGE_SERVICES (GARAGE_ID, SERVICE_ID, DURATION)
|
||||||
|
VALUES
|
||||||
|
(1, 1, 14400),
|
||||||
|
(1, 2, 900),
|
||||||
|
(1, 3, 1800),
|
||||||
|
(2, 2, 600),
|
||||||
|
(2, 4, 10800),
|
||||||
|
(2, 5, 3600);
|
||||||
|
|
||||||
File renamed without changes.
|
500 Internal Server Error
An error occurred: An error occurred Gitea Version: 28.1.0 |