-
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
c937414
commit c97915d
Showing
17 changed files
with
206 additions
and
33 deletions.
There are no files selected for viewing
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
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 |
---|---|---|
@@ -1,4 +1,11 @@ | ||
version: '3.8' | ||
version: '2' | ||
|
||
services: | ||
database: | ||
image: postgres | ||
environment: | ||
POSTGRES_USER: colistracker | ||
POSTGRES_PASSWORD: colistracker | ||
POSTGRES_DB: colistracker | ||
ports: | ||
- 5432:5432 |
4 changes: 2 additions & 2 deletions
4
api/src/main/java/com/ineat/colistracker/domain/model/Colis.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
10 changes: 7 additions & 3 deletions
10
api/src/main/java/com/ineat/colistracker/domain/repository/ColisRepository.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 |
---|---|---|
@@ -1,11 +1,15 @@ | ||
package org.acme.domain.repository; | ||
package com.ineat.colistracker.domain.repository; | ||
|
||
import com.ineat.colistracker.domain.model.Colis; | ||
import io.smallrye.mutiny.Multi; | ||
import io.smallrye.mutiny.Uni; | ||
import org.acme.domain.model.Colis; | ||
|
||
public interface ColisRepository { | ||
Uni<Void> create(Colis colis); | ||
Uni<Colis> create(Colis colis); | ||
|
||
Multi<Colis> all(); | ||
|
||
Uni<Boolean> delete(Long id); | ||
|
||
Uni<Colis> update(Colis colis); | ||
} |
36 changes: 35 additions & 1 deletion
36
api/src/main/java/com/ineat/colistracker/domain/service/ColisService.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 |
---|---|---|
@@ -1,7 +1,41 @@ | ||
package org.acme.domain.service; | ||
package com.ineat.colistracker.domain.service; | ||
|
||
import com.ineat.colistracker.domain.model.Colis; | ||
import com.ineat.colistracker.domain.repository.ColisRepository; | ||
import io.smallrye.mutiny.Multi; | ||
import io.smallrye.mutiny.Uni; | ||
import lombok.extern.java.Log; | ||
import lombok.extern.slf4j.Slf4j; | ||
|
||
import javax.enterprise.context.ApplicationScoped; | ||
import javax.inject.Inject; | ||
|
||
@ApplicationScoped | ||
@Slf4j | ||
public class ColisService { | ||
|
||
@Inject | ||
ColisRepository colisRepository; | ||
|
||
public Uni<Colis> create(Colis colis) { | ||
return colisRepository | ||
.create(colis) | ||
.onItem().invoke(created -> log.info("Created colis with id {} and tracking id {}", created.id, created.trackingId)); | ||
} | ||
|
||
public Multi<Colis> findAll() { | ||
return colisRepository.all(); | ||
} | ||
|
||
public Uni<Boolean> delete(Long id) { | ||
return colisRepository | ||
.delete(id) | ||
.onItem().invoke(aBoolean -> log.info("Colis with id {} deleted : {}", id, aBoolean)); | ||
} | ||
|
||
public Uni<Colis> update(Colis colis) { | ||
return colisRepository | ||
.update(colis) | ||
.onItem().invoke(updated -> log.info("Colis with id {} successfully updated", updated.id)); | ||
} | ||
} |
13 changes: 12 additions & 1 deletion
13
api/src/main/java/com/ineat/colistracker/infrastructure/api/dto/ColisDTO.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 |
---|---|---|
@@ -1,4 +1,15 @@ | ||
package org.acme.infrastructure.api.dto; | ||
package com.ineat.colistracker.infrastructure.api.dto; | ||
|
||
import com.fasterxml.jackson.annotation.JsonFormat; | ||
|
||
import java.time.LocalDateTime; | ||
|
||
public class ColisDTO { | ||
public Long id; | ||
public String name; | ||
public String trackingId; | ||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss") | ||
public LocalDateTime created; | ||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss") | ||
public LocalDateTime updated; | ||
} |
2 changes: 2 additions & 0 deletions
2
api/src/main/java/com/ineat/colistracker/infrastructure/api/dto/CreateOrUpdateColisDTO.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 |
---|---|---|
@@ -1,4 +1,6 @@ | ||
package com.ineat.colistracker.infrastructure.api.dto; | ||
|
||
public class CreateOrUpdateColisDTO { | ||
public String name; | ||
public String trackingId; | ||
} |
10 changes: 6 additions & 4 deletions
10
api/src/main/java/com/ineat/colistracker/infrastructure/api/mapper/ColisMapper.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 |
---|---|---|
@@ -1,13 +1,15 @@ | ||
package org.acme.infrastructure.api.mapper; | ||
package com.ineat.colistracker.infrastructure.api.mapper; | ||
|
||
import org.acme.domain.model.Colis; | ||
import org.acme.infrastructure.api.dto.ColisDTO; | ||
import com.ineat.colistracker.domain.model.Colis; | ||
import com.ineat.colistracker.infrastructure.api.dto.ColisDTO; | ||
import com.ineat.colistracker.infrastructure.api.dto.CreateOrUpdateColisDTO; | ||
import org.mapstruct.Mapper; | ||
|
||
@Mapper(componentModel = "cdi") | ||
public interface ColisMapper { | ||
Colis toDomain(ColisDTO dto); | ||
|
||
ColisDTO toEntity(Colis colis); | ||
ColisDTO toDTO(Colis colis); | ||
|
||
Colis toDomain(CreateOrUpdateColisDTO dto); | ||
} |
57 changes: 56 additions & 1 deletion
57
api/src/main/java/com/ineat/colistracker/infrastructure/api/resource/ColisResource.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 |
---|---|---|
@@ -1,4 +1,59 @@ | ||
package org.acme.infrastructure.api.resource; | ||
package com.ineat.colistracker.infrastructure.api.resource; | ||
|
||
import com.ineat.colistracker.domain.model.Colis; | ||
import com.ineat.colistracker.domain.service.ColisService; | ||
import com.ineat.colistracker.infrastructure.api.dto.ColisDTO; | ||
import com.ineat.colistracker.infrastructure.api.dto.CreateOrUpdateColisDTO; | ||
import com.ineat.colistracker.infrastructure.api.mapper.ColisMapper; | ||
import io.smallrye.mutiny.Multi; | ||
import io.smallrye.mutiny.Uni; | ||
|
||
import javax.inject.Inject; | ||
import javax.ws.rs.*; | ||
import javax.ws.rs.core.MediaType; | ||
import javax.ws.rs.core.Response; | ||
import java.net.URI; | ||
|
||
@Path("/api/colis") | ||
@Consumes(MediaType.APPLICATION_JSON) | ||
@Produces(MediaType.APPLICATION_JSON) | ||
public class ColisResource { | ||
|
||
@Inject | ||
ColisService colisService; | ||
|
||
@Inject | ||
ColisMapper colisMapper; | ||
|
||
@POST | ||
public Uni<Response> create(CreateOrUpdateColisDTO body) { | ||
final Colis colis = colisMapper.toDomain(body); | ||
|
||
return colisService.create(colis) | ||
.onItem().transform(created -> colisMapper.toDTO(created)) | ||
.onItem().transform(created -> Response.status(Response.Status.CREATED).entity(created).build()); | ||
} | ||
|
||
@GET | ||
public Multi<ColisDTO> findAll() { | ||
return colisService.findAll() | ||
.onItem().transform(colis -> colisMapper.toDTO(colis)); | ||
} | ||
|
||
@DELETE | ||
@Path("/{id}") | ||
public Uni<Response> delete(@PathParam("id") Long id) { | ||
return colisService.delete(id) | ||
.onItem().transform(res -> Response.ok().build()); | ||
} | ||
|
||
@PUT | ||
@Path("/{id}") | ||
public Uni<ColisDTO> update(@PathParam("id") Long id, CreateOrUpdateColisDTO dto) { | ||
final Colis colis = colisMapper.toDomain(dto); | ||
colis.id = id; | ||
|
||
return colisService.update(colis) | ||
.onItem().transform(updated -> colisMapper.toDTO(updated)); | ||
} | ||
} |
12 changes: 9 additions & 3 deletions
12
api/src/main/java/com/ineat/colistracker/infrastructure/database/entity/ColisEntity.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 |
---|---|---|
@@ -1,24 +1,30 @@ | ||
package org.acme.infrastructure.database.entity; | ||
package com.ineat.colistracker.infrastructure.database.entity; | ||
|
||
import io.quarkus.hibernate.reactive.panache.PanacheEntity; | ||
import io.quarkus.hibernate.reactive.panache.PanacheEntityBase; | ||
import org.hibernate.annotations.CreationTimestamp; | ||
import org.hibernate.annotations.UpdateTimestamp; | ||
|
||
import javax.persistence.*; | ||
import java.time.LocalDateTime; | ||
|
||
@Entity | ||
@Table(name = "colis") | ||
public class ColisEntity { | ||
@Id | ||
@Column(name = "id", columnDefinition = "SERIAL") | ||
@GeneratedValue(strategy = GenerationType.IDENTITY) | ||
public Long id; | ||
|
||
public String name; | ||
|
||
@Column(name = "tracking_id") | ||
public String trackingId; | ||
|
||
@CreationTimestamp | ||
@Temporal(TemporalType.TIMESTAMP) | ||
public LocalDateTime created; | ||
|
||
@UpdateTimestamp | ||
@Temporal(TemporalType.TIMESTAMP) | ||
public LocalDateTime updated; | ||
|
||
} |
6 changes: 3 additions & 3 deletions
6
api/src/main/java/com/ineat/colistracker/infrastructure/database/mapper/ColisMapper.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
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
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,7 @@ | ||
quarkus.flyway.migrate-at-start = true | ||
quarkus.datasource.db-kind=postgresql | ||
quarkus.datasource.username=colistracker | ||
quarkus.datasource.password=colistracker | ||
quarkus.datasource.jdbc.url=jdbc:postgresql://localhost:5432/colistracker | ||
quarkus.datasource.reactive.url=postgresql://localhost:5432/colistracker | ||
quarkus.datasource.jdbc=false |
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 @@ | ||
CREATE TABLE colis | ||
( | ||
id BIGSERIAL, | ||
name TEXT, | ||
tracking_id TEXT, | ||
created TIMESTAMP, | ||
updated TIMESTAMP | ||
); |
2 changes: 1 addition & 1 deletion
2
api/src/test/java/com/ineat/colistracker/ExampleResourceTest.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
2 changes: 1 addition & 1 deletion
2
api/src/test/java/com/ineat/colistracker/NativeExampleResourceIT.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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package org.acme; | ||
package com.ineat.colistracker; | ||
|
||
import io.quarkus.test.junit.NativeImageTest; | ||
|
||
|
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,6 @@ | ||
= Database | ||
|
||
[plantuml, db-model, png] | ||
.... | ||
.... |