Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
lucas-dclrcq committed Mar 4, 2021
1 parent c97915d commit 5d09c1c
Show file tree
Hide file tree
Showing 48 changed files with 1,090 additions and 407 deletions.
407 changes: 246 additions & 161 deletions api/pom.xml

Large diffs are not rendered by default.

13 changes: 13 additions & 0 deletions api/src/main/docker/docker-compose.dev.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,19 @@
version: '2'

services:
kafka:
image: landoop/fast-data-dev:latest
ports:
- "9092:9092"
- "9081:8081"
- "9082:8082"
- "9083:8083"
- "2181:2181"
- "3030:3030"
- "9581-9585:9581-9585"
environment:
- ADV_HOST=127.0.0.1

database:
image: postgres
environment:
Expand Down
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 api/src/main/java/com/ineat/colistracker/domain/model/Colis.java

This file was deleted.

27 changes: 27 additions & 0 deletions api/src/main/java/com/ineat/colistracker/domain/model/Courier.java
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);
}
}
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;
}
}
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;
}
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
}

This file was deleted.

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);
}
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);
}

This file was deleted.

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());
}
}
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));
}
}
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);
}
}
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;
}
}
Loading

0 comments on commit 5d09c1c

Please sign in to comment.