hs.admin.partner from API via Controller to Entity
This commit is contained in:
@@ -1,25 +1,48 @@
|
||||
package net.hostsharing.hsadminng;
|
||||
|
||||
import net.hostsharing.hsadminng.hs.admin.generated.api.v1.model.HsAdminPersonResource;
|
||||
import net.hostsharing.hsadminng.hs.admin.person.HsAdminPersonEntity;
|
||||
import org.modelmapper.Converter;
|
||||
import org.modelmapper.ModelMapper;
|
||||
import org.modelmapper.spi.MappingContext;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.function.BiConsumer;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* A nicer API for ModelMapper.
|
||||
*/
|
||||
public abstract class Mapper {
|
||||
private final static ModelMapper modelMapper = new ModelMapper();
|
||||
|
||||
public final static ModelMapper modelMapper = new ModelMapper();
|
||||
|
||||
public static <S, T> List<T> mapList(final List<S> source, final Class<T> targetClass) {
|
||||
return mapList(source, targetClass, null);
|
||||
}
|
||||
|
||||
public static <S, T> List<T> mapList(final List<S> source, final Class<T> targetClass, final BiConsumer<S, T> postMapper) {
|
||||
return source
|
||||
.stream()
|
||||
.map(element -> modelMapper.map(element, targetClass))
|
||||
.collect(Collectors.toList());
|
||||
.stream()
|
||||
.map(element -> {
|
||||
final var target = map(element, targetClass);
|
||||
if (postMapper != null) {
|
||||
postMapper.accept(element, target);
|
||||
}
|
||||
return target;
|
||||
})
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
public static <S, T> T map(final S source, final Class<T> targetClass) {
|
||||
return modelMapper.map(source, targetClass);
|
||||
return map(source, targetClass, null);
|
||||
}
|
||||
|
||||
public static <S, T> T map(final S source, final Class<T> targetClass, final BiConsumer<S, T> postMapper) {
|
||||
final var target = modelMapper.map(source, targetClass);
|
||||
if (postMapper != null) {
|
||||
postMapper.accept(source, target);
|
||||
}
|
||||
return target;
|
||||
}
|
||||
}
|
||||
|
@@ -0,0 +1,31 @@
|
||||
package net.hostsharing.hsadminng.hs.admin.contact;
|
||||
|
||||
import com.vladmihalcea.hibernate.type.array.ListArrayType;
|
||||
import lombok.*;
|
||||
import org.hibernate.annotations.TypeDef;
|
||||
|
||||
import javax.persistence.Column;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.Id;
|
||||
import java.util.UUID;
|
||||
|
||||
@Entity
|
||||
@Getter
|
||||
@Setter
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class HsAdminContactEntity {
|
||||
|
||||
private @Id UUID uuid;
|
||||
private String label;
|
||||
|
||||
@Column(name = "postaladdress")
|
||||
private String postalAddress;
|
||||
|
||||
@Column(name = "emailaddresses", columnDefinition = "json")
|
||||
private String emailAddresses;
|
||||
|
||||
@Column(name = "phonenumbers", columnDefinition = "json")
|
||||
private String phoneNumbers;
|
||||
}
|
@@ -0,0 +1,25 @@
|
||||
package net.hostsharing.hsadminng.hs.admin.contact;
|
||||
|
||||
import org.springframework.data.jpa.repository.Query;
|
||||
import org.springframework.data.repository.Repository;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.UUID;
|
||||
|
||||
public interface HsAdminContactRepository extends Repository<HsAdminContactEntity, UUID> {
|
||||
|
||||
Optional<HsAdminContactEntity> findByUuid(UUID id);
|
||||
|
||||
@Query("""
|
||||
SELECT c FROM HsAdminContactEntity c
|
||||
WHERE :label is null
|
||||
OR c.label like concat(:label, '%')
|
||||
""")
|
||||
// TODO: join tables missing
|
||||
List<HsAdminContactEntity> findContactByOptionalLabelLike(String label);
|
||||
|
||||
HsAdminContactEntity save(final HsAdminContactEntity entity);
|
||||
|
||||
long count();
|
||||
}
|
@@ -0,0 +1,155 @@
|
||||
package net.hostsharing.hsadminng.hs.admin.partner;
|
||||
|
||||
import net.hostsharing.hsadminng.Mapper;
|
||||
import net.hostsharing.hsadminng.context.Context;
|
||||
import net.hostsharing.hsadminng.hs.admin.contact.HsAdminContactEntity;
|
||||
import net.hostsharing.hsadminng.hs.admin.generated.api.v1.api.HsAdminPartnersApi;
|
||||
import net.hostsharing.hsadminng.hs.admin.generated.api.v1.model.HsAdminContactResource;
|
||||
import net.hostsharing.hsadminng.hs.admin.generated.api.v1.model.HsAdminPartnerResource;
|
||||
import net.hostsharing.hsadminng.hs.admin.generated.api.v1.model.HsAdminPartnerUpdateResource;
|
||||
import net.hostsharing.hsadminng.hs.admin.generated.api.v1.model.HsAdminPersonResource;
|
||||
import net.hostsharing.hsadminng.hs.admin.person.HsAdminPersonEntity;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import org.springframework.web.servlet.mvc.method.annotation.MvcUriComponentsBuilder;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
import java.util.function.BiConsumer;
|
||||
|
||||
import static net.hostsharing.hsadminng.Mapper.map;
|
||||
|
||||
@RestController
|
||||
|
||||
public class HsAdminPartnerController implements HsAdminPartnersApi {
|
||||
|
||||
@Autowired
|
||||
private Context context;
|
||||
|
||||
@Autowired
|
||||
private HsAdminPartnerRepository partnerRepo;
|
||||
|
||||
@Override
|
||||
@Transactional(readOnly = true)
|
||||
public ResponseEntity<List<HsAdminPartnerResource>> listPartners(
|
||||
final String currentUser,
|
||||
final String assumedRoles,
|
||||
final String name) {
|
||||
// TODO: context.define(currentUser, assumedRoles);
|
||||
|
||||
// TODO: final var entities = partnerRepo.findPartnerByOptionalNameLike(name);
|
||||
|
||||
final var entities = List.of(
|
||||
HsAdminPartnerEntity.builder()
|
||||
.uuid(UUID.randomUUID())
|
||||
.person(HsAdminPersonEntity.builder()
|
||||
.tradeName("Ixx AG")
|
||||
.build())
|
||||
.contact(HsAdminContactEntity.builder()
|
||||
.label("Ixx AG")
|
||||
.build())
|
||||
.build(),
|
||||
HsAdminPartnerEntity.builder()
|
||||
.uuid(UUID.randomUUID())
|
||||
.person(HsAdminPersonEntity.builder()
|
||||
.tradeName("Ypsilon GmbH")
|
||||
.build())
|
||||
.contact(HsAdminContactEntity.builder()
|
||||
.label("Ypsilon GmbH")
|
||||
.build())
|
||||
.build(),
|
||||
HsAdminPartnerEntity.builder()
|
||||
.uuid(UUID.randomUUID())
|
||||
.person(HsAdminPersonEntity.builder()
|
||||
.tradeName("Zett OHG")
|
||||
.build())
|
||||
.contact(HsAdminContactEntity.builder()
|
||||
.label("Zett OHG")
|
||||
.build())
|
||||
.build()
|
||||
);
|
||||
|
||||
final var resources = Mapper.mapList(entities, HsAdminPartnerResource.class,
|
||||
PARTNER_ENTITY_TO_RESOURCE_POSTMAPPER);
|
||||
return ResponseEntity.ok(resources);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public ResponseEntity<HsAdminPartnerResource> addPartner(
|
||||
final String currentUser,
|
||||
final String assumedRoles,
|
||||
final HsAdminPartnerResource body) {
|
||||
|
||||
// TODO: context.define(currentUser, assumedRoles);
|
||||
|
||||
if (body.getUuid() == null) {
|
||||
body.setUuid(UUID.randomUUID());
|
||||
}
|
||||
|
||||
// TODO: final var saved = partnerRepo.save(map(body, HsAdminPartnerEntity.class));
|
||||
final var saved = map(body, HsAdminPartnerEntity.class, PARTNER_RESOURCE_TO_ENTITY_POSTMAPPER);
|
||||
|
||||
final var uri =
|
||||
MvcUriComponentsBuilder.fromController(getClass())
|
||||
.path("/api/hs/admin/partners/{id}")
|
||||
.buildAndExpand(body.getUuid())
|
||||
.toUri();
|
||||
final var mapped = map(saved, HsAdminPartnerResource.class,
|
||||
PARTNER_ENTITY_TO_RESOURCE_POSTMAPPER);
|
||||
return ResponseEntity.created(uri).body(mapped);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResponseEntity<HsAdminPartnerResource> getPartnerByUuid(
|
||||
final String currentUser,
|
||||
final String assumedRoles,
|
||||
final UUID partnerUuid) {
|
||||
|
||||
// TODO: context.define(currentUser, assumedRoles);
|
||||
|
||||
// TODO: final var result = partnerRepo.findByUuid(partnerUuid);
|
||||
final var result =
|
||||
partnerUuid.equals(UUID.fromString("3fa85f64-5717-4562-b3fc-2c963f66afa6")) ? null :
|
||||
HsAdminPartnerEntity.builder()
|
||||
.uuid(UUID.randomUUID())
|
||||
.person(HsAdminPersonEntity.builder()
|
||||
.tradeName("Ixx AG")
|
||||
.build())
|
||||
.contact(HsAdminContactEntity.builder()
|
||||
.label("Ixx AG")
|
||||
.build())
|
||||
.build();
|
||||
if (result == null) {
|
||||
return ResponseEntity.notFound().build();
|
||||
}
|
||||
return ResponseEntity.ok(map(result, HsAdminPartnerResource.class, PARTNER_ENTITY_TO_RESOURCE_POSTMAPPER));
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResponseEntity<Void> deletePartnerByUuid(final String currentUser, final String assumedRoles, final UUID userUuid) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResponseEntity<HsAdminPartnerResource> updatePartner(
|
||||
final String currentUser,
|
||||
final String assumedRoles,
|
||||
final UUID partnerUuid,
|
||||
final HsAdminPartnerUpdateResource body) {
|
||||
return null;
|
||||
}
|
||||
|
||||
private final BiConsumer<HsAdminPartnerResource, HsAdminPartnerEntity> PARTNER_RESOURCE_TO_ENTITY_POSTMAPPER = (resource, entity) -> {
|
||||
entity.setPerson(map(resource.getPerson(), HsAdminPersonEntity.class));
|
||||
entity.setContact(map(resource.getContact(), HsAdminContactEntity.class));
|
||||
};
|
||||
|
||||
private final BiConsumer<HsAdminPartnerEntity, HsAdminPartnerResource> PARTNER_ENTITY_TO_RESOURCE_POSTMAPPER = (entity, resource) -> {
|
||||
resource.setPerson(map(entity.getPerson(), HsAdminPersonResource.class));
|
||||
resource.setContact(map(entity.getContact(), HsAdminContactResource.class));
|
||||
};
|
||||
|
||||
}
|
@@ -0,0 +1,35 @@
|
||||
package net.hostsharing.hsadminng.hs.admin.partner;
|
||||
|
||||
import lombok.*;
|
||||
import net.hostsharing.hsadminng.hs.admin.contact.HsAdminContactEntity;
|
||||
import net.hostsharing.hsadminng.hs.admin.person.HsAdminPersonEntity;
|
||||
|
||||
import javax.persistence.*;
|
||||
import java.time.LocalDate;
|
||||
import java.util.UUID;
|
||||
|
||||
@Entity
|
||||
@Table(name = "hs_admin_partner_rv")
|
||||
@Getter
|
||||
@Setter
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class HsAdminPartnerEntity {
|
||||
|
||||
private @Id UUID uuid;
|
||||
|
||||
@ManyToOne
|
||||
@JoinColumn(name = "personuuid")
|
||||
private HsAdminPersonEntity person;
|
||||
|
||||
@ManyToOne
|
||||
@JoinColumn(name = "contactuuid")
|
||||
private HsAdminContactEntity contact;
|
||||
|
||||
private @Column(name = "registrationoffice") String registrationOffice;
|
||||
private @Column(name = "registrationnumber") String registrationNumber;
|
||||
private @Column(name = "birthname") String birthName;
|
||||
private @Column(name = "birthday") LocalDate birthday;
|
||||
private @Column(name = "dateofdeath") LocalDate dateOfDeath;
|
||||
}
|
@@ -0,0 +1,30 @@
|
||||
package net.hostsharing.hsadminng.hs.admin.partner;
|
||||
|
||||
import org.springframework.data.jpa.repository.Query;
|
||||
import org.springframework.data.repository.Repository;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.UUID;
|
||||
|
||||
public interface HsAdminPartnerRepository extends Repository<HsAdminPartnerEntity, UUID> {
|
||||
|
||||
Optional<HsAdminPartnerEntity> findByUuid(UUID id);
|
||||
|
||||
@Query("""
|
||||
SELECT partner FROM HsAdminPartnerEntity partner
|
||||
JOIN HsAdminContactEntity contact ON contact.uuid = partner.contact
|
||||
JOIN HsAdminPersonEntity person ON person.uuid = partner.person
|
||||
WHERE :name is null
|
||||
OR partner.birthName like concat(:name, '%')
|
||||
OR contact.label like concat(:name, '%')
|
||||
OR person.tradeName like concat(:name, '%')
|
||||
OR person.givenName like concat(:name, '%')
|
||||
OR person.familyName like concat(:name, '%')
|
||||
""")
|
||||
List<HsAdminPartnerEntity> findPartnerByOptionalNameLike(String name);
|
||||
|
||||
HsAdminPartnerEntity save(final HsAdminPartnerEntity entity);
|
||||
|
||||
long count();
|
||||
}
|
@@ -0,0 +1,42 @@
|
||||
package net.hostsharing.hsadminng.hs.admin.person;
|
||||
|
||||
import com.vladmihalcea.hibernate.type.array.ListArrayType;
|
||||
import lombok.*;
|
||||
import org.hibernate.annotations.TypeDef;
|
||||
|
||||
import javax.persistence.*;
|
||||
import java.util.UUID;
|
||||
|
||||
@Entity
|
||||
@Table(name = "hs_admin_person_rv")
|
||||
@TypeDef(
|
||||
name = "list-array",
|
||||
typeClass = ListArrayType.class
|
||||
)
|
||||
@Getter
|
||||
@Setter
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class HsAdminPersonEntity {
|
||||
|
||||
private @Id UUID uuid;
|
||||
|
||||
@Enumerated(EnumType.STRING)
|
||||
private PersonType type;
|
||||
|
||||
private String tradeName;
|
||||
|
||||
@Column(name = "givenname")
|
||||
private String givenName;
|
||||
|
||||
@Column(name = "familyname")
|
||||
private String familyName;
|
||||
|
||||
public enum PersonType {
|
||||
NATURAL,
|
||||
LEGAL,
|
||||
SOLE_REPRESENTATION,
|
||||
JOINT_REPRESENTATION
|
||||
}
|
||||
}
|
@@ -0,0 +1,26 @@
|
||||
package net.hostsharing.hsadminng.hs.admin.person;
|
||||
|
||||
import org.springframework.data.jpa.repository.Query;
|
||||
import org.springframework.data.repository.Repository;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.UUID;
|
||||
|
||||
public interface HsAdminPersonRepository extends Repository<HsAdminPersonEntity, UUID> {
|
||||
|
||||
Optional<HsAdminPersonEntity> findByUuid(UUID id);
|
||||
|
||||
@Query("""
|
||||
SELECT p FROM HsAdminPersonEntity p
|
||||
WHERE :name is null
|
||||
OR p.tradeName like concat(:name, '%')
|
||||
OR p.givenName like concat(:name, '%')
|
||||
OR p.familyName like concat(:name, '%')
|
||||
""")
|
||||
List<HsAdminPersonEntity> findPersonByOptionalNameLike(String name);
|
||||
|
||||
HsAdminPersonEntity save(final HsAdminPersonEntity entity);
|
||||
|
||||
long count();
|
||||
}
|
16
src/main/resources/api-definition/hs-admin/api-mappings.yaml
Normal file
16
src/main/resources/api-definition/hs-admin/api-mappings.yaml
Normal file
@@ -0,0 +1,16 @@
|
||||
openapi-processor-mapping: v2
|
||||
|
||||
options:
|
||||
package-name: net.hostsharing.hsadminng.hs.admin.generated.api.v1
|
||||
model-name-suffix: Resource
|
||||
|
||||
map:
|
||||
result: org.springframework.http.ResponseEntity
|
||||
|
||||
types:
|
||||
- type: array => java.util.List
|
||||
- type: string:uuid => java.util.UUID
|
||||
|
||||
paths:
|
||||
/api/hs/admin/partners/{packageUUID}:
|
||||
null: org.openapitools.jackson.nullable.JsonNullable
|
1
src/main/resources/api-definition/hs-admin/auth.yaml
Symbolic link
1
src/main/resources/api-definition/hs-admin/auth.yaml
Symbolic link
@@ -0,0 +1 @@
|
||||
../auth.yaml
|
1
src/main/resources/api-definition/hs-admin/error-responses.yaml
Symbolic link
1
src/main/resources/api-definition/hs-admin/error-responses.yaml
Symbolic link
@@ -0,0 +1 @@
|
||||
../error-responses.yaml
|
@@ -0,0 +1,28 @@
|
||||
|
||||
components:
|
||||
|
||||
schemas:
|
||||
|
||||
HsAdminContactBase:
|
||||
type: object
|
||||
properties:
|
||||
label:
|
||||
type: string
|
||||
postalAddress:
|
||||
type: string
|
||||
emailAddresses:
|
||||
type: string
|
||||
phoneNumbers:
|
||||
type: string
|
||||
|
||||
HsAdminContact:
|
||||
allOf:
|
||||
- type: object
|
||||
properties:
|
||||
uuid:
|
||||
type: string
|
||||
format: uuid
|
||||
- $ref: '#/components/schemas/HsAdminContactBase'
|
||||
|
||||
HsAdminContactUpdate:
|
||||
$ref: '#/components/schemas/HsAdminContactBase'
|
@@ -0,0 +1,45 @@
|
||||
|
||||
components:
|
||||
|
||||
schemas:
|
||||
|
||||
HsAdminPartnerBase:
|
||||
type: object
|
||||
properties:
|
||||
registrationOffice:
|
||||
type: string
|
||||
registrationNumber:
|
||||
type: string
|
||||
birthName:
|
||||
type: string
|
||||
birthday:
|
||||
type: string
|
||||
format: date
|
||||
dateOfDeath:
|
||||
type: string
|
||||
format: date
|
||||
|
||||
HsAdminPartner:
|
||||
allOf:
|
||||
- type: object
|
||||
properties:
|
||||
uuid:
|
||||
type: string
|
||||
format: uuid
|
||||
person:
|
||||
$ref: './hs-admin-person-schemas.yaml#/components/schemas/HsAdminPerson'
|
||||
contact:
|
||||
$ref: './hs-admin-contact-schemas.yaml#/components/schemas/HsAdminContact'
|
||||
- $ref: '#/components/schemas/HsAdminPartnerBase'
|
||||
|
||||
HsAdminPartnerUpdate:
|
||||
allOf:
|
||||
- type: object
|
||||
properties:
|
||||
personUuid:
|
||||
type: string
|
||||
format: uuid
|
||||
contactUuid:
|
||||
type: string
|
||||
format: uuid
|
||||
- $ref: '#/components/schemas/HsAdminPartnerBase'
|
@@ -0,0 +1,81 @@
|
||||
get:
|
||||
tags:
|
||||
- hs-admin-partners
|
||||
description: 'Fetch a single business partner by its uuid, if visible for the current subject.'
|
||||
operationId: getPartnerByUuid
|
||||
parameters:
|
||||
- $ref: './auth.yaml#/components/parameters/currentUser'
|
||||
- $ref: './auth.yaml#/components/parameters/assumedRoles'
|
||||
- name: partnerUUID
|
||||
in: path
|
||||
required: true
|
||||
schema:
|
||||
type: string
|
||||
format: uuid
|
||||
responses:
|
||||
"200":
|
||||
description: OK
|
||||
content:
|
||||
'application/json':
|
||||
schema:
|
||||
$ref: './hs-admin-partner-schemas.yaml#/components/schemas/HsAdminPartner'
|
||||
|
||||
"401":
|
||||
$ref: './error-responses.yaml#/components/responses/Unauthorized'
|
||||
"403":
|
||||
$ref: './error-responses.yaml#/components/responses/Forbidden'
|
||||
|
||||
patch:
|
||||
tags:
|
||||
- hs-admin-partners
|
||||
operationId: updatePartner
|
||||
parameters:
|
||||
- $ref: './auth.yaml#/components/parameters/currentUser'
|
||||
- $ref: './auth.yaml#/components/parameters/assumedRoles'
|
||||
- name: partnerUUID
|
||||
in: path
|
||||
required: true
|
||||
schema:
|
||||
type: string
|
||||
format: uuid
|
||||
requestBody:
|
||||
content:
|
||||
'application/json':
|
||||
schema:
|
||||
$ref: './hs-admin-partner-schemas.yaml#/components/schemas/HsAdminPartnerUpdate'
|
||||
responses:
|
||||
"200":
|
||||
description: OK
|
||||
content:
|
||||
'application/json':
|
||||
schema:
|
||||
$ref: './hs-admin-partner-schemas.yaml#/components/schemas/HsAdminPartner'
|
||||
"401":
|
||||
$ref: './error-responses.yaml#/components/responses/Unauthorized'
|
||||
"403":
|
||||
$ref: './error-responses.yaml#/components/responses/Forbidden'
|
||||
|
||||
|
||||
delete:
|
||||
tags:
|
||||
- hs-admin-partners
|
||||
operationId: deletePartnerByUuid
|
||||
parameters:
|
||||
- $ref: './auth.yaml#/components/parameters/currentUser'
|
||||
- $ref: './auth.yaml#/components/parameters/assumedRoles'
|
||||
- name: userUuid
|
||||
in: path
|
||||
required: true
|
||||
schema:
|
||||
type: string
|
||||
format: uuid
|
||||
description: UUID of the user to delete.
|
||||
responses:
|
||||
"204":
|
||||
description: No Content
|
||||
"401":
|
||||
$ref: './error-responses.yaml#/components/responses/Unauthorized'
|
||||
"403":
|
||||
$ref: './error-responses.yaml#/components/responses/Forbidden'
|
||||
"404":
|
||||
$ref: './error-responses.yaml#/components/responses/NotFound'
|
@@ -0,0 +1,56 @@
|
||||
get:
|
||||
summary: Returns a list of (optionally filtered) business partners.
|
||||
description: Returns the list of (optionally filtered) business partners which are visible to the current user or any of it's assumed roles.
|
||||
tags:
|
||||
- hs-admin-partners
|
||||
operationId: listPartners
|
||||
parameters:
|
||||
- $ref: './auth.yaml#/components/parameters/currentUser'
|
||||
- $ref: './auth.yaml#/components/parameters/assumedRoles'
|
||||
- name: name
|
||||
in: query
|
||||
required: false
|
||||
schema:
|
||||
type: string
|
||||
description: Customer-prefix to filter the results. TODO
|
||||
responses:
|
||||
"200":
|
||||
description: OK
|
||||
content:
|
||||
'application/json':
|
||||
schema:
|
||||
type: array
|
||||
items:
|
||||
$ref: './hs-admin-partner-schemas.yaml#/components/schemas/HsAdminPartner'
|
||||
"401":
|
||||
$ref: './error-responses.yaml#/components/responses/Unauthorized'
|
||||
"403":
|
||||
$ref: './error-responses.yaml#/components/responses/Forbidden'
|
||||
|
||||
post:
|
||||
summary: Adds a new business partner.
|
||||
tags:
|
||||
- hs-admin-partners
|
||||
operationId: addPartner
|
||||
parameters:
|
||||
- $ref: './auth.yaml#/components/parameters/currentUser'
|
||||
- $ref: './auth.yaml#/components/parameters/assumedRoles'
|
||||
requestBody:
|
||||
content:
|
||||
'application/json':
|
||||
schema:
|
||||
$ref: './hs-admin-partner-schemas.yaml#/components/schemas/HsAdminPartner'
|
||||
required: true
|
||||
responses:
|
||||
"201":
|
||||
description: Created
|
||||
content:
|
||||
'application/json':
|
||||
schema:
|
||||
$ref: './hs-admin-partner-schemas.yaml#/components/schemas/HsAdminPartner'
|
||||
"401":
|
||||
$ref: './error-responses.yaml#/components/responses/Unauthorized'
|
||||
"403":
|
||||
$ref: './error-responses.yaml#/components/responses/Forbidden'
|
||||
"409":
|
||||
$ref: './error-responses.yaml#/components/responses/Conflict'
|
@@ -0,0 +1,33 @@
|
||||
|
||||
components:
|
||||
|
||||
schemas:
|
||||
|
||||
HsAdminPersonBase:
|
||||
type: object
|
||||
properties:
|
||||
personType:
|
||||
type: string
|
||||
enum:
|
||||
- NATURAL # a human
|
||||
- LEGAL # e.g. Corp., Inc., AG, GmbH, eG
|
||||
- SOLE_REPRESENTATION # e.g. OHG, GbR
|
||||
- JOINT_REPRESENTATION # e.g. community of heirs
|
||||
tradeName:
|
||||
type: string
|
||||
givenName:
|
||||
type: string
|
||||
familyName:
|
||||
type: string
|
||||
|
||||
HsAdminPerson:
|
||||
allOf:
|
||||
- type: object
|
||||
properties:
|
||||
uuid:
|
||||
type: string
|
||||
format: uuid
|
||||
- $ref: '#/components/schemas/HsAdminPersonBase'
|
||||
|
||||
HsAdminPersonUpdate:
|
||||
$ref: '#/components/schemas/HsAdminPersonBase'
|
16
src/main/resources/api-definition/hs-admin/hs-admin.yaml
Normal file
16
src/main/resources/api-definition/hs-admin/hs-admin.yaml
Normal file
@@ -0,0 +1,16 @@
|
||||
openapi: 3.0.1
|
||||
info:
|
||||
title: Hostsharing hsadmin-ng API
|
||||
version: v0
|
||||
servers:
|
||||
- url: http://localhost:8080
|
||||
description: Local development default URL.
|
||||
|
||||
paths:
|
||||
|
||||
/api/hs/admin/partners:
|
||||
$ref: "./hs-admin-partners.yaml"
|
||||
|
||||
/api/hs/admin/partners/{partnerUUID}:
|
||||
$ref: "./hs-admin-partners-with-uuid.yaml"
|
||||
|
83
src/main/resources/db/changelog/200-hs-base.sql
Normal file
83
src/main/resources/db/changelog/200-hs-base.sql
Normal file
@@ -0,0 +1,83 @@
|
||||
--liquibase formatted sql
|
||||
|
||||
-- ============================================================================
|
||||
--changeset hs-base-GLOBAL-OBJECT:1 endDelimiter:--//
|
||||
-- ----------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
A single row to be referenced as a global object.
|
||||
*/
|
||||
begin transaction;
|
||||
call defineContext('initializing table "global"', null, null, null);
|
||||
insert
|
||||
into RbacObject (objecttable) values ('global');
|
||||
insert
|
||||
into Global (uuid, name) values ((select uuid from RbacObject where objectTable = 'global'), 'hostsharing');
|
||||
commit;
|
||||
--//
|
||||
|
||||
|
||||
-- ============================================================================
|
||||
--changeset hs-base-ADMIN-ROLE:1 endDelimiter:--//
|
||||
-- ----------------------------------------------------------------------------
|
||||
/*
|
||||
A global administrator role.
|
||||
*/
|
||||
create or replace function hsHostsharingAdmin()
|
||||
returns RbacRoleDescriptor
|
||||
returns null on null input
|
||||
stable leakproof
|
||||
language sql as $$
|
||||
select 'global', (select uuid from RbacObject where objectTable = 'global'), 'admin'::RbacRoleType;
|
||||
$$;
|
||||
|
||||
begin transaction;
|
||||
call defineContext('creating Hostsharing admin role', null, null, null);
|
||||
select createRole(hsHostsharingAdmin());
|
||||
commit;
|
||||
|
||||
-- ============================================================================
|
||||
--changeset hs-base-ADMIN-USERS:1 context:dev,tc endDelimiter:--//
|
||||
-- ----------------------------------------------------------------------------
|
||||
/*
|
||||
Create two users and assign both to the administrators role.
|
||||
*/
|
||||
do language plpgsql $$
|
||||
declare
|
||||
admins uuid ;
|
||||
begin
|
||||
call defineContext('creating fake Hostsharing admin users', null, null, null);
|
||||
|
||||
admins = findRoleId(hsHostsharingAdmin());
|
||||
call grantRoleToUserUnchecked(admins, admins, createRbacUser('mike@hostsharing.net'));
|
||||
call grantRoleToUserUnchecked(admins, admins, createRbacUser('sven@hostsharing.net'));
|
||||
end;
|
||||
$$;
|
||||
--//
|
||||
|
||||
|
||||
-- ============================================================================
|
||||
--changeset hs-base-hostsharing-TEST:1 context:dev,tc runAlways:true endDelimiter:--//
|
||||
-- ----------------------------------------------------------------------------
|
||||
|
||||
/*
|
||||
Tests if currentUserUuid() can fetch the user from the session variable.
|
||||
*/
|
||||
|
||||
do language plpgsql $$
|
||||
declare
|
||||
userName varchar;
|
||||
begin
|
||||
call defineContext('testing currentUserUuid', null, 'sven@hostsharing.net', null);
|
||||
select userName from RbacUser where uuid = currentUserUuid() into userName;
|
||||
if userName <> 'sven@hostsharing.net' then
|
||||
raise exception 'setting or fetching initial currentUser failed, got: %', userName;
|
||||
end if;
|
||||
|
||||
call defineContext('testing currentUserUuid', null, 'mike@hostsharing.net', null);
|
||||
select userName from RbacUser where uuid = currentUserUuid() into userName;
|
||||
if userName = 'mike@ehostsharing.net' then
|
||||
raise exception 'currentUser should not change in one transaction, but did change, got: %', userName;
|
||||
end if;
|
||||
end; $$;
|
||||
--//
|
Reference in New Issue
Block a user