Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
lucas-dclrcq committed Feb 24, 2021
1 parent c97915d commit a65d7e0
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
public interface ColisRepository {
Uni<Colis> create(Colis colis);

Uni<Colis> getById(Long id);

Multi<Colis> all();

Uni<Boolean> delete(Long id);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@

@Mapper(componentModel = "cdi")
public interface ColisMapper {
Colis toDomain(ColisDTO dto);

ColisDTO toDTO(Colis colis);

Colis toDomain(CreateOrUpdateColisDTO dto);

}
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,8 @@
import javax.ws.rs.*;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import java.net.URI;

@Path("/api/colis")
@Path("/api/trackings")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
public class ColisResource {
Expand Down Expand Up @@ -47,6 +46,12 @@ public Uni<Response> delete(@PathParam("id") Long id) {
.onItem().transform(res -> Response.ok().build());
}

@GET
@Path("/{id}")
public Uni<ColisDTO> get(@PathParam("id") Long id) {
return null;
}

@PUT
@Path("/{id}")
public Uni<ColisDTO> update(@PathParam("id") Long id, CreateOrUpdateColisDTO dto) {
Expand All @@ -56,4 +61,10 @@ public Uni<ColisDTO> update(@PathParam("id") Long id, CreateOrUpdateColisDTO dto
return colisService.update(colis)
.onItem().transform(updated -> colisMapper.toDTO(updated));
}

@POST
@Path("/{id}/archive")
public Uni<Response> archive(@PathParam("id") Long id) {
return null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import javax.persistence.*;
import java.time.LocalDateTime;
import java.util.Set;

@Entity
@Table(name = "colis")
Expand All @@ -27,4 +28,11 @@ public class ColisEntity {
@UpdateTimestamp
public LocalDateTime updated;

@OneToMany(
mappedBy = "colis",
cascade = CascadeType.ALL,
orphanRemoval = true
)
public Set<TrackingEventEntity> trackingHistory;

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package com.ineat.colistracker.infrastructure.database.entity;

import javax.persistence.*;
import java.time.LocalDateTime;

@Entity
@Table(name = "tracking_event")
public class TrackingEventEntity {
@Id
@Column(name = "id", columnDefinition = "SERIAL")
@GeneratedValue(strategy = GenerationType.IDENTITY)
public Long id;

public LocalDateTime time;

public String description;

@ManyToOne(fetch = FetchType.LAZY)
public ColisEntity colis;
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,12 @@ public Uni<Colis> create(Colis colis) {
.map(persisted -> mapper.toDomain(entity));
}

@Override
public Uni<Colis> getById(Long id) {
return findById(id)
.onItem().transform(entity -> mapper.toDomain(entity));
}

@Override
public Multi<Colis> all() {
return findAll().stream()
Expand Down

0 comments on commit a65d7e0

Please sign in to comment.