Skip to content

Commit 29904ea

Browse files
committed
Project definitions using DDD
1 parent 4e0c9fb commit 29904ea

File tree

14 files changed

+553
-33
lines changed

14 files changed

+553
-33
lines changed

README.md

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,14 @@
55
![JUnit](https://img.shields.io/badge/JUnit-5.x-blue)
66
![JaCoCo](https://img.shields.io/badge/JaCoCo-0.8.x-blue)
77
![Kafka](https://img.shields.io/badge/Kafka-4.x-red)
8+
![Redis](https://img.shields.io/badge/Redis-7.4-green)
9+
![PostgreSQL](https://img.shields.io/badge/PostgreSQL-17-green)
810

911
A Spring Boot application for tracking flight events.
1012

1113
## Build Status
1214

1315
[![Java CI with Maven](https://github.com/luismr/flight-tracker-event-server-java/actions/workflows/maven.yml/badge.svg)](https://github.com/luismr/flight-tracker-event-server-java/actions/workflows/maven.yml)
14-
15-
## Code Coverage
16-
1716
![Coverage](badges/jacoco.svg)
1817
![Branches](badges/branches.svg)
1918

pom.xml

Lines changed: 128 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,11 @@
1919
<properties>
2020
<java.version>21</java.version>
2121
<jacoco.version>0.8.11</jacoco.version>
22+
<jacoco.coverage.minimum>0.80</jacoco.coverage.minimum>
23+
<jacoco.coverage.enforcer>false</jacoco.coverage.enforcer>
24+
<lombok.version>1.18.36</lombok.version>
2225
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
2326
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
24-
<jacoco.coverage.minimum>0.00</jacoco.coverage.minimum>
2527
</properties>
2628

2729
<dependencies>
@@ -30,16 +32,39 @@
3032
<artifactId>spring-boot-starter-web</artifactId>
3133
</dependency>
3234

35+
<dependency>
36+
<groupId>org.springframework.boot</groupId>
37+
<artifactId>spring-boot-starter-data-jpa</artifactId>
38+
</dependency>
39+
40+
<dependency>
41+
<groupId>org.springframework.kafka</groupId>
42+
<artifactId>spring-kafka</artifactId>
43+
</dependency>
44+
3345
<dependency>
3446
<groupId>org.springframework.boot</groupId>
3547
<artifactId>spring-boot-starter-test</artifactId>
3648
<scope>test</scope>
3749
</dependency>
3850

51+
<dependency>
52+
<groupId>org.springframework.kafka</groupId>
53+
<artifactId>spring-kafka-test</artifactId>
54+
<scope>test</scope>
55+
</dependency>
56+
3957
<dependency>
4058
<groupId>org.projectlombok</groupId>
4159
<artifactId>lombok</artifactId>
42-
<optional>true</optional>
60+
<version>${lombok.version}</version>
61+
<scope>provided</scope>
62+
</dependency>
63+
64+
<dependency>
65+
<groupId>com.h2database</groupId>
66+
<artifactId>h2</artifactId>
67+
<scope>runtime</scope>
4368
</dependency>
4469
</dependencies>
4570

@@ -48,14 +73,6 @@
4873
<plugin>
4974
<groupId>org.springframework.boot</groupId>
5075
<artifactId>spring-boot-maven-plugin</artifactId>
51-
<configuration>
52-
<excludes>
53-
<exclude>
54-
<groupId>org.projectlombok</groupId>
55-
<artifactId>lombok</artifactId>
56-
</exclude>
57-
</excludes>
58-
</configuration>
5976
</plugin>
6077

6178
<plugin>
@@ -76,28 +93,109 @@
7693
<goal>report</goal>
7794
</goals>
7895
</execution>
79-
<execution>
80-
<id>check</id>
81-
<goals>
82-
<goal>check</goal>
83-
</goals>
84-
<configuration>
85-
<rules>
86-
<rule>
87-
<element>BUNDLE</element>
88-
<limits>
89-
<limit>
90-
<counter>LINE</counter>
91-
<value>COVEREDRATIO</value>
92-
<minimum>${jacoco.coverage.minimum}</minimum>
93-
</limit>
94-
</limits>
95-
</rule>
96-
</rules>
97-
</configuration>
98-
</execution>
9996
</executions>
10097
</plugin>
98+
<plugin>
99+
<groupId>org.apache.maven.plugins</groupId>
100+
<artifactId>maven-compiler-plugin</artifactId>
101+
<version>3.10.1</version>
102+
<configuration>
103+
<annotationProcessorPaths>
104+
<path>
105+
<groupId>org.projectlombok</groupId>
106+
<artifactId>lombok</artifactId>
107+
<version>${lombok.version}</version>
108+
</path>
109+
</annotationProcessorPaths>
110+
<compilerArgs>
111+
<arg>-parameters</arg>
112+
</compilerArgs>
113+
</configuration>
114+
</plugin>
101115
</plugins>
102116
</build>
117+
118+
<profiles>
119+
<profile>
120+
<id>local</id>
121+
<activation>
122+
<activeByDefault>true</activeByDefault>
123+
</activation>
124+
<properties>
125+
<jacoco.coverage.enforcer>false</jacoco.coverage.enforcer>
126+
</properties>
127+
</profile>
128+
<profile>
129+
<id>dev</id>
130+
<properties>
131+
<jacoco.coverage.enforcer>true</jacoco.coverage.enforcer>
132+
</properties>
133+
<build>
134+
<plugins>
135+
<plugin>
136+
<groupId>org.jacoco</groupId>
137+
<artifactId>jacoco-maven-plugin</artifactId>
138+
<executions>
139+
<execution>
140+
<id>check</id>
141+
<goals>
142+
<goal>check</goal>
143+
</goals>
144+
<configuration>
145+
<rules>
146+
<rule>
147+
<element>BUNDLE</element>
148+
<limits>
149+
<limit>
150+
<counter>LINE</counter>
151+
<value>COVEREDRATIO</value>
152+
<minimum>${jacoco.coverage.minimum}</minimum>
153+
</limit>
154+
</limits>
155+
</rule>
156+
</rules>
157+
</configuration>
158+
</execution>
159+
</executions>
160+
</plugin>
161+
</plugins>
162+
</build>
163+
</profile>
164+
<profile>
165+
<id>prod</id>
166+
<properties>
167+
<jacoco.coverage.enforcer>true</jacoco.coverage.enforcer>
168+
</properties>
169+
<build>
170+
<plugins>
171+
<plugin>
172+
<groupId>org.jacoco</groupId>
173+
<artifactId>jacoco-maven-plugin</artifactId>
174+
<executions>
175+
<execution>
176+
<id>check</id>
177+
<goals>
178+
<goal>check</goal>
179+
</goals>
180+
<configuration>
181+
<rules>
182+
<rule>
183+
<element>BUNDLE</element>
184+
<limits>
185+
<limit>
186+
<counter>LINE</counter>
187+
<value>COVEREDRATIO</value>
188+
<minimum>${jacoco.coverage.minimum}</minimum>
189+
</limit>
190+
</limits>
191+
</rule>
192+
</rules>
193+
</configuration>
194+
</execution>
195+
</executions>
196+
</plugin>
197+
</plugins>
198+
</build>
199+
</profile>
200+
</profiles>
103201
</project>
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
package dev.luismachadoreis.flighttracker.server.api;
2+
3+
import dev.luismachadoreis.flighttracker.server.application.PingService;
4+
import dev.luismachadoreis.flighttracker.server.application.dto.PingDTO;
5+
import org.springframework.beans.factory.annotation.Value;
6+
import org.springframework.http.ResponseEntity;
7+
import org.springframework.web.bind.annotation.GetMapping;
8+
import org.springframework.web.bind.annotation.RequestMapping;
9+
import org.springframework.web.bind.annotation.RequestParam;
10+
import org.springframework.web.bind.annotation.RestController;
11+
import java.util.List;
12+
import java.util.Optional;
13+
14+
@RestController
15+
@RequestMapping("/api/pings")
16+
public class PingController {
17+
18+
private final PingService pingService;
19+
private final int defaultRequestLimit;
20+
21+
public PingController(
22+
PingService pingService,
23+
@Value("${default.request.limit:50}") int defaultRequestLimit
24+
) {
25+
this.pingService = pingService;
26+
this.defaultRequestLimit = defaultRequestLimit;
27+
}
28+
29+
@GetMapping
30+
public ResponseEntity<List<PingDTO>> getPings(@RequestParam(required = false) Integer limit) {
31+
return ResponseEntity.ok(pingService.getPings(
32+
Optional.ofNullable(limit).orElse(defaultRequestLimit)
33+
));
34+
}
35+
36+
}
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
package dev.luismachadoreis.flighttracker.server.application;
2+
3+
import dev.luismachadoreis.flighttracker.server.application.dto.PingDTO;
4+
import dev.luismachadoreis.flighttracker.server.domain.Ping;
5+
import dev.luismachadoreis.flighttracker.server.domain.PingRepository;
6+
import lombok.RequiredArgsConstructor;
7+
import lombok.extern.slf4j.Slf4j;
8+
import org.springframework.stereotype.Service;
9+
import org.springframework.transaction.annotation.Transactional;
10+
import java.util.List;
11+
12+
@Slf4j
13+
@Service
14+
@Transactional
15+
@RequiredArgsConstructor
16+
public class PingService {
17+
18+
private final PingRepository pingRepository;
19+
20+
public PingDTO createPing(PingDTO pingDTO) {
21+
var ping = new Ping(
22+
pingDTO.icao24(),
23+
pingDTO.callsign(),
24+
pingDTO.originCountry(),
25+
pingDTO.timePosition(),
26+
pingDTO.lastContact(),
27+
pingDTO.longitude(),
28+
pingDTO.latitude(),
29+
pingDTO.baroAltitude(),
30+
pingDTO.onGround(),
31+
pingDTO.velocity(),
32+
pingDTO.trueTrack(),
33+
pingDTO.verticalRate(),
34+
pingDTO.sensors(),
35+
pingDTO.geoAltitude(),
36+
pingDTO.squawk(),
37+
pingDTO.spi(),
38+
pingDTO.positionSource()
39+
);
40+
41+
pingRepository.save(ping);
42+
ping.registerPingCreated();
43+
44+
return pingDTO;
45+
}
46+
47+
@Transactional(readOnly = true)
48+
public List<PingDTO> getPings(final Integer limit) {
49+
return pingRepository
50+
.findTopNPings(limit)
51+
.stream()
52+
.map(ping -> new PingDTO(
53+
ping.getIcao24(),
54+
ping.getCallsign(),
55+
ping.getOriginCountry(),
56+
ping.getTimePosition(),
57+
ping.getLastContact(),
58+
ping.getLongitude(),
59+
ping.getLatitude(),
60+
ping.getBaroAltitude(),
61+
ping.getOnGround(),
62+
ping.getVelocity(),
63+
ping.getTrueTrack(),
64+
ping.getVerticalRate(),
65+
ping.getSensors(),
66+
ping.getGeoAltitude(),
67+
ping.getSquawk(),
68+
ping.getSpi(),
69+
ping.getPositionSource()
70+
))
71+
.toList();
72+
}
73+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package dev.luismachadoreis.flighttracker.server.application.dto;
2+
3+
import com.fasterxml.jackson.annotation.JsonProperty;
4+
5+
public record PingDTO(
6+
@JsonProperty("icao24") String icao24,
7+
@JsonProperty("callsign") String callsign,
8+
@JsonProperty("origin_country") String originCountry,
9+
@JsonProperty("time_position") Long timePosition,
10+
@JsonProperty("last_contact") Long lastContact,
11+
@JsonProperty("longitude") Double longitude,
12+
@JsonProperty("latitude") Double latitude,
13+
@JsonProperty("baro_altitude") Double baroAltitude,
14+
@JsonProperty("on_ground") Boolean onGround,
15+
@JsonProperty("velocity") Double velocity,
16+
@JsonProperty("true_track") Double trueTrack,
17+
@JsonProperty("vertical_rate") Double verticalRate,
18+
@JsonProperty("sensors") Integer[] sensors,
19+
@JsonProperty("geo_altitude") Double geoAltitude,
20+
@JsonProperty("squawk") String squawk,
21+
@JsonProperty("spi") Boolean spi,
22+
@JsonProperty("position_source") Integer positionSource
23+
) {}

0 commit comments

Comments
 (0)