-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c97915d
commit 5d09c1c
Showing
48 changed files
with
1,090 additions
and
407 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 30 additions & 0 deletions
30
api/src/main/java/com/ineat/colistracker/application/ColisTrackerApplication.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package com.ineat.colistracker.application; | ||
|
||
|
||
import org.eclipse.microprofile.openapi.annotations.OpenAPIDefinition; | ||
import org.eclipse.microprofile.openapi.annotations.info.Contact; | ||
import org.eclipse.microprofile.openapi.annotations.info.Info; | ||
import org.eclipse.microprofile.openapi.annotations.info.License; | ||
import org.eclipse.microprofile.openapi.annotations.tags.Tag; | ||
|
||
import javax.ws.rs.core.Application; | ||
|
||
@OpenAPIDefinition( | ||
tags = { | ||
@Tag(name="trackings", description="Operations related to trackings"), | ||
@Tag(name="couriers", description="Operations related to couriers") | ||
}, | ||
info = @Info( | ||
title="Colis Tracker API", | ||
version = "1.0.0-SNAPSHOT", | ||
contact = @Contact( | ||
name = "Example API Support", | ||
url = "http://exampleurl.com/contact", | ||
email = "[email protected]"), | ||
license = @License( | ||
name = "Apache 2.0", | ||
url = "https://www.apache.org/licenses/LICENSE-2.0.html")) | ||
) | ||
public class ColisTrackerApplication extends Application { | ||
|
||
} |
13 changes: 0 additions & 13 deletions
13
api/src/main/java/com/ineat/colistracker/domain/model/Colis.java
This file was deleted.
Oops, something went wrong.
27 changes: 27 additions & 0 deletions
27
api/src/main/java/com/ineat/colistracker/domain/model/Courier.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package com.ineat.colistracker.domain.model; | ||
|
||
import lombok.Getter; | ||
import org.eclipse.microprofile.config.ConfigProvider; | ||
|
||
public enum Courier { | ||
LA_POSTE("La Poste", "colis_tracker.trackers.la_poste"), | ||
DPD("DPD", "colis_tracker.trackers.dpd"), | ||
MONDIAL_RELAY("Mondial Relay", "colis_tracker.trackers.mondial_relay"); | ||
|
||
@Getter | ||
private final String name; | ||
private final String configProperty; | ||
|
||
Courier(String name, String configProperty) { | ||
this.name = name; | ||
this.configProperty = configProperty; | ||
} | ||
|
||
public boolean isActive() { | ||
final String activeConfigPropertyKey = String.format("%s.active", configProperty); | ||
|
||
return ConfigProvider.getConfig() | ||
.getOptionalValue(activeConfigPropertyKey, Boolean.class) | ||
.orElse(false); | ||
} | ||
} |
52 changes: 52 additions & 0 deletions
52
api/src/main/java/com/ineat/colistracker/domain/model/Tracking.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package com.ineat.colistracker.domain.model; | ||
|
||
|
||
import lombok.AllArgsConstructor; | ||
import lombok.Builder; | ||
import lombok.NoArgsConstructor; | ||
import lombok.With; | ||
|
||
import java.time.LocalDateTime; | ||
import java.util.Set; | ||
|
||
@With | ||
@Builder | ||
@AllArgsConstructor | ||
@NoArgsConstructor | ||
public class Tracking { | ||
/** | ||
* Technical id used internally to identify the tracking | ||
*/ | ||
public Long id; | ||
|
||
/** | ||
* User defined name for the tracking | ||
*/ | ||
public String name; | ||
|
||
/** | ||
* Courier id | ||
*/ | ||
public String trackingId; | ||
|
||
/** | ||
* Datetime for when the tracking was created | ||
*/ | ||
public LocalDateTime created; | ||
|
||
public LocalDateTime updated; | ||
|
||
public TrackingStatus status; | ||
|
||
public Courier courier; | ||
|
||
public Set<TrackingEvent> history; | ||
|
||
public void activate() { | ||
this.status = TrackingStatus.ACTIVE; | ||
} | ||
|
||
public void archive() { | ||
this.status = TrackingStatus.ARCHIVED; | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
api/src/main/java/com/ineat/colistracker/domain/model/TrackingEvent.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package com.ineat.colistracker.domain.model; | ||
|
||
import java.time.LocalDateTime; | ||
|
||
public class TrackingEvent { | ||
public Long id; | ||
public LocalDateTime time; | ||
public String description; | ||
} |
16 changes: 16 additions & 0 deletions
16
api/src/main/java/com/ineat/colistracker/domain/model/TrackingStatus.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package com.ineat.colistracker.domain.model; | ||
|
||
/** | ||
* User defined status for the tracking. This | ||
* defines if we watch for updates for the tracking or not | ||
*/ | ||
public enum TrackingStatus { | ||
/** | ||
* Active. We'll watch for update for the tracking | ||
*/ | ||
ACTIVE, | ||
/** | ||
* Archived. We won't watch for updates for the tracking | ||
*/ | ||
ARCHIVED | ||
} |
15 changes: 0 additions & 15 deletions
15
api/src/main/java/com/ineat/colistracker/domain/repository/ColisRepository.java
This file was deleted.
Oops, something went wrong.
8 changes: 8 additions & 0 deletions
8
api/src/main/java/com/ineat/colistracker/domain/repository/TrackingEventRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package com.ineat.colistracker.domain.repository; | ||
|
||
import com.ineat.colistracker.domain.model.TrackingEvent; | ||
import io.smallrye.mutiny.Uni; | ||
|
||
public interface TrackingEventRepository { | ||
Uni<TrackingEvent> save(TrackingEvent trackingEvent); | ||
} |
17 changes: 17 additions & 0 deletions
17
api/src/main/java/com/ineat/colistracker/domain/repository/TrackingRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package com.ineat.colistracker.domain.repository; | ||
|
||
import com.ineat.colistracker.domain.model.Tracking; | ||
import io.smallrye.mutiny.Multi; | ||
import io.smallrye.mutiny.Uni; | ||
|
||
public interface TrackingRepository { | ||
Uni<Tracking> create(Tracking tracking); | ||
|
||
Uni<Tracking> getById(Long id); | ||
|
||
Multi<Tracking> all(); | ||
|
||
Uni<Boolean> delete(Long id); | ||
|
||
Uni<Tracking> update(Tracking tracking); | ||
} |
41 changes: 0 additions & 41 deletions
41
api/src/main/java/com/ineat/colistracker/domain/service/ColisService.java
This file was deleted.
Oops, something went wrong.
14 changes: 14 additions & 0 deletions
14
api/src/main/java/com/ineat/colistracker/domain/usecase/courier/CourierFetcher.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package com.ineat.colistracker.domain.usecase.courier; | ||
|
||
import com.ineat.colistracker.domain.model.Courier; | ||
import io.smallrye.mutiny.Multi; | ||
|
||
import javax.enterprise.context.ApplicationScoped; | ||
|
||
@ApplicationScoped | ||
public class CourierFetcher { | ||
|
||
public Multi<Courier> all() { | ||
return Multi.createFrom().items(Courier.values()); | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
api/src/main/java/com/ineat/colistracker/domain/usecase/tracking/TrackingAppender.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package com.ineat.colistracker.domain.usecase.tracking; | ||
|
||
import com.ineat.colistracker.domain.model.Tracking; | ||
import com.ineat.colistracker.domain.repository.TrackingRepository; | ||
import io.smallrye.mutiny.Uni; | ||
import lombok.RequiredArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
|
||
import javax.enterprise.context.ApplicationScoped; | ||
import javax.transaction.Transactional; | ||
|
||
@ApplicationScoped | ||
@RequiredArgsConstructor | ||
@Slf4j | ||
public class TrackingAppender { | ||
|
||
private final TrackingRepository trackingRepository; | ||
|
||
@Transactional | ||
public Uni<Tracking> execute(Tracking tracking) { | ||
tracking.activate(); | ||
|
||
return trackingRepository | ||
.create(tracking) | ||
.onItem().invoke(created -> log.info("Created tracking with id {} and tracking id {}", created.id, created.trackingId)); | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
api/src/main/java/com/ineat/colistracker/domain/usecase/tracking/TrackingFetcher.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package com.ineat.colistracker.domain.usecase.tracking; | ||
|
||
import com.ineat.colistracker.domain.model.Tracking; | ||
import com.ineat.colistracker.domain.repository.TrackingRepository; | ||
import io.smallrye.mutiny.Multi; | ||
import io.smallrye.mutiny.Uni; | ||
import lombok.RequiredArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
|
||
import javax.enterprise.context.ApplicationScoped; | ||
import javax.transaction.Transactional; | ||
|
||
@ApplicationScoped | ||
@RequiredArgsConstructor | ||
@Slf4j | ||
public class TrackingFetcher { | ||
private final TrackingRepository trackingRepository; | ||
|
||
@Transactional | ||
public Multi<Tracking> findAll() { | ||
return trackingRepository.all(); | ||
} | ||
|
||
public Uni<Tracking> getById(Long id) { | ||
return trackingRepository.getById(id); | ||
} | ||
} |
47 changes: 47 additions & 0 deletions
47
api/src/main/java/com/ineat/colistracker/domain/usecase/tracking/TrackingPatcher.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package com.ineat.colistracker.domain.usecase.tracking; | ||
|
||
import com.ineat.colistracker.domain.model.Tracking; | ||
import com.ineat.colistracker.domain.repository.TrackingRepository; | ||
import io.smallrye.mutiny.Uni; | ||
import lombok.RequiredArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
|
||
import javax.enterprise.context.ApplicationScoped; | ||
import javax.transaction.Transactional; | ||
|
||
@ApplicationScoped | ||
@Slf4j | ||
@RequiredArgsConstructor | ||
public class TrackingPatcher { | ||
|
||
private final TrackingRepository trackingRepository; | ||
|
||
@Transactional | ||
public Uni<Tracking> execute(Tracking tracking) { | ||
if (tracking.id == null) { | ||
return Uni.createFrom().failure(() -> new IllegalArgumentException("Tracking to update should not have null id")); | ||
} | ||
|
||
return trackingRepository.getById(tracking.id) | ||
.onFailure().invoke(error -> log.error("Could not find tracking with id {} to update", tracking.id, error)) | ||
.onItem().transform(existing -> updateExistingTrackingWithFieldsToModify(tracking, existing)) | ||
.onItem().call(trackingRepository::update) | ||
.onItem().invoke(updated -> log.info("Colis with id {} successfully updated", updated.id)); | ||
} | ||
|
||
private Tracking updateExistingTrackingWithFieldsToModify(Tracking toModify, Tracking existing) { | ||
if (toModify.name != null) { | ||
existing.name = toModify.name; | ||
} | ||
|
||
if (toModify.trackingId != null) { | ||
existing.trackingId = toModify.trackingId; | ||
} | ||
|
||
if (toModify.status != null) { | ||
existing.status = toModify.status; | ||
} | ||
|
||
return existing; | ||
} | ||
} |
Oops, something went wrong.