Compare commits
1 commit
main
...
create-api
| Author | SHA1 | Date | |
|---|---|---|---|
| 4b749dc372 |
7 changed files with 437 additions and 0 deletions
40
.gitignore
vendored
Normal file
40
.gitignore
vendored
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
#Maven
|
||||
target/
|
||||
pom.xml.tag
|
||||
pom.xml.releaseBackup
|
||||
pom.xml.versionsBackup
|
||||
release.properties
|
||||
.flattened-pom.xml
|
||||
|
||||
# Eclipse
|
||||
.project
|
||||
.classpath
|
||||
.settings/
|
||||
bin/
|
||||
|
||||
# IntelliJ
|
||||
.idea
|
||||
*.ipr
|
||||
*.iml
|
||||
*.iws
|
||||
|
||||
# NetBeans
|
||||
nb-configuration.xml
|
||||
|
||||
# Visual Studio Code
|
||||
.vscode
|
||||
.factorypath
|
||||
|
||||
# OSX
|
||||
.DS_Store
|
||||
|
||||
# Vim
|
||||
*.swp
|
||||
*.swo
|
||||
|
||||
# patch
|
||||
*.orig
|
||||
*.rej
|
||||
|
||||
# Local environment
|
||||
.env
|
||||
129
pom.xml
Normal file
129
pom.xml
Normal file
|
|
@ -0,0 +1,129 @@
|
|||
<?xml version="1.0"?>
|
||||
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>com.c4181</groupId>
|
||||
<artifactId>cad-call-api</artifactId>
|
||||
<version>1.0.0-SNAPSHOT</version>
|
||||
<properties>
|
||||
<compiler-plugin.version>3.10.1</compiler-plugin.version>
|
||||
<maven.compiler.release>17</maven.compiler.release>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
|
||||
<quarkus.platform.artifact-id>quarkus-bom</quarkus.platform.artifact-id>
|
||||
<quarkus.platform.group-id>io.quarkus.platform</quarkus.platform.group-id>
|
||||
<quarkus.platform.version>2.16.0.Final</quarkus.platform.version>
|
||||
<skipITs>true</skipITs>
|
||||
<surefire-plugin.version>3.0.0-M7</surefire-plugin.version>
|
||||
</properties>
|
||||
<dependencyManagement>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>${quarkus.platform.group-id}</groupId>
|
||||
<artifactId>${quarkus.platform.artifact-id}</artifactId>
|
||||
<version>${quarkus.platform.version}</version>
|
||||
<type>pom</type>
|
||||
<scope>import</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</dependencyManagement>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>io.quarkus</groupId>
|
||||
<artifactId>quarkus-resteasy-reactive-jackson</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.quarkus</groupId>
|
||||
<artifactId>quarkus-reactive-pg-client</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.quarkus</groupId>
|
||||
<artifactId>quarkus-arc</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.quarkus</groupId>
|
||||
<artifactId>quarkus-resteasy-reactive</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.quarkus</groupId>
|
||||
<artifactId>quarkus-junit5</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.rest-assured</groupId>
|
||||
<artifactId>rest-assured</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>${quarkus.platform.group-id}</groupId>
|
||||
<artifactId>quarkus-maven-plugin</artifactId>
|
||||
<version>${quarkus.platform.version}</version>
|
||||
<extensions>true</extensions>
|
||||
<executions>
|
||||
<execution>
|
||||
<goals>
|
||||
<goal>build</goal>
|
||||
<goal>generate-code</goal>
|
||||
<goal>generate-code-tests</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<version>${compiler-plugin.version}</version>
|
||||
<configuration>
|
||||
<compilerArgs>
|
||||
<arg>-parameters</arg>
|
||||
</compilerArgs>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<artifactId>maven-surefire-plugin</artifactId>
|
||||
<version>${surefire-plugin.version}</version>
|
||||
<configuration>
|
||||
<systemPropertyVariables>
|
||||
<java.util.logging.manager>org.jboss.logmanager.LogManager</java.util.logging.manager>
|
||||
<maven.home>${maven.home}</maven.home>
|
||||
</systemPropertyVariables>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<artifactId>maven-failsafe-plugin</artifactId>
|
||||
<version>${surefire-plugin.version}</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<goals>
|
||||
<goal>integration-test</goal>
|
||||
<goal>verify</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<systemPropertyVariables>
|
||||
<native.image.path>${project.build.directory}/${project.build.finalName}-runner</native.image.path>
|
||||
<java.util.logging.manager>org.jboss.logmanager.LogManager</java.util.logging.manager>
|
||||
<maven.home>${maven.home}</maven.home>
|
||||
</systemPropertyVariables>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
<profiles>
|
||||
<profile>
|
||||
<id>native</id>
|
||||
<activation>
|
||||
<property>
|
||||
<name>native</name>
|
||||
</property>
|
||||
</activation>
|
||||
<properties>
|
||||
<skipITs>false</skipITs>
|
||||
<quarkus.package.type>native</quarkus.package.type>
|
||||
</properties>
|
||||
</profile>
|
||||
</profiles>
|
||||
</project>
|
||||
47
src/main/java/com/c4181/Controller/CallController.java
Normal file
47
src/main/java/com/c4181/Controller/CallController.java
Normal file
|
|
@ -0,0 +1,47 @@
|
|||
package com.c4181.Controller;
|
||||
|
||||
import com.c4181.model.JsoCall;
|
||||
import com.c4181.model.JsoCalls;
|
||||
import io.smallrye.mutiny.Multi;
|
||||
import io.smallrye.mutiny.Uni;
|
||||
import io.vertx.mutiny.pgclient.PgPool;
|
||||
import org.jboss.resteasy.reactive.RestQuery;
|
||||
|
||||
import javax.enterprise.context.RequestScoped;
|
||||
import javax.inject.Inject;
|
||||
import javax.ws.rs.BadRequestException;
|
||||
import javax.ws.rs.GET;
|
||||
import javax.ws.rs.Path;
|
||||
import javax.ws.rs.Produces;
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
@Path("calls")
|
||||
@RequestScoped
|
||||
public class CallController {
|
||||
|
||||
@Inject
|
||||
PgPool client;
|
||||
|
||||
@Path("get-calls-in-range")
|
||||
@GET
|
||||
public Uni<JsoCalls> getCallsInRange(@RestQuery LocalDateTime startTime, @RestQuery LocalDateTime endTime) {
|
||||
if (startTime == null || endTime == null) {
|
||||
throw new BadRequestException("Start time and end time are required");
|
||||
}
|
||||
|
||||
if (endTime.isBefore(startTime)) {
|
||||
throw new BadRequestException("End time should be before start time");
|
||||
}
|
||||
|
||||
return JsoCall.findCallsInDateRange(client, startTime, endTime);
|
||||
}
|
||||
|
||||
@Path("get-all-call-types")
|
||||
@Produces
|
||||
public Multi<String> getAllCallTypes() {
|
||||
return client.query("SELECT DISTINCT call_description FROM calls")
|
||||
.execute()
|
||||
.onItem().transformToMulti(set -> Multi.createFrom().iterable(set))
|
||||
.onItem().transform((row -> row.getString(0)));
|
||||
}
|
||||
}
|
||||
125
src/main/java/com/c4181/model/JsoCall.java
Normal file
125
src/main/java/com/c4181/model/JsoCall.java
Normal file
|
|
@ -0,0 +1,125 @@
|
|||
package com.c4181.model;
|
||||
|
||||
import io.smallrye.mutiny.Multi;
|
||||
import io.smallrye.mutiny.Uni;
|
||||
import io.vertx.mutiny.pgclient.PgPool;
|
||||
import io.vertx.mutiny.sqlclient.Row;
|
||||
import io.vertx.mutiny.sqlclient.Tuple;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.Objects;
|
||||
|
||||
public class JsoCall {
|
||||
|
||||
String incidentNumber;
|
||||
LocalDateTime dispatchedTime;
|
||||
String address;
|
||||
String signal;
|
||||
String callDescription;
|
||||
Point point;
|
||||
|
||||
public String getIncidentNumber() {
|
||||
return incidentNumber;
|
||||
}
|
||||
|
||||
public void setIncidentNumber(String incidentNumber) {
|
||||
this.incidentNumber = incidentNumber;
|
||||
}
|
||||
|
||||
public LocalDateTime getDispatchedTime() {
|
||||
return dispatchedTime;
|
||||
}
|
||||
|
||||
public void setDispatchedTime(LocalDateTime dispatchedTime) {
|
||||
this.dispatchedTime = dispatchedTime;
|
||||
}
|
||||
|
||||
public String getAddress() {
|
||||
return address;
|
||||
}
|
||||
|
||||
public void setAddress(String address) {
|
||||
this.address = address;
|
||||
}
|
||||
|
||||
public String getSignal() {
|
||||
return signal;
|
||||
}
|
||||
|
||||
public void setSignal(String signal) {
|
||||
this.signal = signal;
|
||||
}
|
||||
|
||||
public String getCallDescription() {
|
||||
return callDescription;
|
||||
}
|
||||
|
||||
public void setCallDescription(String callDescription) {
|
||||
this.callDescription = callDescription;
|
||||
}
|
||||
|
||||
public Point getPoint() {
|
||||
return point;
|
||||
}
|
||||
|
||||
public void setPoint(Point point) {
|
||||
this.point = point;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
JsoCall jsoCall = (JsoCall) o;
|
||||
return Objects.equals(incidentNumber, jsoCall.incidentNumber) && Objects.equals(dispatchedTime, jsoCall.dispatchedTime) && Objects.equals(address, jsoCall.address) && Objects.equals(signal, jsoCall.signal) && Objects.equals(callDescription, jsoCall.callDescription) && Objects.equals(point, jsoCall.point);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(incidentNumber, dispatchedTime, address, signal, callDescription, point);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "JsoCall{" +
|
||||
"incidentNumber='" + incidentNumber + '\'' +
|
||||
", dispatchedTime=" + dispatchedTime +
|
||||
", address='" + address + '\'' +
|
||||
", signal='" + signal + '\'' +
|
||||
", callDescription='" + callDescription + '\'' +
|
||||
", point=" + point +
|
||||
'}';
|
||||
}
|
||||
|
||||
private static JsoCall fromPostgres(Row row) {
|
||||
JsoCall call = new JsoCall();
|
||||
|
||||
call.setIncidentNumber(row.getString("incident_number"));
|
||||
call.setDispatchedTime(row.getLocalDateTime("dispatched_time"));
|
||||
call.setAddress(row.getString("address"));
|
||||
call.setSignal(row.getString("signal"));
|
||||
call.setCallDescription(row.getString("call_description"));
|
||||
|
||||
io.vertx.pgclient.data.Point pgPoint = row.get(io.vertx.pgclient.data.Point.class, "point");
|
||||
if (pgPoint != null) {
|
||||
Point point = new Point(pgPoint.getX(), pgPoint.getY());
|
||||
call.setPoint(point);
|
||||
}
|
||||
|
||||
return call;
|
||||
}
|
||||
|
||||
public static Uni<JsoCalls> findCallsInDateRange(PgPool client, LocalDateTime startTime, LocalDateTime endTime) {
|
||||
JsoCalls responseObject = new JsoCalls();
|
||||
return client.preparedQuery("" +
|
||||
"SELECT * " +
|
||||
"FROM calls " +
|
||||
"WHERE dispatched_time BETWEEN $1 AND $2").execute(Tuple.of(startTime, endTime))
|
||||
.onItem().transformToMulti(set -> Multi.createFrom().iterable(set))
|
||||
.onItem().transform(JsoCall::fromPostgres)
|
||||
.collect().asList().map(jsoCalls -> {
|
||||
responseObject.setCalls(jsoCalls);
|
||||
return responseObject;
|
||||
});
|
||||
}
|
||||
}
|
||||
37
src/main/java/com/c4181/model/JsoCalls.java
Normal file
37
src/main/java/com/c4181/model/JsoCalls.java
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
package com.c4181.model;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.concurrent.CopyOnWriteArrayList;
|
||||
|
||||
public class JsoCalls {
|
||||
List<JsoCall> calls = new CopyOnWriteArrayList<>();
|
||||
|
||||
public List<JsoCall> getCalls() {
|
||||
return calls;
|
||||
}
|
||||
|
||||
public void setCalls(List<JsoCall> calls) {
|
||||
this.calls = calls;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
JsoCalls jsoCalls = (JsoCalls) o;
|
||||
return Objects.equals(calls, jsoCalls.calls);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(calls);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "JsoCalls{" +
|
||||
"calls=" + calls +
|
||||
'}';
|
||||
}
|
||||
}
|
||||
50
src/main/java/com/c4181/model/Point.java
Normal file
50
src/main/java/com/c4181/model/Point.java
Normal file
|
|
@ -0,0 +1,50 @@
|
|||
package com.c4181.model;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
public class Point {
|
||||
private double lat;
|
||||
private double lng;
|
||||
|
||||
public Point(double lat, double lng) {
|
||||
this.lat = lat;
|
||||
this.lng = lng;
|
||||
}
|
||||
|
||||
public double getLat() {
|
||||
return lat;
|
||||
}
|
||||
|
||||
public void setLat(double lat) {
|
||||
this.lat = lat;
|
||||
}
|
||||
|
||||
public double getLng() {
|
||||
return lng;
|
||||
}
|
||||
|
||||
public void setLng(double lng) {
|
||||
this.lng = lng;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
Point point = (Point) o;
|
||||
return Double.compare(point.lat, lat) == 0 && Double.compare(point.lng, lng) == 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(lat, lng);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Point{" +
|
||||
"lat=" + lat +
|
||||
", lng=" + lng +
|
||||
'}';
|
||||
}
|
||||
}
|
||||
9
src/main/resources/application.properties
Normal file
9
src/main/resources/application.properties
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
quarkus.datasource.db-kind=postgresql
|
||||
quarkus.datasource.username=${USER_NAME}
|
||||
quarkus.datasource.password=${PASSWORD}
|
||||
quarkus.datasource.reactive.url=postgresql://192.168.1.17:5432/jsoCad
|
||||
|
||||
quarkus.http.cors=true
|
||||
quarkus.http.cors.origins=*
|
||||
quarkus.http.cors.methods=GET
|
||||
quarkus.http.cors.headers=X-Custom
|
||||
Loading…
Reference in a new issue