1
0

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

@ -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> {
}