This commit is contained in:
@@ -0,0 +1,28 @@
|
||||
package fr.codeanddata.pathit.storage.postgres.entity;
|
||||
|
||||
import io.quarkus.hibernate.reactive.panache.PanacheEntity;
|
||||
import jakarta.persistence.Column;
|
||||
import jakarta.persistence.Entity;
|
||||
import jakarta.persistence.Table;
|
||||
import lombok.*;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
@Entity(name = "PathMap")
|
||||
@Table(name = "path_map")
|
||||
@Getter
|
||||
@Setter
|
||||
@Builder
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
public class PathMapEntity extends PanacheEntity {
|
||||
|
||||
@Column(name="hash", unique = true)
|
||||
String hash;
|
||||
|
||||
@Column(name = "destination")
|
||||
String destination;
|
||||
|
||||
@Column(name = "creation_date")
|
||||
LocalDateTime creationDate;
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
package fr.codeanddata.pathit.storage.postgres.mappers;
|
||||
|
||||
import fr.codeanddata.pathit.core.models.PathMap;
|
||||
import fr.codeanddata.pathit.storage.postgres.entity.PathMapEntity;
|
||||
import org.mapstruct.Mapper;
|
||||
import org.mapstruct.MappingConstants;
|
||||
|
||||
@Mapper(componentModel = MappingConstants.ComponentModel.CDI)
|
||||
public interface PathMapEntityMapper {
|
||||
PathMap toModel(PathMapEntity pathMapEntity);
|
||||
PathMapEntity toEntity(PathMap model);
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
package fr.codeanddata.pathit.storage.postgres.repository;
|
||||
|
||||
import fr.codeanddata.pathit.core.PathMapRepository;
|
||||
import fr.codeanddata.pathit.core.models.PathMap;
|
||||
import fr.codeanddata.pathit.storage.postgres.entity.PathMapEntity;
|
||||
import fr.codeanddata.pathit.storage.postgres.mappers.PathMapEntityMapper;
|
||||
import io.quarkus.hibernate.reactive.panache.PanacheRepository;
|
||||
import io.quarkus.hibernate.reactive.panache.common.WithSession;
|
||||
import io.quarkus.hibernate.reactive.panache.common.WithTransaction;
|
||||
import io.smallrye.mutiny.Uni;
|
||||
import jakarta.enterprise.context.ApplicationScoped;
|
||||
import jakarta.inject.Inject;
|
||||
|
||||
@ApplicationScoped
|
||||
public class PathMapJpaRepository implements PathMapRepository, PanacheRepository<PathMapEntity> {
|
||||
|
||||
@Inject
|
||||
PathMapEntityMapper mapper;
|
||||
|
||||
@WithTransaction
|
||||
public Uni<PathMap> create(PathMap pathMap) {
|
||||
final PathMapEntity entity = mapper.toEntity(pathMap);
|
||||
return entity.persist()
|
||||
.map(o -> (PathMapEntity) o)
|
||||
.map(mapper::toModel);
|
||||
}
|
||||
|
||||
@WithSession
|
||||
public Uni<PathMap> getByHash(String hash) {
|
||||
return find("hash = ?1", hash)
|
||||
.singleResult()
|
||||
.map(e -> mapper.toModel(e));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
name: Pathit Storage Postgres
|
||||
#description: Do something useful.
|
||||
metadata:
|
||||
# keywords:
|
||||
# - pathit-storage-postgres
|
||||
# guide: ... # To create and publish this guide, see https://github.com/quarkiverse/quarkiverse/wiki#documenting-your-extension
|
||||
# categories:
|
||||
# - "miscellaneous"
|
||||
# status: "preview"
|
||||
@@ -0,0 +1,11 @@
|
||||
quarkus.datasource.db-kind=postgresql
|
||||
|
||||
quarkus.flyway.enabled=true
|
||||
quarkus.flyway.active=false
|
||||
quarkus.flyway.migrate-at-start=true
|
||||
quarkus.flyway.baseline-on-migrate=true
|
||||
quarkus.flyway.baseline-version=0.9
|
||||
quarkus.flyway.baseline-description=Initial version
|
||||
|
||||
quarkus.native.resources.includes=src/main/resources/db/migration/**
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
create sequence path_map_SEQ start with 1 increment by 50;
|
||||
|
||||
create table path_map
|
||||
(
|
||||
id bigint not null,
|
||||
creation_date timestamp(6),
|
||||
destination varchar(255),
|
||||
hash varchar(255) unique,
|
||||
primary key (id)
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user