Compare commits
3 Commits
1f7dfee78f
...
97d86cd11a
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
97d86cd11a | ||
|
|
6985e0ea87 | ||
|
|
a0cf2d1854 |
35
pom.xml
35
pom.xml
@@ -22,6 +22,7 @@
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
<!-- Spring libs -->
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-web</artifactId>
|
||||
@@ -30,18 +31,12 @@
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-data-jdbc</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- CSV handling -->
|
||||
<dependency>
|
||||
<groupId>com.h2database</groupId>
|
||||
<artifactId>h2</artifactId>
|
||||
<scope>runtime</scope>
|
||||
<groupId>com.fasterxml.jackson.dataformat</groupId>
|
||||
<artifactId>jackson-dataformat-csv</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.projectlombok</groupId>
|
||||
<artifactId>lombok</artifactId>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
|
||||
<!-- OpenAPI generation -->
|
||||
<dependency>
|
||||
<groupId>org.springdoc</groupId>
|
||||
<artifactId>springdoc-openapi-ui</artifactId>
|
||||
@@ -52,7 +47,18 @@
|
||||
<artifactId>jackson-databind-nullable</artifactId>
|
||||
<version>0.2.6</version>
|
||||
</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 -->
|
||||
<dependency>
|
||||
@@ -60,6 +66,11 @@
|
||||
<artifactId>spring-boot-starter-test</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.mockito</groupId>
|
||||
<artifactId>mockito-core</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
@@ -79,7 +90,7 @@
|
||||
</inputSpec>
|
||||
<generatorName>spring</generatorName>
|
||||
<apiPackage>de.etecture.ga.api</apiPackage>
|
||||
<modelPackage>de.etecture.ga.model</modelPackage>
|
||||
<modelPackage>de.etecture.ga.dto</modelPackage>
|
||||
<supportingFilesToGenerate>
|
||||
ApiUtil.java
|
||||
</supportingFilesToGenerate>
|
||||
|
||||
46
src/main/java/de/etecture/ga/api/GarageApiController.java
Normal file
46
src/main/java/de/etecture/ga/api/GarageApiController.java
Normal file
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
22
src/main/java/de/etecture/ga/config/Setup.java
Normal file
22
src/main/java/de/etecture/ga/config/Setup.java
Normal file
@@ -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();
|
||||
}
|
||||
}
|
||||
32
src/main/java/de/etecture/ga/model/Appointment.java
Normal file
32
src/main/java/de/etecture/ga/model/Appointment.java
Normal file
@@ -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;
|
||||
}
|
||||
63
src/main/java/de/etecture/ga/model/Garage.java
Normal file
63
src/main/java/de/etecture/ga/model/Garage.java
Normal file
@@ -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);
|
||||
}
|
||||
}
|
||||
23
src/main/java/de/etecture/ga/model/GarageServices.java
Normal file
23
src/main/java/de/etecture/ga/model/GarageServices.java
Normal file
@@ -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;
|
||||
|
||||
}
|
||||
23
src/main/java/de/etecture/ga/model/MDService.java
Normal file
23
src/main/java/de/etecture/ga/model/MDService.java
Normal file
@@ -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);
|
||||
}
|
||||
118
src/main/java/de/etecture/ga/service/GarageImportService.java
Normal file
118
src/main/java/de/etecture/ga/service/GarageImportService.java
Normal file
@@ -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) {
|
||||
}
|
||||
}
|
||||
39
src/main/java/de/etecture/ga/service/MDServiceService.java
Normal file
39
src/main/java/de/etecture/ga/service/MDServiceService.java
Normal file
@@ -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
|
||||
|
||||
# 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
|
||||
25
src/main/resources/data.sql
Normal file
25
src/main/resources/data.sql
Normal file
@@ -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);
|
||||
|
||||
42
src/main/resources/schema.sql
Normal file
42
src/main/resources/schema.sql
Normal file
@@ -0,0 +1,42 @@
|
||||
|
||||
CREATE TABLE GARAGE (
|
||||
ID BIGINT NOT NULL AUTO_INCREMENT UNIQUE,
|
||||
CODE VARCHAR(100) DEFAULT NULL UNIQUE,
|
||||
NAME VARCHAR(200) DEFAULT NULL,
|
||||
MAX_APPOINTMENTS INT NOT NULL DEFAULT 1,
|
||||
|
||||
PRIMARY KEY (ID)
|
||||
);
|
||||
|
||||
CREATE TABLE APPOINTMENT (
|
||||
ID BIGINT NOT NULL AUTO_INCREMENT UNIQUE,
|
||||
GARAGE_ID BIGINT NOT NULL,
|
||||
SERVICE_CODE VARCHAR(5) DEFAULT NULL,
|
||||
SERVICE_NAME VARCHAR(50) DEFAULT NULL,
|
||||
APPOINTMENT_TIME DATE DEFAULT NULL,
|
||||
SLOT INT NOT NULL DEFAULT 1,
|
||||
DURATION BIGINT NOT NULL DEFAULT 0,
|
||||
|
||||
PRIMARY KEY (ID),
|
||||
FOREIGN KEY (GARAGE_ID) REFERENCES GARAGE(ID)
|
||||
);
|
||||
|
||||
CREATE TABLE MD_SERVICE (
|
||||
ID BIGINT NOT NULL AUTO_INCREMENT UNIQUE,
|
||||
CODE VARCHAR(5) NOT NULL UNIQUE,
|
||||
NAME VARCHAR(50) DEFAULT NULL,
|
||||
DURATION BIGINT DEFAULT 0,
|
||||
|
||||
PRIMARY KEY (ID)
|
||||
);
|
||||
|
||||
CREATE TABLE GARAGE_SERVICES (
|
||||
GARAGE_ID BIGINT NOT NULL,
|
||||
SERVICE_ID BIGINT NOT NULL,
|
||||
DURATION BIGINT DEFAULT NULL,
|
||||
|
||||
CONSTRAINT GARAGE_SERVICE_IDX UNIQUE (GARAGE_ID, SERVICE_ID),
|
||||
|
||||
FOREIGN KEY (GARAGE_ID) REFERENCES GARAGE(ID),
|
||||
FOREIGN KEY (SERVICE_ID) REFERENCES MD_SERVICE(ID)
|
||||
);
|
||||
@@ -1,13 +1,36 @@
|
||||
package de.etecture.ga;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
import java.net.URISyntaxException;
|
||||
import java.util.Optional;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
|
||||
import de.etecture.ga.model.Garage;
|
||||
import de.etecture.ga.repository.GarageRepository;
|
||||
|
||||
@SpringBootTest
|
||||
class GarageAppointmentManagementApplicationTests {
|
||||
|
||||
@Autowired
|
||||
private GarageRepository garageRepository;
|
||||
|
||||
@Test
|
||||
void contextLoads() {
|
||||
}
|
||||
|
||||
@Test
|
||||
void testImportedGarageData() throws URISyntaxException {
|
||||
|
||||
Optional<Garage> testGarage = garageRepository.findByCode("test-data");
|
||||
|
||||
assertThat(testGarage).isPresent();
|
||||
assertThat(testGarage.get().name()).isEqualTo("Test Autohaus");
|
||||
assertThat(testGarage.get().appointments()).hasSize(19);
|
||||
assertThat(testGarage.get().garageServices()).hasSize(3);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,53 @@
|
||||
package de.etecture.ga.api;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.fail;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.test.web.servlet.MockMvc;
|
||||
import org.springframework.test.web.servlet.MvcResult;
|
||||
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders;
|
||||
import org.springframework.test.web.servlet.result.MockMvcResultHandlers;
|
||||
import org.springframework.test.web.servlet.result.MockMvcResultMatchers;
|
||||
|
||||
/**
|
||||
* Integrationtest for the {@link WerkstattApi}
|
||||
*/
|
||||
@SpringBootTest
|
||||
@AutoConfigureMockMvc
|
||||
class GarageApiControllerTest {
|
||||
|
||||
@Autowired
|
||||
private MockMvc mockMvc;
|
||||
|
||||
@Test
|
||||
void testGetTermin() throws Exception {
|
||||
|
||||
MvcResult mvcResult = this.mockMvc.perform(MockMvcRequestBuilders.get("/werkstatt/{werkstattId}/termin/{terminId}", "1", "1"))
|
||||
.andDo(MockMvcResultHandlers.print())
|
||||
.andExpect(MockMvcResultMatchers.status().isOk())
|
||||
// .andExpect(MockMvcResultMatchers.jsonPath("$.message").value("Hello World!!!"))
|
||||
.andReturn();
|
||||
|
||||
assertEquals("application/json;charset=UTF-8", mvcResult.getResponse().getContentType());
|
||||
}
|
||||
|
||||
@Test
|
||||
void testGetTermine() {
|
||||
fail("Not yet implemented");
|
||||
}
|
||||
|
||||
@Test
|
||||
void testGetTerminvorschlaege() {
|
||||
fail("Not yet implemented");
|
||||
}
|
||||
|
||||
@Test
|
||||
void testPostTermin() {
|
||||
fail("Not yet implemented");
|
||||
}
|
||||
|
||||
}
|
||||
10
src/test/resources/application.properties
Normal file
10
src/test/resources/application.properties
Normal file
@@ -0,0 +1,10 @@
|
||||
spring.application.name=Garage appointment management - test
|
||||
|
||||
# Datasource settings
|
||||
spring.datasource.url=jdbc:h2:mem:etecture_test
|
||||
spring.datasource.driverClassName=org.h2.Driver
|
||||
spring.datasource.username=sa
|
||||
spring.datasource.password=password
|
||||
|
||||
# init DB by script
|
||||
spring.sql.init.mode=always
|
||||
12
src/test/resources/data.sql
Normal file
12
src/test/resources/data.sql
Normal file
@@ -0,0 +1,12 @@
|
||||
-- test data
|
||||
INSERT INTO GARAGE (CODE, NAME, MAX_APPOINTMENTS)
|
||||
VALUES
|
||||
('test-data', 'Test Autohaus', 2);
|
||||
|
||||
|
||||
INSERT INTO GARAGE_SERVICES (GARAGE_ID, SERVICE_ID, DURATION)
|
||||
VALUES
|
||||
(select id from GARAGE where CODE = 'test-data', 1, 14400),
|
||||
(select id from GARAGE where CODE = 'test-data', 2, 900),
|
||||
(select id from GARAGE where CODE = 'test-data', 3, 1800);
|
||||
|
||||
20
src/test/resources/import/test-data.csv
Normal file
20
src/test/resources/import/test-data.csv
Normal file
@@ -0,0 +1,20 @@
|
||||
APP_DATE,SERVICE
|
||||
2019-01-02T13:00Z,WHE
|
||||
2019-01-02T15:00Z,WHE
|
||||
2019-01-04T08:15Z,MOT
|
||||
2019-01-04T09:00Z,OIL
|
||||
2019-01-04T09:00Z,OIL
|
||||
2019-01-05T10:15Z,MOT
|
||||
2019-01-05T13:00Z,WHE
|
||||
2019-01-07T08:15Z,OIL
|
||||
2019-01-07T08:45Z,OIL
|
||||
2019-01-08T09:15Z,MOT
|
||||
2019-01-08T09:30Z,MOT
|
||||
2019-01-08T08:00Z,WHE
|
||||
2019-01-09T08:30Z,WHE
|
||||
2019-01-09T10:45Z,OIL
|
||||
2019-01-09T13:00Z,OIL
|
||||
2019-01-10T15:15Z,WHE
|
||||
2019-01-10T14:10Z,MOT
|
||||
2019-01-11T12:15Z,OIL
|
||||
2019-01-11T08:15Z,WHE
|
||||
|
Reference in New Issue
Block a user