1
0

add SpringBoot 2.7.x application

This commit is contained in:
Michael Hoennig
2022-07-28 16:51:36 +02:00
parent feff1b5794
commit 6c33bbe780
10 changed files with 510 additions and 142 deletions

View File

@ -0,0 +1,13 @@
package net.hostsharing.hsadminng;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class HsadminNgApplication {
public static void main(String[] args) {
SpringApplication.run(HsadminNgApplication.class, args);
}
}

View File

@ -0,0 +1,37 @@
package net.hostsharing.hsadminng;
import org.hibernate.type.PostgresUUIDType;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.transaction.Transactional;
import java.util.List;
@Controller
public class TestController {
@PersistenceContext
private EntityManager em;
@RequestMapping(value = "/api/test", method = RequestMethod.GET)
public List<Object> test() {
final var query = em.createNativeQuery("select * from public.rbacuser")
.unwrap(org.hibernate.query.NativeQuery.class)
.addScalar("uuidColumn", PostgresUUIDType.INSTANCE);
return query.getResultList();
}
@Transactional
@ResponseBody
@RequestMapping(value = "/api/currentUser", method = RequestMethod.GET)
public String currentUser() {
em.createNativeQuery("SET LOCAL hsadminng.currentUser = 'mike@hostsharing.net';").executeUpdate();
em.createNativeQuery("SET LOCAL hsadminng.assumedRoles = '';").executeUpdate();
final var query = em.createNativeQuery("select currentUser()");
return query.getSingleResult().toString();
}
}

View File

@ -0,0 +1,11 @@
spring:
datasource:
driver-class-name: org.postgresql.Driver
password: password
url: jdbc:postgresql://localhost:5432/postgres
username: postgres
sql:
init:
mode: never