This commit is contained in:
@@ -0,0 +1,9 @@
|
||||
package fr.codeanddata.pathit.core;
|
||||
|
||||
import fr.codeanddata.pathit.core.models.PathMap;
|
||||
import io.smallrye.mutiny.Uni;
|
||||
|
||||
public interface PathMapRepository {
|
||||
Uni<PathMap> create(PathMap pathMap);
|
||||
Uni<PathMap> getByHash(String hash);
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
package fr.codeanddata.pathit.core.mappers;
|
||||
|
||||
import fr.codeanddata.pathit.core.models.PathMap;
|
||||
import fr.codeanddata.pathit.core.models.PushRequest;
|
||||
import org.mapstruct.Mapper;
|
||||
import org.mapstruct.MappingConstants;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
@Mapper(componentModel = MappingConstants.ComponentModel.CDI)
|
||||
public abstract class PathMapMapper {
|
||||
public PathMap toModel(PushRequest pushRequest) {
|
||||
return PathMap.builder()
|
||||
.hash(pushRequest.getHash())
|
||||
.destination(pushRequest.getDestination())
|
||||
.creationDate(LocalDateTime.now())
|
||||
.build();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
package fr.codeanddata.pathit.core.models;
|
||||
|
||||
import lombok.*;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@Builder
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
public class PathMap {
|
||||
/**
|
||||
*
|
||||
*/
|
||||
String hash;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
String destination;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
LocalDateTime creationDate;
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
package fr.codeanddata.pathit.core.models;
|
||||
|
||||
|
||||
import lombok.*;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@Builder
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
public class PushRequest {
|
||||
/**
|
||||
*
|
||||
*/
|
||||
String hash;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
String destination;
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
package fr.codeanddata.pathit.core.resources;
|
||||
|
||||
import fr.codeanddata.pathit.core.models.PathMap;
|
||||
import fr.codeanddata.pathit.core.models.PushRequest;
|
||||
import fr.codeanddata.pathit.core.services.PathMapService;
|
||||
import io.smallrye.mutiny.Uni;
|
||||
import jakarta.annotation.security.RolesAllowed;
|
||||
import jakarta.inject.Inject;
|
||||
import jakarta.ws.rs.Consumes;
|
||||
import jakarta.ws.rs.POST;
|
||||
import jakarta.ws.rs.Path;
|
||||
import jakarta.ws.rs.Produces;
|
||||
import jakarta.ws.rs.core.MediaType;
|
||||
|
||||
@Path("/admin/api/pathmap")
|
||||
public class AdminResource {
|
||||
|
||||
@Inject
|
||||
PathMapService pathMapService;
|
||||
|
||||
@POST
|
||||
@Consumes(MediaType.APPLICATION_JSON)
|
||||
@Produces(MediaType.APPLICATION_JSON)
|
||||
@RolesAllowed("pathit")
|
||||
public Uni<PathMap> push(PushRequest pushRequest) {
|
||||
return pathMapService.push(pushRequest);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
package fr.codeanddata.pathit.core.resources;
|
||||
|
||||
import fr.codeanddata.pathit.core.services.PathMapService;
|
||||
import io.quarkus.qute.Template;
|
||||
import io.smallrye.mutiny.Uni;
|
||||
import jakarta.annotation.security.PermitAll;
|
||||
import jakarta.inject.Inject;
|
||||
import jakarta.ws.rs.GET;
|
||||
import jakarta.ws.rs.Path;
|
||||
import jakarta.ws.rs.Produces;
|
||||
import jakarta.ws.rs.core.MediaType;
|
||||
import jakarta.ws.rs.core.Response;
|
||||
import org.jboss.resteasy.reactive.RestPath;
|
||||
|
||||
@Path("/")
|
||||
public class PathMapResource {
|
||||
|
||||
@Inject
|
||||
PathMapService pathMapService;
|
||||
|
||||
@Inject
|
||||
Template redirect;
|
||||
|
||||
@GET
|
||||
@Path("{hash}")
|
||||
@Produces(MediaType.TEXT_HTML)
|
||||
@PermitAll
|
||||
public Uni<Response> mapPath(@RestPath String hash) {
|
||||
return pathMapService.getByHash(hash)
|
||||
.map(pathMap -> Response.status(Response.Status.FOUND)
|
||||
.header("Location", pathMap.getDestination())
|
||||
.entity(redirect.data("location", pathMap.getDestination()).render())
|
||||
.build())
|
||||
|
||||
.onFailure().recoverWithItem(e -> Response
|
||||
.status(Response.Status.SERVICE_UNAVAILABLE)
|
||||
.entity(redirect.data("location", hash).render())
|
||||
.build());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
package fr.codeanddata.pathit.core.services;
|
||||
|
||||
import fr.codeanddata.pathit.core.PathMapRepository;
|
||||
import fr.codeanddata.pathit.core.mappers.PathMapMapper;
|
||||
import fr.codeanddata.pathit.core.models.PathMap;
|
||||
import fr.codeanddata.pathit.core.models.PushRequest;
|
||||
import io.smallrye.mutiny.Uni;
|
||||
import jakarta.enterprise.context.ApplicationScoped;
|
||||
import jakarta.inject.Inject;
|
||||
|
||||
@ApplicationScoped
|
||||
public class PathMapService {
|
||||
@Inject
|
||||
PathMapRepository pathMapRepository;
|
||||
|
||||
@Inject
|
||||
PathMapMapper mapper;
|
||||
|
||||
public Uni<PathMap> push(PushRequest pushRequest) {
|
||||
return pathMapRepository.create(mapper.toModel(pushRequest));
|
||||
}
|
||||
|
||||
public Uni<PathMap> getByHash(String hash) {
|
||||
return pathMapRepository.getByHash(hash);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
name: Pathit Core
|
||||
#description: Do something useful.
|
||||
metadata:
|
||||
# keywords:
|
||||
# - pathit-pathit
|
||||
# guide: ... # To create and publish this guide, see https://github.com/quarkiverse/quarkiverse/wiki#documenting-your-extension
|
||||
# categories:
|
||||
# - "miscellaneous"
|
||||
# status: "preview"
|
||||
@@ -0,0 +1 @@
|
||||
quarkus.native.resources.includes=src/main/resources/templates/**
|
||||
@@ -0,0 +1,9 @@
|
||||
<html lang="en">
|
||||
<head>
|
||||
<title>{location}</title>
|
||||
<meta http-equiv="refresh" content="5;url={location}"/>
|
||||
</head>
|
||||
<body>
|
||||
<p>You will be redirect soon. Please wait.</p>
|
||||
</body>
|
||||
</html>
|
||||
Reference in New Issue
Block a user