PackagerEntity, -Repository and -Controller

This commit is contained in:
Michael Hoennig 2022-07-29 16:13:38 +02:00
parent 46957dc590
commit 4721d1be23
7 changed files with 85 additions and 11 deletions

View File

@ -2,13 +2,15 @@
<!-- generated TOC begin: -->
- [Setting up the Development Environment](#setting-up-the-development-environment)
- [SDKMAN](#sdkman)
- [PostgreSQL Server](#postgresql-server)
- [Markdown with PlantUML plugin](#markdown-with-plantuml-plugin)
- [Other Tools](#other-tools)
- [SDKMAN](#sdkman)
- [PostgreSQL Server](#postgresql-server)
- [Markdown](#markdown)
- [Render Markdown embedded PlantUML](#render-markdown-embedded-plantuml)
- [Other Tools](#other-tools)
- [Running the SQL files](#running-the-sql-files)
- [For RBAC](#for-rbac)
- [For Historization](#for-historization)
- [For RBAC](#for-rbac)
- [For Historization](#for-historization)
<!-- generated TOC end. -->
## Setting up the Development Environment
@ -40,12 +42,17 @@ If you have at least Docker, the Java JDK and Gradle installed in appropriate ve
# the following command should reply with "pong":
curl http://localhost:8080/api/ping
# the following command should return a JSON array with just the customer aac:
# the following command should return a JSON array with just all customers:
curl \
-H 'current-user: mike@hostsharing.net' \
-H 'assumed-roles: customer#aac.admin' \
http://localhost:8080/api/customer
# the following command should return a JSON array with just all packages visible for the admin of the customer aab:
curl \
-H 'current-user: mike@hostsharing.net' \
-H 'assumed-roles: customer#aab.admin' \
http://localhost:8080/api/package
The latter `curl` command actually goes through the database server.
<big>&#9432;</big>

View File

@ -1,4 +1,4 @@
package net.hostsharing.hsadminng.customer;
package net.hostsharing.hsadminng.hscustomer;
import net.hostsharing.hsadminng.context.Context;
import org.springframework.beans.factory.annotation.Autowired;

View File

@ -1,4 +1,4 @@
package net.hostsharing.hsadminng.customer;
package net.hostsharing.hsadminng.hscustomer;
import lombok.Getter;

View File

@ -1,4 +1,4 @@
package net.hostsharing.hsadminng.customer;
package net.hostsharing.hsadminng.hscustomer;
import org.springframework.data.jpa.repository.JpaRepository;

View File

@ -0,0 +1,37 @@
package net.hostsharing.hsadminng.hspackage;
import net.hostsharing.hsadminng.context.Context;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import javax.transaction.Transactional;
import java.util.List;
@Controller
public class PackageController {
@Autowired
private Context context;
@Autowired
private PackageRepository packageRepository;
@ResponseBody
@RequestMapping(value = "/api/package", method = RequestMethod.GET)
@Transactional
public List<PackageEntity> listPackages(
@RequestHeader(value = "current-user") String userName,
@RequestHeader(value = "assumed-roles", required = false) String assumedRoles
) {
context.setCurrentUser(userName);
if (assumedRoles != null && !assumedRoles.isBlank()) {
context.assumeRoles(assumedRoles);
}
return packageRepository.findAll();
}
}

View File

@ -0,0 +1,21 @@
package net.hostsharing.hsadminng.hspackage;
import lombok.Getter;
import net.hostsharing.hsadminng.hscustomer.CustomerEntity;
import javax.persistence.*;
import java.util.UUID;
@Entity
@Table(name = "package_rv")
@Getter
public class PackageEntity {
private @Id UUID uuid;
private String name;
@ManyToOne(optional = false)
@JoinColumn(name = "customeruuid")
private CustomerEntity customer;
}

View File

@ -0,0 +1,9 @@
package net.hostsharing.hsadminng.hspackage;
import org.springframework.data.jpa.repository.JpaRepository;
import java.util.UUID;
public interface PackageRepository extends JpaRepository<PackageEntity, UUID> {
}