Fix LazyInitializationException and update hostname format
This commit is contained in:
parent
3b43039a29
commit
94363b9429
@ -4,11 +4,21 @@ import com.hithomelabs.CFTunnels.Entity.Request;
|
|||||||
import org.springframework.data.domain.Page;
|
import org.springframework.data.domain.Page;
|
||||||
import org.springframework.data.domain.Pageable;
|
import org.springframework.data.domain.Pageable;
|
||||||
import org.springframework.data.jpa.repository.JpaRepository;
|
import org.springframework.data.jpa.repository.JpaRepository;
|
||||||
|
import org.springframework.data.jpa.repository.Query;
|
||||||
|
import org.springframework.data.repository.query.Param;
|
||||||
import org.springframework.stereotype.Repository;
|
import org.springframework.stereotype.Repository;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Optional;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
@Repository
|
@Repository
|
||||||
public interface RequestRepository extends JpaRepository<Request, UUID> {
|
public interface RequestRepository extends JpaRepository<Request, UUID> {
|
||||||
Page<Request> findByStatus(Request.RequestStatus status, Pageable pageable);
|
Page<Request> findByStatus(Request.RequestStatus status, Pageable pageable);
|
||||||
|
|
||||||
|
@Query("SELECT r FROM Request r JOIN FETCH r.mapping m JOIN FETCH m.tunnel JOIN FETCH r.createdBy LEFT JOIN FETCH r.acceptedBy")
|
||||||
|
List<Request> findAllWithDetails();
|
||||||
|
|
||||||
|
@Query("SELECT r FROM Request r JOIN FETCH r.mapping m JOIN FETCH m.tunnel JOIN FETCH r.createdBy LEFT JOIN FETCH r.acceptedBy WHERE r.id = :id")
|
||||||
|
Optional<Request> findByIdWithDetails(@Param("id") UUID id);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -59,8 +59,9 @@ public class MappingRequestService {
|
|||||||
return createRequest(mapping, user);
|
return createRequest(mapping, user);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Transactional(readOnly = true)
|
||||||
public List<Request> getAllRequests() {
|
public List<Request> getAllRequests() {
|
||||||
return requestRepository.findAll();
|
return requestRepository.findAllWithDetails();
|
||||||
}
|
}
|
||||||
|
|
||||||
public User mapUser(OidcUser oidcUser){
|
public User mapUser(OidcUser oidcUser){
|
||||||
@ -99,7 +100,7 @@ public class MappingRequestService {
|
|||||||
|
|
||||||
@Transactional
|
@Transactional
|
||||||
public Request approveRequest(UUID requestId, User approver) {
|
public Request approveRequest(UUID requestId, User approver) {
|
||||||
Request request = requestRepository.findById(requestId)
|
Request request = requestRepository.findByIdWithDetails(requestId)
|
||||||
.orElseThrow(() -> new NoSuchElementException("Request not found"));
|
.orElseThrow(() -> new NoSuchElementException("Request not found"));
|
||||||
|
|
||||||
if (request.getStatus() != Request.RequestStatus.PENDING) {
|
if (request.getStatus() != Request.RequestStatus.PENDING) {
|
||||||
@ -127,7 +128,7 @@ public class MappingRequestService {
|
|||||||
|
|
||||||
@Transactional
|
@Transactional
|
||||||
public Request rejectRequest(UUID requestId, User rejecter) {
|
public Request rejectRequest(UUID requestId, User rejecter) {
|
||||||
Request request = requestRepository.findById(requestId)
|
Request request = requestRepository.findByIdWithDetails(requestId)
|
||||||
.orElseThrow(() -> new NoSuchElementException("Request not found"));
|
.orElseThrow(() -> new NoSuchElementException("Request not found"));
|
||||||
|
|
||||||
if (request.getStatus() != Request.RequestStatus.PENDING) {
|
if (request.getStatus() != Request.RequestStatus.PENDING) {
|
||||||
@ -145,7 +146,7 @@ public class MappingRequestService {
|
|||||||
Tunnel tunnel = mapping.getTunnel();
|
Tunnel tunnel = mapping.getTunnel();
|
||||||
String protocol = mapping.getProtocol().name().toLowerCase();
|
String protocol = mapping.getProtocol().name().toLowerCase();
|
||||||
String service = protocol + "://" + SERVER_IP + ":" + mapping.getPort();
|
String service = protocol + "://" + SERVER_IP + ":" + mapping.getPort();
|
||||||
String hostname = mapping.getSubdomain() + "." + tunnel.getName() + ".hithomelabs.com";
|
String hostname = mapping.getSubdomain() + ".hithomelabs.com";
|
||||||
return new Ingress(service, hostname, null, null);
|
return new Ingress(service, hostname, null, null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -7,6 +7,6 @@ management.endpoint.health.show-details=always
|
|||||||
logging.level.org.hibernate.SQL=DEBUG
|
logging.level.org.hibernate.SQL=DEBUG
|
||||||
debug=true
|
debug=true
|
||||||
|
|
||||||
spring.jpa.hibernate.ddl-auto=create-drop
|
spring.jpa.hibernate.ddl-auto=update
|
||||||
spring.jpa.show-sql=true
|
spring.jpa.show-sql=true
|
||||||
spring.datasource.url=jdbc:postgresql://localhost:5432/cftunnel
|
spring.datasource.url=jdbc:postgresql://localhost:5432/cftunnel
|
||||||
|
|||||||
@ -7,6 +7,6 @@ spring.datasource.password=${POSTGRES_PASSWORD}
|
|||||||
spring.datasource.driver-class-name=org.postgresql.Driver
|
spring.datasource.driver-class-name=org.postgresql.Driver
|
||||||
|
|
||||||
# JPA Configuration
|
# JPA Configuration
|
||||||
spring.jpa.hibernate.ddl-auto=create-drop
|
spring.jpa.hibernate.ddl-auto=update
|
||||||
spring.jpa.show-sql=true
|
spring.jpa.show-sql=false
|
||||||
spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.PostgreSQLDialect
|
spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.PostgreSQLDialect
|
||||||
@ -7,6 +7,6 @@ spring.datasource.password=${POSTGRES_PASSWORD}
|
|||||||
spring.datasource.driver-class-name=org.postgresql.Driver
|
spring.datasource.driver-class-name=org.postgresql.Driver
|
||||||
|
|
||||||
# JPA Configuration
|
# JPA Configuration
|
||||||
spring.jpa.hibernate.ddl-auto=create-drop
|
spring.jpa.hibernate.ddl-auto=update
|
||||||
spring.jpa.show-sql=true
|
spring.jpa.show-sql=true
|
||||||
spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.PostgreSQLDialect
|
spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.PostgreSQLDialect
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user