PackagerEntity, -Repository and -Controller
This commit is contained in:
parent
46957dc590
commit
4721d1be23
13
README.md
13
README.md
@ -4,11 +4,13 @@
|
|||||||
- [Setting up the Development Environment](#setting-up-the-development-environment)
|
- [Setting up the Development Environment](#setting-up-the-development-environment)
|
||||||
- [SDKMAN](#sdkman)
|
- [SDKMAN](#sdkman)
|
||||||
- [PostgreSQL Server](#postgresql-server)
|
- [PostgreSQL Server](#postgresql-server)
|
||||||
- [Markdown with PlantUML plugin](#markdown-with-plantuml-plugin)
|
- [Markdown](#markdown)
|
||||||
|
- [Render Markdown embedded PlantUML](#render-markdown-embedded-plantuml)
|
||||||
- [Other Tools](#other-tools)
|
- [Other Tools](#other-tools)
|
||||||
- [Running the SQL files](#running-the-sql-files)
|
- [Running the SQL files](#running-the-sql-files)
|
||||||
- [For RBAC](#for-rbac)
|
- [For RBAC](#for-rbac)
|
||||||
- [For Historization](#for-historization)
|
- [For Historization](#for-historization)
|
||||||
|
|
||||||
<!-- generated TOC end. -->
|
<!-- generated TOC end. -->
|
||||||
|
|
||||||
## Setting up the Development Environment
|
## 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":
|
# the following command should reply with "pong":
|
||||||
curl http://localhost:8080/api/ping
|
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 \
|
curl \
|
||||||
-H 'current-user: mike@hostsharing.net' \
|
-H 'current-user: mike@hostsharing.net' \
|
||||||
-H 'assumed-roles: customer#aac.admin' \
|
|
||||||
http://localhost:8080/api/customer
|
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.
|
The latter `curl` command actually goes through the database server.
|
||||||
|
|
||||||
<big>ⓘ</big>
|
<big>ⓘ</big>
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
package net.hostsharing.hsadminng.customer;
|
package net.hostsharing.hsadminng.hscustomer;
|
||||||
|
|
||||||
import net.hostsharing.hsadminng.context.Context;
|
import net.hostsharing.hsadminng.context.Context;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
@ -1,4 +1,4 @@
|
|||||||
package net.hostsharing.hsadminng.customer;
|
package net.hostsharing.hsadminng.hscustomer;
|
||||||
|
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
|
|
@ -1,4 +1,4 @@
|
|||||||
package net.hostsharing.hsadminng.customer;
|
package net.hostsharing.hsadminng.hscustomer;
|
||||||
|
|
||||||
import org.springframework.data.jpa.repository.JpaRepository;
|
import org.springframework.data.jpa.repository.JpaRepository;
|
||||||
|
|
@ -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();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -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;
|
||||||
|
}
|
@ -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> {
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user